ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilRepositoryObjectPlugin.php
Go to the documentation of this file.
1<?php
2
3include_once("./Services/Component/classes/class.ilPlugin.php");
4
13abstract class ilRepositoryObjectPlugin extends ilPlugin
14{
21 {
22 return IL_COMP_SERVICE;
23 }
24
31 {
32 return "Repository";
33 }
34
40 function getSlot()
41 {
42 return "RepositoryObject";
43 }
44
50 function getSlotId()
51 {
52 return "robj";
53 }
54
58 protected function slotInit()
59 {
60 // nothing to do here
61 }
62
66 static function _getIcon($a_type, $a_size)
67 {
68 return ilPlugin::_getImagePath(IL_COMP_SERVICE, "Repository", "robj",
70 "icon_".$a_type.".svg");
71 }
72
76 static function _getName($a_id)
77 {
78 $name = ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj",$a_id);
79 if ($name != "")
80 {
81 return $name;
82 }
83 }
84
88 protected function beforeActivation()
89 {
90 global $lng, $ilDB;
91
92 // before activating, we ensure, that the type exists in the ILIAS
93 // object database and that all permissions exist
94 $type = $this->getId();
95
96 if (substr($type, 0, 1) != "x")
97 {
98 throw new ilPluginException("Object plugin type must start with an x. Current type is ".$type.".");
99 }
100
101 // check whether type exists in object data, if not, create the type
102 $set = $ilDB->query("SELECT * FROM object_data ".
103 " WHERE type = ".$ilDB->quote("typ", "text").
104 " AND title = ".$ilDB->quote($type, "text")
105 );
106 if ($rec = $ilDB->fetchAssoc($set))
107 {
108 $t_id = $rec["obj_id"];
109 }
110 else
111 {
112 $t_id = $ilDB->nextId("object_data");
113 $ilDB->manipulate("INSERT INTO object_data ".
114 "(obj_id, type, title, description, owner, create_date, last_update) VALUES (".
115 $ilDB->quote($t_id, "integer").",".
116 $ilDB->quote("typ", "text").",".
117 $ilDB->quote($type, "text").",".
118 $ilDB->quote("Plugin ".$this->getPluginName(), "text").",".
119 $ilDB->quote(-1, "integer").",".
120 $ilDB->quote(ilUtil::now(), "timestamp").",".
121 $ilDB->quote(ilUtil::now(), "timestamp").
122 ")");
123 }
124
125 // add rbac operations
126 // 1: edit_permissions, 2: visible, 3: read, 4:write, 6:delete
127 $ops = array(1, 2, 3, 4, 6);
128 if ($this->allowCopy())
129 {
131 }
132 foreach ($ops as $op)
133 {
134 // check whether type exists in object data, if not, create the type
135 $set = $ilDB->query("SELECT * FROM rbac_ta ".
136 " WHERE typ_id = ".$ilDB->quote($t_id, "integer").
137 " AND ops_id = ".$ilDB->quote($op, "integer")
138 );
139 if (!$ilDB->fetchAssoc($set))
140 {
141 $ilDB->manipulate("INSERT INTO rbac_ta ".
142 "(typ_id, ops_id) VALUES (".
143 $ilDB->quote($t_id, "integer").",".
144 $ilDB->quote($op, "integer").
145 ")");
146 }
147 }
148
149 // now add creation permission, if not existing
150 $set = $ilDB->query("SELECT * FROM rbac_operations ".
151 " WHERE class = ".$ilDB->quote("create", "text").
152 " AND operation = ".$ilDB->quote("create_".$type, "text")
153 );
154 if ($rec = $ilDB->fetchAssoc($set))
155 {
156 $create_ops_id = $rec["ops_id"];
157 }
158 else
159 {
160 $create_ops_id = $ilDB->nextId(rbac_operations);
161 $ilDB->manipulate("INSERT INTO rbac_operations ".
162 "(ops_id, operation, description, class) VALUES (".
163 $ilDB->quote($create_ops_id, "integer").",".
164 $ilDB->quote("create_".$type, "text").",".
165 $ilDB->quote("create ".$type, "text").",".
166 $ilDB->quote("create", "text").
167 ")");
168 }
169
170 // assign creation operation to root, cat, crs, grp and fold
171 $par_types = $this->getParentTypes();
172 foreach ($par_types as $par_type)
173 {
174 $set = $ilDB->query("SELECT obj_id FROM object_data ".
175 " WHERE type = ".$ilDB->quote("typ", "text").
176 " AND title = ".$ilDB->quote($par_type, "text")
177 );
178 if ($rec = $ilDB->fetchAssoc($set))
179 {
180 if ($rec["obj_id"] > 0)
181 {
182 $set = $ilDB->query("SELECT * FROM rbac_ta ".
183 " WHERE typ_id = ".$ilDB->quote($rec["obj_id"], "integer").
184 " AND ops_id = ".$ilDB->quote($create_ops_id, "integer")
185 );
186 if (!$ilDB->fetchAssoc($set))
187 {
188 $ilDB->manipulate("INSERT INTO rbac_ta ".
189 "(typ_id, ops_id) VALUES (".
190 $ilDB->quote($rec["obj_id"], "integer").",".
191 $ilDB->quote($create_ops_id, "integer").
192 ")");
193 }
194 }
195 }
196 }
197
198 return true;
199 }
200
201 protected function beforeUninstallCustom()
202 {
203 // plugin-specific
204 // false would indicate that anything went wrong
205 return true;
206 }
207
208 abstract protected function uninstallCustom();
209
210 final protected function beforeUninstall()
211 {
212 if($this->beforeUninstallCustom())
213 {
214 include_once "Services/Repository/classes/class.ilRepUtil.php";
215 $rep_util = new ilRepUtil();
216 $rep_util->deleteObjectType($this->getId());
217
218 // custom database tables may be needed by plugin repository object
219 $this->uninstallCustom();
220
221 return true;
222 }
223 return false;
224 }
225
229 public function getParentTypes() {
230 $par_types = array("root", "cat", "crs", "grp", "fold");
231 return $par_types;
232 }
233
239 public function allowCopy()
240 {
241 return false;
242 }
243}
244?>
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
static _getImagePath($a_ctype, $a_cname, $a_slot_id, $a_pname, $a_img)
Get image path.
static lookupNameForId($a_ctype, $a_cname, $a_slot_id, $a_plugin_id)
Lookup name for id.
getId()
Get Id.
static _getOperationIdByName($a_operation)
get operation id by name of operation @access public @access static
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI)
Abstract parent class for all repository object plugin classes.
allowCopy()
decides if this repository plugin can be copied
static _getIcon($a_type, $a_size)
Get Icon.
static _getName($a_id)
Get class name.
beforeActivation()
Before activation processing.
slotInit()
Object initialization done by slot.
static now()
Return current timestamp in Y-m-d H:i:s format.
global $lng
Definition: privfeed.php:17
global $ilDB
$a_type
Definition: workflow.php:93