ILIAS  release_8 Revision v8.24
class.ilHelpMapping.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilDBInterface $db;
26
27 public function __construct()
28 {
29 global $DIC;
30
31 $this->db = $DIC->database();
32 }
33
34 public static function saveScreenIdsForChapter(
35 int $a_chap,
36 array $a_ids
37 ): void {
38 global $DIC;
39
40 $ilDB = $DIC->database();
41
43 foreach ($a_ids as $id) {
44 $id = trim($id);
45 $id = explode("/", $id);
46 if ($id[0] != "") {
47 if (($id[1] ?? "") == "") {
48 $id[1] = "-";
49 }
50 $id2 = explode("#", ($id[2] ?? ""));
51 if ($id2[0] == "") {
52 $id2[0] = "-";
53 }
54 if (($id2[1] ?? "") == "") {
55 $id2[1] = "-";
56 }
57 $ilDB->replace(
58 "help_map",
59 array("chap" => array("integer", $a_chap),
60 "component" => array("text", $id[0]),
61 "screen_id" => array("text", $id[1]),
62 "screen_sub_id" => array("text", $id2[0]),
63 "perm" => array("text", $id2[1]),
64 "module_id" => array("integer", 0)
65 ),
66 array()
67 );
68 }
69 }
70 }
71
72 public static function saveMappingEntry(
73 int $a_chap,
74 string $a_comp,
75 string $a_screen_id,
76 string $a_screen_sub_id,
77 string $a_perm,
78 int $a_module_id = 0
79 ): void {
80 global $DIC;
81
82 $ilDB = $DIC->database();
83
84 $ilDB->replace(
85 "help_map",
86 array("chap" => array("integer", $a_chap),
87 "component" => array("text", $a_comp),
88 "screen_id" => array("text", $a_screen_id),
89 "screen_sub_id" => array("text", $a_screen_sub_id),
90 "perm" => array("text", $a_perm),
91 "module_id" => array("integer", $a_module_id)
92 ),
93 array()
94 );
95 }
96
97 public static function removeScreenIdsOfChapter(
98 int $a_chap,
99 int $a_module_id = 0
100 ): void {
101 global $DIC;
102
103 $ilDB = $DIC->database();
104
105 $ilDB->manipulate(
106 "DELETE FROM help_map WHERE " .
107 " chap = " . $ilDB->quote($a_chap, "integer") .
108 " AND module_id = " . $ilDB->quote($a_module_id, "integer")
109 );
110 }
111
112 public static function getScreenIdsOfChapter(
113 int $a_chap,
114 int $a_module_id = 0
115 ): array {
116 global $DIC;
117
118 $ilDB = $DIC->database();
119
120 $set = $ilDB->query(
121 "SELECT * FROM help_map " .
122 " WHERE chap = " . $ilDB->quote($a_chap, "integer") .
123 " AND module_id = " . $ilDB->quote($a_module_id, "integer") .
124 " ORDER BY component, screen_id, screen_sub_id"
125 );
126 $screen_ids = array();
127 while ($rec = $ilDB->fetchAssoc($set)) {
128 if ($rec["screen_id"] == "-") {
129 $rec["screen_id"] = "";
130 }
131 if ($rec["screen_sub_id"] == "-") {
132 $rec["screen_sub_id"] = "";
133 }
134 $id = $rec["component"] . "/" . $rec["screen_id"] . "/" . $rec["screen_sub_id"];
135 if ($rec["perm"] != "" && $rec["perm"] != "-") {
136 $id .= "#" . $rec["perm"];
137 }
138 $screen_ids[] = $id;
139 }
140 return $screen_ids;
141 }
142
143 public static function getHelpSectionsForId(
144 string $a_screen_id,
145 int $a_ref_id
146 ): array {
147 global $DIC;
148
149 $ilDB = $DIC->database();
150 $ilAccess = $DIC->access();
151 $ilSetting = $DIC->settings();
152 $rbacreview = $DIC->rbac()->review();
153 $ilUser = $DIC->user();
154 $ilObjDataCache = $DIC["ilObjDataCache"];
155
156 if (defined('OH_REF_ID') && (int) OH_REF_ID > 0) {
157 $module = 0;
158 } else {
159 $module = (int) $ilSetting->get("help_module");
160 if ($module === 0) {
161 return array();
162 }
163 }
164
165 $sc_id = explode("/", $a_screen_id);
166 $chaps = array();
167 if ($sc_id[0] != "") {
168 if ($sc_id[1] == "") {
169 $sc_id[1] = "-";
170 }
171 if ($sc_id[2] == "") {
172 $sc_id[2] = "-";
173 }
174 $set = $ilDB->query(
175 "SELECT chap, perm FROM help_map JOIN lm_tree" .
176 " ON (help_map.chap = lm_tree.child) " .
177 " WHERE (component = " . $ilDB->quote($sc_id[0], "text") .
178 " OR component = " . $ilDB->quote("*", "text") . ")" .
179 " AND screen_id = " . $ilDB->quote($sc_id[1], "text") .
180 " AND screen_sub_id = " . $ilDB->quote($sc_id[2], "text") .
181 " AND module_id = " . $ilDB->quote($module, "integer") .
182 " ORDER BY lm_tree.lft"
183 );
184 while ($rec = $ilDB->fetchAssoc($set)) {
185 if ($rec["perm"] != "" && $rec["perm"] != "-") {
186 // check special "create*" permission
187 if ($rec["perm"] === "create*") {
188 $has_create_perm = false;
189
190 // check owner
191 if ($ilUser->getId() === $ilObjDataCache->lookupOwner(ilObject::_lookupObjId($a_ref_id))) {
192 $has_create_perm = true;
193 } elseif ($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID)) { // check admin
194 $has_create_perm = true;
195 } elseif ($ilAccess->checkAccess("read", "", $a_ref_id)) {
196 $perm = $rbacreview->getUserPermissionsOnObject($ilUser->getId(), $a_ref_id);
197 foreach ($perm as $p) {
198 if (strpos($p, "create_") === 0) {
199 $has_create_perm = true;
200 }
201 }
202 }
203 if ($has_create_perm) {
204 $chaps[] = $rec["chap"];
205 }
206 } elseif ($ilAccess->checkAccess($rec["perm"], "", $a_ref_id)) {
207 $chaps[] = $rec["chap"];
208 }
209 } else {
210 $chaps[] = $rec["chap"];
211 }
212 }
213 }
214 return $chaps;
215 }
216
224 public static function hasScreenIdSections(
225 string $a_screen_id
226 ): bool {
227 global $DIC;
228
229 $ilDB = $DIC->database();
230 $ilSetting = $DIC->settings();
231 $ilUser = $DIC->user();
232
233 if ($ilUser->getLanguage() !== "de") {
234 return false;
235 }
236
237 if ($ilSetting->get("help_mode") === "2") {
238 return false;
239 }
240
241 if (defined('OH_REF_ID') && (int) OH_REF_ID > 0) {
242 $module = 0;
243 } else {
244 $module = (int) $ilSetting->get("help_module");
245 if ($module === 0) {
246 return false;
247 }
248 }
249
250 $sc_id = explode("/", $a_screen_id);
251 if ($sc_id[0] != "") {
252 if ($sc_id[1] == "") {
253 $sc_id[1] = "-";
254 }
255 if ($sc_id[2] == "") {
256 $sc_id[2] = "-";
257 }
258 $set = $ilDB->query(
259 "SELECT chap, perm FROM help_map " .
260 " WHERE (component = " . $ilDB->quote($sc_id[0], "text") .
261 " OR component = " . $ilDB->quote("*", "text") . ")" .
262 " AND screen_id = " . $ilDB->quote($sc_id[1], "text") .
263 " AND screen_sub_id = " . $ilDB->quote($sc_id[2], "text") .
264 " AND module_id = " . $ilDB->quote($module, "integer")
265 );
266 while ($rec = $ilDB->fetchAssoc($set)) {
267 return true;
268
269 // no permission check, since it takes to much performance
270 // getHelpSectionsForId() does the permission checks.
271 /*if ($rec["perm"] != "" && $rec["perm"] != "-")
272 {
273 if ($ilAccess->checkAccess($rec["perm"], "", (int) $a_ref_id))
274 {
275 return true;
276 }
277 }
278 else
279 {
280 return true;
281 }*/
282 }
283 }
284 return false;
285 }
286
287 public static function deleteEntriesOfModule(
288 int $a_id
289 ): void {
290 global $DIC;
291
292 $ilDB = $DIC->database();
293
294 $ilDB->manipulate("DELETE FROM help_map WHERE " .
295 " module_id = " . $ilDB->quote($a_id, "integer"));
296 }
297}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static saveMappingEntry(int $a_chap, string $a_comp, string $a_screen_id, string $a_screen_sub_id, string $a_perm, int $a_module_id=0)
static getHelpSectionsForId(string $a_screen_id, int $a_ref_id)
static deleteEntriesOfModule(int $a_id)
static saveScreenIdsForChapter(int $a_chap, array $a_ids)
static getScreenIdsOfChapter(int $a_chap, int $a_module_id=0)
static removeScreenIdsOfChapter(int $a_chap, int $a_module_id=0)
ilDBInterface $db
static hasScreenIdSections(string $a_screen_id)
Has given screen Id any sections? Note: We removed the "ref_id" parameter here, since this method sho...
static _lookupObjId(int $ref_id)
const SYSTEM_ROLE_ID
Definition: constants.php:29
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
Interface ilDBInterface.
global $ilSetting
Definition: privfeed.php:17