ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilRepositoryObjectPlugin.php
Go to the documentation of this file.
1 <?php
2 
24 abstract class ilRepositoryObjectPlugin extends ilPlugin
25 {
26  protected ilLanguage $lng;
27 
41  public static function _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img): string
42  {
43  global $DIC;
44 
45  $img = ilUtil::getImagePath($a_img);
46  if (is_int(strpos($img, "Customizing"))) {
47  return $img;
48  }
49 
50  $component_repository = $DIC["component.repository"];
51 
53  $component = $component_repository->getComponentByTypeAndName($a_ctype, $a_cname);
54 
55  $d2 = $component->getId() . "_" . $a_slot_id . "_" . $plugin->getId();
56 
57  $img = ilUtil::getImagePath($d2 . "/" . $a_img);
58  if (is_int(strpos($img, "Customizing"))) {
59  return $img;
60  }
61 
62  $d = $plugin->getPath();
63  return $d . "/templates/images/" . $a_img;
64  }
65 
66 
67 
68  public static function _getIcon(string $a_type): string
69  {
70  global $DIC;
71  $component_repository = $DIC["component.repository"];
72  return self::_getImagePath(
74  "Repository",
75  "robj",
76  $component_repository->getPluginById($a_type)->getName(),
77  "icon_" . $a_type . ".svg"
78  );
79  }
80 
81  public static function _getName(string $a_id): string
82  {
83  global $DIC;
84  $component_repository = $DIC["component.repository"];
85  if (!$component_repository->hasPluginId($a_id)) {
86  return "";
87  }
88  return $component_repository->getPluginById($a_id)->getName();
89  }
90 
91  protected function beforeActivation(): bool
92  {
93  $ilDB = $this->db;
94 
95  // before activating, we ensure, that the type exists in the ILIAS
96  // object database and that all permissions exist
97  $type = $this->getId();
98 
99  if (strpos($type, "x") !== 0) {
100  throw new ilPluginException("Object plugin type must start with an x. Current type is " . $type . ".");
101  }
102 
103  // check whether type exists in object data, if not, create the type
104  $set = $ilDB->query(
105  "SELECT * FROM object_data " .
106  " WHERE type = " . $ilDB->quote("typ", "text") .
107  " AND title = " . $ilDB->quote($type, "text")
108  );
109  if ($rec = $ilDB->fetchAssoc($set)) {
110  $t_id = $rec["obj_id"];
111  } else {
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 = [1, 2, 3, 4, 6];
128  if ($this->allowCopy()) {
129  $ops[] = ilRbacReview::_getOperationIdByName("copy");
130  }
131  foreach ($ops as $op) {
132  // check whether type exists in object data, if not, create the type
133  $set = $ilDB->query(
134  "SELECT * FROM rbac_ta " .
135  " WHERE typ_id = " . $ilDB->quote($t_id, "integer") .
136  " AND ops_id = " . $ilDB->quote($op, "integer")
137  );
138  if (!$ilDB->fetchAssoc($set)) {
139  $ilDB->manipulate("INSERT INTO rbac_ta " .
140  "(typ_id, ops_id) VALUES (" .
141  $ilDB->quote($t_id, "integer") . "," .
142  $ilDB->quote($op, "integer") .
143  ")");
144  }
145  }
146 
147  // now add creation permission, if not existing
148  $set = $ilDB->query(
149  "SELECT * FROM rbac_operations " .
150  " WHERE class = " . $ilDB->quote("create", "text") .
151  " AND operation = " . $ilDB->quote("create_" . $type, "text")
152  );
153  if ($rec = $ilDB->fetchAssoc($set)) {
154  $create_ops_id = $rec["ops_id"];
155  } else {
156  $create_ops_id = $ilDB->nextId("rbac_operations");
157  $ilDB->manipulate("INSERT INTO rbac_operations " .
158  "(ops_id, operation, description, class) VALUES (" .
159  $ilDB->quote($create_ops_id, "integer") . "," .
160  $ilDB->quote("create_" . $type, "text") . "," .
161  $ilDB->quote("create " . $type, "text") . "," .
162  $ilDB->quote("create", "text") .
163  ")");
164  }
165 
166  // assign creation operation to root, cat, crs, grp and fold
167  $par_types = $this->getParentTypes();
168  foreach ($par_types as $par_type) {
169  $set = $ilDB->query(
170  "SELECT obj_id FROM object_data " .
171  " WHERE type = " . $ilDB->quote("typ", "text") .
172  " AND title = " . $ilDB->quote($par_type, "text")
173  );
174  if (($rec = $ilDB->fetchAssoc($set)) && $rec["obj_id"] > 0) {
175  $set = $ilDB->query(
176  "SELECT * FROM rbac_ta " .
177  " WHERE typ_id = " . $ilDB->quote($rec["obj_id"], "integer") .
178  " AND ops_id = " . $ilDB->quote($create_ops_id, "integer")
179  );
180  if (!$ilDB->fetchAssoc($set)) {
181  $ilDB->manipulate("INSERT INTO rbac_ta " .
182  "(typ_id, ops_id) VALUES (" .
183  $ilDB->quote($rec["obj_id"], "integer") . "," .
184  $ilDB->quote($create_ops_id, "integer") .
185  ")");
186  }
187  }
188  }
189 
190  return true;
191  }
192 
193  protected function beforeUninstallCustom(): bool
194  {
195  // plugin-specific
196  // false would indicate that anything went wrong
197  return true;
198  }
199 
200  abstract protected function uninstallCustom(): void;
201 
202  final protected function beforeUninstall(): bool
203  {
204  if ($this->beforeUninstallCustom()) {
205  $rep_util = new ilRepUtil();
206  $rep_util->deleteObjectType($this->getId());
207 
208  // custom database tables may be needed by plugin repository object
209  $this->uninstallCustom();
210 
211  return true;
212  }
213  return false;
214  }
215 
219  public function getParentTypes(): array
220  {
221  $par_types = ["root", "cat", "crs", "grp", "fold"];
222  return $par_types;
223  }
224 
228  public function allowCopy(): bool
229  {
230  return false;
231  }
232 
236  public function useOrguPermissions(): bool
237  {
238  return false;
239  }
240 
241  public function getPrefix(): string
242  {
243  $lh = $this->getLanguageHandler();
244  return $lh->getPrefix();
245  }
246 }
hasPluginId(string $id)
Check if a plugin exists.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
useOrguPermissions()
Decide if this repository plugin uses OrgUnit Permissions.
static now()
Return current timestamp in Y-m-d H:i:s format.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPluginByName(string $name)
Get a plugin by name.
ilComponentRepositoryWrite $component_repository
allowCopy()
decides if this repository plugin can be copied
global $DIC
Definition: shib_login.php:26
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
getPluginById(string $id)
Get a plugin by id.
ilDBInterface $db
static _getOperationIdByName(string $a_operation)
get operation id by name of operation
getComponentByTypeAndName(string $type, string $name)
Get a component by type and name.
static _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img)
Only very little classes seem to care about this: