ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjectPlugin.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Object/classes/class.ilObject2.php");
5 require_once('./Services/Component/classes/class.ilPlugin.php');
6 
7 /*
8 * Object class for plugins. This one wraps around ilObject
9 *
10 * @author Alex Killing <alex.killing@gmx.de>
11 * @version $Id$
12 * @ingroup ServicesRepository
13 */
14 abstract class ilObjectPlugin extends ilObject2
15 {
16  private $object;
17 
18  protected $plugin;
19 
23  protected static $plugin_by_type = array();
24 
25 
29  public function __construct($a_ref_id = 0)
30  {
31  $this->initType();
32  parent::__construct($a_ref_id, true);
33  $this->plugin = $this->getPlugin();
34  }
35 
36 
43  public static function getPluginObjectByType($type)
44  {
45  if (!self::$plugin_by_type[$type]) {
46  list($component, $component_name) = ilPlugin::lookupTypeInformationsForId($type);
47  if (
48  $component == IL_COMP_SERVICE &&
49  $component_name == "Repository"
50  ) {
51  self::loadRepoPlugin($type);
52  }
53 
54  if (
55  $component == IL_COMP_MODULE &&
56  $component_name == "OrgUnit"
57  ) {
58  self::loadOrgUnitPlugin($type);
59  }
60  }
61 
62  return self::$plugin_by_type[$type];
63  }
64 
65  protected static function loadRepoPlugin(string $type_id)
66  {
67  $plugin = null;
68  $name = ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $type_id);
69 
70  if (!is_null($name)) {
71  $plugin = ilPlugin::getPluginObject(IL_COMP_SERVICE, "Repository", "robj", $name);
72  }
73 
74  if (is_null($plugin)) {
75  ilLoggerFactory::getLogger("obj")->log("Try to get repo plugin obj by type: $type_id. No such type exists for Repository and Org Unit pluginss.");
76  }
77  self::$plugin_by_type[$type_id] = $plugin;
78  }
79 
80  protected static function loadOrgUnitPlugin(string $type_id)
81  {
82  $plugin = null;
83  $name = ilPlugin::lookupNameForId(IL_COMP_MODULE, "OrgUnit", "orguext", $type_id);
84  if (!is_null($name)) {
85  $plugin = ilPlugin::getPluginObject(IL_COMP_MODULE, "OrgUnit", "orguext", $name);
86  }
87 
88  if (is_null($plugin)) {
89  ilLoggerFactory::getLogger("obj")->log("Try to get repo plugin obj by type: $type_id. No such type exists for Repository and Org Unit pluginss.");
90  }
91  self::$plugin_by_type[$type_id] = $plugin;
92  }
93 
99  public static function lookupTxtById($plugin_id, $lang_var)
100  {
101  $pl = self::getPluginObjectByType($plugin_id);
102  return $pl->txt($lang_var);
103  }
104 
110  protected function getPlugin()
111  {
112  if (!$this->plugin) {
113  $this->plugin =
116  "Repository",
117  "robj",
118  ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $this->getType())
119  );
120  if (!is_object($this->plugin)) {
121  throw new ilPluginException("ilObjectPlugin: Could not instantiate plugin object for type " . $this->getType() . ".");
122  }
123  }
124  return $this->plugin;
125  }
126 
130  final protected function txt($a_var)
131  {
132  return $this->getPlugin()->txt($a_var);
133  }
134 
139  public function getParentTypes()
140  {
141  return $this->plugin->getParentTypes();
142  }
143 }
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
getParentTypes()
returns a list of all repository object types which can be a parent of this type. ...
static lookupTxtById($plugin_id, $lang_var)
static loadRepoPlugin(string $type_id)
txt($a_var)
Wrapper for txt function.
static getPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin...
static lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
__construct($a_ref_id=0)
Constructor.
static lookupTypeInformationsForId(string $id)
const IL_COMP_MODULE
getPlugin()
Get plugin object.
static getLogger($a_component_id)
Get component logger.
static loadOrgUnitPlugin(string $type_id)
const IL_COMP_SERVICE