ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4include_once("./Services/Object/classes/class.ilObject2.php");
5require_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*/
14abstract 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 (!isset(self::$plugin_by_type[$type]) || !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 ) {
52 }
53
54 if (
55 $component == IL_COMP_MODULE &&
56 $component_name == "OrgUnit"
57 ) {
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)) {
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}
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
const IL_COMP_MODULE
static getLogger($a_component_id)
Get component logger.
Class ilObject2 This is an intermediate progress of ilObject class.
getType()
get object type @access public
__construct($a_ref_id=0)
Constructor.
getParentTypes()
returns a list of all repository object types which can be a parent of this type.
static lookupTxtById($plugin_id, $lang_var)
static loadOrgUnitPlugin(string $type_id)
static loadRepoPlugin(string $type_id)
txt($a_var)
Wrapper for txt function.
getPlugin()
Get plugin object.
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)
static lookupTypeInformationsForId(string $id)
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc