ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMobStakeholder.php
Go to the documentation of this file.
1<?php
2
21
23{
25 protected ?ilDBInterface $database = null;
26
27 public function getId(): string
28 {
29 return 'mob';
30 }
31
32 public function getOwnerOfNewResources(): int
33 {
35 }
36
37 public function canBeAccessedByCurrentUser(ResourceIdentification $identification): bool
38 {
39 $mob_id = $this->resolveObjectId($identification);
40 if ($mob_id === null) {
41 return true;
42 }
43
44 foreach (\ilObjMediaObject::lookupUsages($mob_id) as $usage) {
46 // for content snippets we must get their usages and check them
47 switch ($usage["type"]) {
48 case "auth:pg":
49 // Mobs on the Loginpage should always be delivered
50 return true;
51 case "mep:pg":
52 $usages2 = ilMediaPoolPage::lookupUsages($usage["id"]);
53 foreach ($usages2 as $usage2) {
55 if ($this->checkAccessMobUsage($usage2, $oid2)) {
56 return true;
57 }
58 }
59 break;
60
61 case "clip":
62 if ($usage["id"] == $this->current_user) {
63 return true;
64 }
65 break;
66
67 default:
68 if ($oid !== null && $this->checkAccessMobUsage($usage, $oid)) {
69 return true;
70 }
71
72 if ($oid === null) {
73 /*
74 $this->logger->error(
75 sprintf(
76 "Could not determine parent obj_id for usage: %s",
77 json_encode($usage, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
78 )
79 );*/
80 }
81 break;
82 }
83 }
84
85 return false;
86 }
87
88 protected function checkAccessMobUsage(
89 array $usage,
90 int $oid
91 ): bool {
92 $user_id = $this->current_user;
93
94 switch ($usage['type']) {
95 case 'lm:pg':
96 if ($this->checkAccessObject($oid, 'lm')) {
97 return true;
98 }
99 break;
100
101 case 'news':
102 // media objects in news (media casts)
103 if ($this->checkAccessObject($oid)) {
104 return true;
106 return true;
107 }
108 break;
109
110 case 'frm~:html':
111 case 'exca~:html':
112 // $oid = userid
113 // foreach ($this->check_users as $user_id) {
114 if (ilObject::_lookupType($oid) === 'usr' && $oid == $user_id) {
115 return true;
116 }
117 // }
118 break;
119
120 case 'frm~d:html':
121 $draft_id = $usage['id'];
122
123 $oDraft = ilForumPostDraft::newInstanceByDraftId($draft_id);
124 if ($user_id == $oDraft->getPostAuthorId()) {
125 return true;
126 }
127 break;
128 case 'frm~h:html':
129 $history_id = $usage['id'];
130 $oHistoryDraft = new ilForumDraftsHistory($history_id);
131 $oDraft = ilForumPostDraft::newInstanceByDraftId($oHistoryDraft->getDraftId());
132 if ($user_id == $oDraft->getPostAuthorId()) {
133 return true;
134 }
135 break;
136 case 'qpl:pg':
137 case 'qpl:html':
138 // test questions
139 if ($this->checkAccessTestQuestion($oid, $usage['id'])) {
140 return true;
141 }
142 break;
143
144 case 'term:pg':
145 // special check for glossary terms
146 if ($this->checkAccessGlossaryTerm($oid, $usage['id'])) {
147 return true;
148 }
149 break;
150
151 case 'sahs:pg':
152 // check for scorm pages
153 if ($this->checkAccessObject($oid, 'sahs')) {
154 return true;
155 }
156 break;
157
158 case 'prtf:pg':
159 // special check for portfolio pages
160 if ($this->checkAccessPortfolioPage($oid, $usage['id'])) {
161 return true;
162 }
163 break;
164
165 case 'blp:pg':
166 // special check for blog pages
167 if ($this->checkAccessBlogPage($oid)) {
168 return true;
169 }
170 break;
171
172 case 'lobj:pg':
173 // special check for learning objective pages
174 if ($this->checkAccessLearningObjectivePage($oid, $usage['id'])) {
175 return true;
176 }
177 break;
178
179 case 'impr:pg':
180 return (ilImprint::isActive() || $this->checkAccessObject(SYSTEM_FOLDER_ID, 'adm'));
181
182 case 'cstr:pg':
183 default:
184 // standard object check
185 if ($this->checkAccessObject($oid)) {
186 return true;
187 }
188 break;
189 }
190
191 return false;
192 }
193
197 protected function checkAccessObject(
198 int $obj_id,
199 string $obj_type = ''
200 ): bool {
201 global $DIC;
202
203 $ilAccess = $DIC->access();
204 $user_id = $this->current_user;
205
206 if (!$obj_type) {
207 $obj_type = ilObject::_lookupType($obj_id);
208 }
209 $ref_ids = ilObject::_getAllReferences($obj_id);
210
211 foreach ($ref_ids as $ref_id) {
212 // foreach ($this->check_users as $user_id) {
213 if ($ilAccess->checkAccessOfUser($user_id, "read", "view", $ref_id, $obj_type, $obj_id)) {
214 return true;
215 }
216 // }
217 }
218
219 return false;
220 }
221
222
228 protected function checkAccessTestQuestion(
229 int $obj_id,
230 int $usage_id = 0
231 ): bool {
232 // give access if direct usage is readable
233 if ($this->checkAccessObject($obj_id)) {
234 return true;
235 }
236
237 $obj_type = ilObject::_lookupType($obj_id);
238 if ($obj_type == 'qpl') {
239 // give access if question pool is used by readable test
240 // for random selection of questions
242 foreach ($tests as $test_id) {
243 if ($this->checkAccessObject($test_id, 'tst')) {
244 return true;
245 }
246 }
247 }
248
249 return false;
250 }
251
252
260 protected function checkAccessGlossaryTerm(
261 int $obj_id,
262 int $page_id
263 ): bool {
264 // give access if glossary is readable
265 if ($this->checkAccessObject($obj_id)) {
266 return true;
267 }
268
269 $term_id = $page_id;
270
271 $sources = ilInternalLink::_getSourcesOfTarget('git', $term_id, 0);
272
273 if ($sources) {
274 foreach ($sources as $src) {
275 switch ($src['type']) {
276 // Give access if term is linked by a learning module with read access.
277 // The term including media is shown by the learning module presentation!
278 case 'lm:pg':
279 $src_obj_id = ilLMObject::_lookupContObjID($src['id']);
280 if ($this->checkAccessObject($src_obj_id, 'lm')) {
281 return true;
282 }
283 break;
284
285 // Don't yet give access if the term is linked by another glossary
286 // The link will lead to the origin glossary which is already checked
287 /*
288 case 'gdf:pg':
289 $src_term_id = ilGlossaryDefinition::_lookupTermId($src['id']);
290 $src_obj_id = ilGlossaryTerm::_lookGlossaryID($src_term_id);
291 if ($this->checkAccessObject($src_obj_id, 'glo'))
292 {
293 return true;
294 }
295 break;
296 */
297 }
298 }
299 }
300 return false;
301 }
302
303
309 protected function checkAccessPortfolioPage(
310 int $obj_id,
311 int $page_id
312 ): bool {
313 $access_handler = new ilPortfolioAccessHandler();
314 if ($access_handler->checkAccessOfUser($this->current_user, "read", "view", $obj_id, "prtf")) {
315 return true;
316 }
317
318 return false;
319 }
320
321
326 protected function checkAccessBlogPage(
327 int $obj_id
328 ): bool {
329 $tree = new ilWorkspaceTree(0);
330 $node_id = $tree->lookupNodeId($obj_id);
331 if (!$node_id) {
332 return $this->checkAccessObject($obj_id);
333 } else {
334 $access_handler = new ilWorkspaceAccessHandler($tree);
335 if ($access_handler->checkAccessOfUser($tree, $this->current_user, "read", "view", $node_id, "blog")) {
336 return true;
337 }
338 }
339
340 return false;
341 }
342
343
345 int $obj_id,
346 int $page_id
347 ): bool {
348 $crs_obj_id = ilCourseObjective::_lookupContainerIdByObjectiveId($page_id);
349
350 return $this->checkAccessObject($crs_obj_id, 'crs');
351 }
352
353 public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
354 {
355 // at this place we could handle de deletion of a resource. not needed for instruction files IMO.
356
357 return true;
358 }
359
360 public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
361 {
362 $this->initDB();
363 $object_id = $this->resolveObjectId($identification);
364 if ($object_id !== null) {
365 $references = ilObject::_getAllReferences($object_id);
366 $ref_id = array_shift($references);
367
368 return ilLink::_getLink($ref_id);
369 }
370 return null;
371 }
372
373 private function resolveObjectId(ResourceIdentification $identification): ?int
374 {
375 $this->initDB();
376 $r = $this->database->queryF(
377 "SELECT id FROM mob_data WHERE rid = %s;",
378 ['text'],
379 [$identification->serialize()]
380 );
381 $d = $this->database->fetchObject($r);
382
383 return (isset($d->id) ? (int) $d->id : null);
384 }
385
386 private function initDB(): void
387 {
388 global $DIC;
389 if ($this->database === null) {
390 $this->database = $DIC->database();
391 }
392 }
393}
const NEWS_PUBLIC
class ilcourseobjective
Class ilForumDraftHistory.
static newInstanceByDraftId(int $draft_id)
static isActive()
static _lookupContObjID(int $a_id)
get learning module id for lm object
static lookupUsages(int $a_id, bool $a_incl_hist=true)
Lookup usages of media object.
resourceHasBeenDeleted(ResourceIdentification $identification)
checkAccessPortfolioPage(int $obj_id, int $page_id)
Check access rights for portfolio pages.
canBeAccessedByCurrentUser(ResourceIdentification $identification)
checkAccessGlossaryTerm(int $obj_id, int $page_id)
Check access rights for glossary terms This checks also learning modules linking the term.
checkAccessBlogPage(int $obj_id)
Check access rights for blog pages.
checkAccessObject(int $obj_id, string $obj_type='')
Check access rights for an object by its object id.
checkAccessLearningObjectivePage(int $obj_id, int $page_id)
resolveObjectId(ResourceIdentification $identification)
checkAccessMobUsage(array $usage, int $oid)
checkAccessTestQuestion(int $obj_id, int $usage_id=0)
Check access rights for a test question This checks also tests with random selection of questions.
getLocationURIForResourceUsage(ResourceIdentification $identification)
static _lookupVisibility(int $a_news_id)
Lookup News Visibility.
static getParentObjectIdForUsage(array $a_usage, bool $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible see ilWebAccessChecker.
static lookupUsages(int $a_id, bool $a_include_history=true)
Lookup usages of media object.
static _getRandomTestsForQuestionPool(int $qpl_id)
Get all tests using a question pool for random selection.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
Access handler for portfolio NOTE: This file needs to stay in the classes directory,...
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...
lookupNodeId(int $a_obj_id)
Get node id for object id As we do not allow references in workspace this should not be ambigious.
const SYSTEM_FOLDER_ID
Definition: constants.php:35
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:66
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26