ILIAS  release_8 Revision v8.24
class.ilRepositoryObjectPlugin.php
Go to the documentation of this file.
1<?php
2
24abstract 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
64 return $d . "/templates/images/" . $a_img;
65 }
66
67
68
69 public static function _getIcon(string $a_type): string
70 {
71 global $DIC;
72 $component_repository = $DIC["component.repository"];
75 "Repository",
76 "robj",
77 $component_repository->getPluginById($a_type)->getName(),
78 "icon_" . $a_type . ".svg"
79 );
80 }
81
82 public static function _getName(string $a_id): string
83 {
84 global $DIC;
85 $component_repository = $DIC["component.repository"];
87 return "";
88 }
89 return $component_repository->getPluginById($a_id)->getName();
90 }
91
92 protected function beforeActivation(): bool
93 {
95
96 // before activating, we ensure, that the type exists in the ILIAS
97 // object database and that all permissions exist
98 $type = $this->getId();
99
100 if (strpos($type, "x") !== 0) {
101 throw new ilPluginException("Object plugin type must start with an x. Current type is " . $type . ".");
102 }
103
104 // check whether type exists in object data, if not, create the type
105 $set = $ilDB->query(
106 "SELECT * FROM object_data " .
107 " WHERE type = " . $ilDB->quote("typ", "text") .
108 " AND title = " . $ilDB->quote($type, "text")
109 );
110 if ($rec = $ilDB->fetchAssoc($set)) {
111 $t_id = $rec["obj_id"];
112 } else {
113 $t_id = $ilDB->nextId("object_data");
114 $ilDB->manipulate("INSERT INTO object_data " .
115 "(obj_id, type, title, description, owner, create_date, last_update) VALUES (" .
116 $ilDB->quote($t_id, "integer") . "," .
117 $ilDB->quote("typ", "text") . "," .
118 $ilDB->quote($type, "text") . "," .
119 $ilDB->quote("Plugin " . $this->getPluginName(), "text") . "," .
120 $ilDB->quote(-1, "integer") . "," .
121 $ilDB->quote(ilUtil::now(), "timestamp") . "," .
122 $ilDB->quote(ilUtil::now(), "timestamp") .
123 ")");
124 }
125
126 // add rbac operations
127 // 1: edit_permissions, 2: visible, 3: read, 4:write, 6:delete
128 $ops = [1, 2, 3, 4, 6];
129 if ($this->allowCopy()) {
131 }
132 foreach ($ops as $op) {
133 // check whether type exists in object data, if not, create the type
134 $set = $ilDB->query(
135 "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 $ilDB->manipulate("INSERT INTO rbac_ta " .
141 "(typ_id, ops_id) VALUES (" .
142 $ilDB->quote($t_id, "integer") . "," .
143 $ilDB->quote($op, "integer") .
144 ")");
145 }
146 }
147
148 // now add creation permission, if not existing
149 $set = $ilDB->query(
150 "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 $create_ops_id = $rec["ops_id"];
156 } else {
157 $create_ops_id = $ilDB->nextId("rbac_operations");
158 $ilDB->manipulate("INSERT INTO rbac_operations " .
159 "(ops_id, operation, description, class) VALUES (" .
160 $ilDB->quote($create_ops_id, "integer") . "," .
161 $ilDB->quote("create_" . $type, "text") . "," .
162 $ilDB->quote("create " . $type, "text") . "," .
163 $ilDB->quote("create", "text") .
164 ")");
165 }
166
167 // assign creation operation to root, cat, crs, grp and fold
168 $par_types = $this->getParentTypes();
169 foreach ($par_types as $par_type) {
170 $set = $ilDB->query(
171 "SELECT obj_id FROM object_data " .
172 " WHERE type = " . $ilDB->quote("typ", "text") .
173 " AND title = " . $ilDB->quote($par_type, "text")
174 );
175 if (($rec = $ilDB->fetchAssoc($set)) && $rec["obj_id"] > 0) {
176 $set = $ilDB->query(
177 "SELECT * FROM rbac_ta " .
178 " WHERE typ_id = " . $ilDB->quote($rec["obj_id"], "integer") .
179 " AND ops_id = " . $ilDB->quote($create_ops_id, "integer")
180 );
181 if (!$ilDB->fetchAssoc($set)) {
182 $ilDB->manipulate("INSERT INTO rbac_ta " .
183 "(typ_id, ops_id) VALUES (" .
184 $ilDB->quote($rec["obj_id"], "integer") . "," .
185 $ilDB->quote($create_ops_id, "integer") .
186 ")");
187 }
188 }
189 }
190
191 return true;
192 }
193
194 protected function beforeUninstallCustom(): bool
195 {
196 // plugin-specific
197 // false would indicate that anything went wrong
198 return true;
199 }
200
201 abstract protected function uninstallCustom(): void;
202
203 final protected function beforeUninstall(): bool
204 {
205 if ($this->beforeUninstallCustom()) {
206 $rep_util = new ilRepUtil();
207 $rep_util->deleteObjectType($this->getId());
208
209 // custom database tables may be needed by plugin repository object
210 $this->uninstallCustom();
211
212 return true;
213 }
214 return false;
215 }
216
220 public function getParentTypes(): array
221 {
222 $par_types = ["root", "cat", "crs", "grp", "fold"];
223 return $par_types;
224 }
225
229 public function allowCopy(): bool
230 {
231 return false;
232 }
233
237 public function useOrguPermissions(): bool
238 {
239 return false;
240 }
241
242 public function getPrefix(): string
243 {
244 $lh = $this->getLanguageHandler();
245 return $lh->getPrefix();
246 }
247}
language handling
ilDBInterface $db
ilComponentRepositoryWrite $component_repository
static _getOperationIdByName(string $a_operation)
get operation id by name of operation
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
allowCopy()
decides if this repository plugin can be copied
beforeUninstall()
@deprecate If you cannot get rid of the requirement to use this, adjust the uninstall method in your ...
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:
useOrguPermissions()
Decide if this repository plugin uses OrgUnit Permissions.
beforeActivation()
@deprecate If you cannot get rid of the requirement to use this, adjust the activate method in your s...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static now()
Return current timestamp in Y-m-d H:i:s format.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: feed.php:28
$img
Definition: imgupload.php:83
getPluginById(string $id)
Get a plugin by id.
hasPluginId(string $id)
Check if a plugin exists.
getPluginByName(string $name)
Get a plugin by name.
getComponentByTypeAndName(string $type, string $name)
Get a component by type and name.
$type