ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
20 final function getComponentType()
21 {
22 return IL_COMP_SERVICE;
23 }
24
30 final function getComponentName()
31 {
32 return "Repository";
33 }
34
40 final function getSlot()
41 {
42 return "RepositoryObject";
43 }
44
50 final function getSlotId()
51 {
52 return "robj";
53 }
54
58 protected final function slotInit()
59 {
60 // nothing to do here
61 }
62
66 static function _getIcon($a_type, $a_size)
67 {
68 /*
69 switch($a_size)
70 {
71 case "small": $suff = ""; break;
72 case "tiny": $suff = "_s"; break;
73 default: $suff = "_b"; break;
74 }
75 */
76 return ilPlugin::_getImagePath(IL_COMP_SERVICE, "Repository", "robj",
77 ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj",$a_type),
78 "icon_".$a_type/*.$suff*/.".svg");
79 }
80
84 function _getName($a_id)
85 {
86 $name = ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj",$a_id);
87 if ($name != "")
88 {
89 return $name;
90 }
91 }
92
96 protected function beforeActivation()
97 {
98 global $lng, $ilDB;
99
100 // before activating, we ensure, that the type exists in the ILIAS
101 // object database and that all permissions exist
102 $type = $this->getId();
103
104 if (substr($type, 0, 1) != "x")
105 {
106 throw new ilPluginException("Object plugin type must start with an x. Current type is ".$type.".");
107 }
108
109 // check whether type exists in object data, if not, create the type
110 $set = $ilDB->query("SELECT * FROM object_data ".
111 " WHERE type = ".$ilDB->quote("typ", "text").
112 " AND title = ".$ilDB->quote($type, "text")
113 );
114 if ($rec = $ilDB->fetchAssoc($set))
115 {
116 $t_id = $rec["obj_id"];
117 }
118 else
119 {
120 $t_id = $ilDB->nextId("object_data");
121 $ilDB->manipulate("INSERT INTO object_data ".
122 "(obj_id, type, title, description, owner, create_date, last_update) VALUES (".
123 $ilDB->quote($t_id, "integer").",".
124 $ilDB->quote("typ", "text").",".
125 $ilDB->quote($type, "text").",".
126 $ilDB->quote("Plugin ".$this->getPluginName(), "text").",".
127 $ilDB->quote(-1, "integer").",".
128 $ilDB->quote(ilUtil::now(), "timestamp").",".
129 $ilDB->quote(ilUtil::now(), "timestamp").
130 ")");
131 }
132
133 // add rbac operations
134 // 1: edit_permissions, 2: visible, 3: read, 4:write, 6:delete
135 $ops = array(1, 2, 3, 4, 6);
136 foreach ($ops as $op)
137 {
138 // check whether type exists in object data, if not, create the type
139 $set = $ilDB->query("SELECT * FROM rbac_ta ".
140 " WHERE typ_id = ".$ilDB->quote($t_id, "integer").
141 " AND ops_id = ".$ilDB->quote($op, "integer")
142 );
143 if (!$ilDB->fetchAssoc($set))
144 {
145 $ilDB->manipulate("INSERT INTO rbac_ta ".
146 "(typ_id, ops_id) VALUES (".
147 $ilDB->quote($t_id, "integer").",".
148 $ilDB->quote($op, "integer").
149 ")");
150 }
151 }
152
153 // now add creation permission, if not existing
154 $set = $ilDB->query("SELECT * FROM rbac_operations ".
155 " WHERE class = ".$ilDB->quote("create", "text").
156 " AND operation = ".$ilDB->quote("create_".$type, "text")
157 );
158 if ($rec = $ilDB->fetchAssoc($set))
159 {
160 $create_ops_id = $rec["ops_id"];
161 }
162 else
163 {
164 $create_ops_id = $ilDB->nextId(rbac_operations);
165 $ilDB->manipulate("INSERT INTO rbac_operations ".
166 "(ops_id, operation, description, class) VALUES (".
167 $ilDB->quote($create_ops_id, "integer").",".
168 $ilDB->quote("create_".$type, "text").",".
169 $ilDB->quote("create ".$type, "text").",".
170 $ilDB->quote("create", "text").
171 ")");
172 }
173
174 // assign creation operation to root, cat, crs, grp and fold
175 $par_types = array("root", "cat", "crs", "grp", "fold");
176 foreach ($par_types as $par_type)
177 {
178 $set = $ilDB->query("SELECT obj_id FROM object_data ".
179 " WHERE type = ".$ilDB->quote("typ", "text").
180 " AND title = ".$ilDB->quote($par_type, "text")
181 );
182 if ($rec = $ilDB->fetchAssoc($set))
183 {
184 if ($rec["obj_id"] > 0)
185 {
186 $set = $ilDB->query("SELECT * FROM rbac_ta ".
187 " WHERE typ_id = ".$ilDB->quote($rec["obj_id"], "integer").
188 " AND ops_id = ".$ilDB->quote($create_ops_id, "integer")
189 );
190 if (!$ilDB->fetchAssoc($set))
191 {
192 $ilDB->manipulate("INSERT INTO rbac_ta ".
193 "(typ_id, ops_id) VALUES (".
194 $ilDB->quote($rec["obj_id"], "integer").",".
195 $ilDB->quote($create_ops_id, "integer").
196 ")");
197 }
198 }
199 }
200 }
201
202 return true;
203 }
204
205 protected function beforeUninstallCustom()
206 {
207 // plugin-specific
208 // false would indicate that anything went wrong
209 return true;
210 }
211
212 abstract protected function uninstallCustom();
213
214 final protected function beforeUninstall()
215 {
216 if($this->beforeUninstallCustom())
217 {
218 include_once "Services/Repository/classes/class.ilRepUtil.php";
219 $rep_util = new ilRepUtil();
220 $rep_util->deleteObjectType($this->getId());
221
222 // custom database tables may be needed by plugin repository object
223 $this->uninstallCustom();
224
225 return true;
226 }
227 return false;
228 }
229}
230?>
const IL_COMP_SERVICE
static _getImagePath($a_ctype, $a_cname, $a_slot_id, $a_pname, $a_img)
Get image path.
getId()
Get Id.
lookupNameForId($a_ctype, $a_cname, $a_slot_id, $a_plugin_id)
Lookup name for id.
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI)
Abstract parent class for all repository object plugin classes.
static _getIcon($a_type, $a_size)
Get Icon.
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:40
global $ilDB