ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRepositoryObjectPlugin.php
Go to the documentation of this file.
1 <?php
2 
3 include_once("./Services/Component/classes/class.ilPlugin.php");
4 
13 abstract 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  switch($a_size)
69  {
70  case "small": $suff = ""; break;
71  case "tiny": $suff = "_s"; break;
72  default: $suff = "_b"; break;
73  }
74  return ilPlugin::_getImagePath(IL_COMP_SERVICE, "Repository", "robj",
75  ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj",$a_type),
76  "icon_".$a_type.$suff.".gif");
77  }
78 
82  function _getName($a_id)
83  {
84  $name = ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj",$a_id);
85  if ($name != "")
86  {
87  return $name;
88  }
89  }
90 
94  protected function beforeActivation()
95  {
96  global $lng, $ilDB;
97 
98  // before activating, we ensure, that the type exists in the ILIAS
99  // object database and that all permissions exist
100  $type = $this->getId();
101 
102  if (substr($type, 0, 1) != "x")
103  {
104  throw new ilPluginException("Object plugin type must start with an x. Current type is ".$type.".");
105  }
106 
107  // check whether type exists in object data, if not, create the type
108  $set = $ilDB->query("SELECT * FROM object_data ".
109  " WHERE type = ".$ilDB->quote("typ", "text").
110  " AND title = ".$ilDB->quote($type, "text")
111  );
112  if ($rec = $ilDB->fetchAssoc($set))
113  {
114  $t_id = $rec["obj_id"];
115  }
116  else
117  {
118  $t_id = $ilDB->nextId("object_data");
119  $ilDB->manipulate("INSERT INTO object_data ".
120  "(obj_id, type, title, description, owner, create_date, last_update) VALUES (".
121  $ilDB->quote($t_id, "integer").",".
122  $ilDB->quote("typ", "text").",".
123  $ilDB->quote($type, "text").",".
124  $ilDB->quote("Plugin ".$this->getPluginName(), "text").",".
125  $ilDB->quote(-1, "integer").",".
126  $ilDB->quote(ilUtil::now(), "timestamp").",".
127  $ilDB->quote(ilUtil::now(), "timestamp").
128  ")");
129  }
130 
131  // add rbac operations
132  // 1: edit_permissions, 2: visible, 3: read, 4:write, 6:delete
133  $ops = array(1, 2, 3, 4, 6);
134  foreach ($ops as $op)
135  {
136  // check whether type exists in object data, if not, create the type
137  $set = $ilDB->query("SELECT * FROM rbac_ta ".
138  " WHERE typ_id = ".$ilDB->quote($t_id, "integer").
139  " AND ops_id = ".$ilDB->quote($op, "integer")
140  );
141  if (!$ilDB->fetchAssoc($set))
142  {
143  $ilDB->manipulate("INSERT INTO rbac_ta ".
144  "(typ_id, ops_id) VALUES (".
145  $ilDB->quote($t_id, "integer").",".
146  $ilDB->quote($op, "integer").
147  ")");
148  }
149  }
150 
151  // now add creation permission, if not existing
152  $set = $ilDB->query("SELECT * FROM rbac_operations ".
153  " WHERE class = ".$ilDB->quote("create", "text").
154  " AND operation = ".$ilDB->quote("create_".$type, "text")
155  );
156  if ($rec = $ilDB->fetchAssoc($set))
157  {
158  $create_ops_id = $rec["ops_id"];
159  }
160  else
161  {
162  $create_ops_id = $ilDB->nextId(rbac_operations);
163  $ilDB->manipulate("INSERT INTO rbac_operations ".
164  "(ops_id, operation, description, class) VALUES (".
165  $ilDB->quote($create_ops_id, "integer").",".
166  $ilDB->quote("create_".$type, "text").",".
167  $ilDB->quote("create ".$type, "text").",".
168  $ilDB->quote("create", "text").
169  ")");
170  }
171 
172  // assign creation operation to root, cat, crs, grp and fold
173  $par_types = array("root", "cat", "crs", "grp", "fold");
174  foreach ($par_types as $par_type)
175  {
176  $set = $ilDB->query("SELECT obj_id FROM object_data ".
177  " WHERE type = ".$ilDB->quote("typ", "text").
178  " AND title = ".$ilDB->quote($par_type, "text")
179  );
180  if ($rec = $ilDB->fetchAssoc($set))
181  {
182  if ($rec["obj_id"] > 0)
183  {
184  $set = $ilDB->query("SELECT * FROM rbac_ta ".
185  " WHERE typ_id = ".$ilDB->quote($rec["obj_id"], "integer").
186  " AND ops_id = ".$ilDB->quote($create_ops_id, "integer")
187  );
188  if (!$ilDB->fetchAssoc($set))
189  {
190  $ilDB->manipulate("INSERT INTO rbac_ta ".
191  "(typ_id, ops_id) VALUES (".
192  $ilDB->quote($rec["obj_id"], "integer").",".
193  $ilDB->quote($create_ops_id, "integer").
194  ")");
195  }
196  }
197  }
198  }
199 
200  return true;
201  }
202 
203 }
204 ?>