ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjMediaObjectAccess.php
Go to the documentation of this file.
1<?php
2require_once('./Services/WebAccessChecker/interfaces/interface.ilWACCheckingClass.php');
3require_once('./Services/MediaObjects/classes/class.ilObjMediaObject.php');
4
12{
16 protected $obj_data_cache;
17
21 protected $user;
22
26 protected $access;
27
28
32 public function __construct()
33 {
34 global $DIC;
35
36 $this->obj_data_cache = $DIC["ilObjDataCache"];
37 $this->user = $DIC->user();
38 $this->access = $DIC->access();
39 }
40
41
47 public function canBeDelivered(ilWACPath $ilWACPath)
48 {
49 preg_match("/.\\/data\\/.*\\/mm_([0-9]*)\\/.*/ui", $ilWACPath->getPath(), $matches);
50 $obj_id = $matches[1];
51
52 return $this->checkAccessMob($obj_id);
53 }
54
55
61 protected function checkAccessMob($obj_id)
62 {
63 foreach (ilObjMediaObject::lookupUsages($obj_id) as $usage) {
65
66 // for content snippets we must get their usages and check them
67 switch ($usage["type"]) {
68 case "auth:pg":
69 // Mobs on the Loginpage should always be delivered
70 return true;
71 case "mep:pg":
72 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
73 $usages2 = ilMediaPoolPage::lookupUsages($usage["id"]);
74 foreach ($usages2 as $usage2) {
76 if ($this->checkAccessMobUsage($usage2, $oid2)) {
77 return true;
78 }
79 }
80 break;
81
82 default:
83 if ($this->checkAccessMobUsage($usage, $oid)) {
84 return true;
85 }
86 break;
87 }
88 }
89
90 return false;
91 }
92
93
100 protected function checkAccessMobUsage($usage, $oid)
101 {
105 $ilObjDataCache = $this->obj_data_cache;
107 $user_id = $ilUser->getId();
108
109 switch ($usage['type']) {
110 case 'lm:pg':
111 if ($this->checkAccessObject($oid, 'lm')) {
112 return true;
113 }
114 break;
115
116 case 'news':
117 // media objects in news (media casts)
118 include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
119 include_once("./Services/News/classes/class.ilNewsItem.php");
120 if ($this->checkAccessObject($oid)) {
121 return true;
123 return true;
124 }
125 break;
126
127 case 'frm~:html':
128 case 'exca~:html':
129 // $oid = userid
130 // foreach ($this->check_users as $user_id) {
131 if ($ilObjDataCache->lookupType($oid) == 'usr' && $oid == $user_id) {
132 return true;
133 }
134 // }
135 break;
136
137 case 'frm~d:html':
138 $draft_id = $usage['id'];
139
140 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
141 $oDraft = ilForumPostDraft::newInstanceByDraftId($draft_id);
142 if ($user_id == $oDraft->getPostAuthorId()) {
143 return true;
144 }
145 break;
146 case 'frm~h:html':
147 $history_id = $usage['id'];
148 include_once 'Modules/Forum/classes/class.ilForumDraftsHistory.php';
149 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
150
151 $oHistoryDraft = new ilForumDraftsHistory($history_id);
152 $oDraft = ilForumPostDraft::newInstanceByDraftId($oHistoryDraft->getDraftId());
153 if ($user_id == $oDraft->getPostAuthorId()) {
154 return true;
155 }
156 break;
157 case 'qpl:pg':
158 case 'qpl:html':
159 // test questions
160 if ($this->checkAccessTestQuestion($oid, $usage['id'])) {
161 return true;
162 }
163 break;
164
165 case 'gdf:pg':
166 // special check for glossary terms
167 if ($this->checkAccessGlossaryTerm($oid, $usage['id'])) {
168 return true;
169 }
170 break;
171
172 case 'sahs:pg':
173 // check for scorm pages
174 if ($this->checkAccessObject($oid, 'sahs')) {
175 return true;
176 }
177 break;
178
179 case 'prtf:pg':
180 // special check for portfolio pages
181 if ($this->checkAccessPortfolioPage($oid, $usage['id'])) {
182 return true;
183 }
184 break;
185
186 case 'blp:pg':
187 // special check for blog pages
188 if ($this->checkAccessBlogPage($oid, $usage['id'])) {
189 return true;
190 }
191 break;
192
193 case 'lobj:pg':
194 // special check for learning objective pages
195 if ($this->checkAccessLearningObjectivePage($oid, $usage['id'])) {
196 return true;
197 }
198 break;
199
200 case 'impr:pg':
201 include_once 'Services/Imprint/classes/class.ilImprint.php';
202
203 return (ilImprint::isActive() || $this->checkAccessObject(SYSTEM_FOLDER_ID, 'adm'));
204
205 case 'cstr:pg':
206 default:
207 // standard object check
208 if ($this->checkAccessObject($oid)) {
209 return true;
210 }
211 break;
212 }
213
214 return false;
215 }
216
217
225 protected function checkAccessObject($obj_id, $obj_type = '')
226 {
227 $ilAccess = $this->access;
229 $user_id = $ilUser->getId();
230
231 if (!$obj_type) {
232 $obj_type = ilObject::_lookupType($obj_id);
233 }
234 $ref_ids = ilObject::_getAllReferences($obj_id);
235
236 foreach ($ref_ids as $ref_id) {
237 // foreach ($this->check_users as $user_id) {
238 if ($ilAccess->checkAccessOfUser($user_id, "read", "view", $ref_id, $obj_type, $obj_id)) {
239 return true;
240 }
241 // }
242 }
243
244 return false;
245 }
246
247
257 protected function checkAccessTestQuestion($obj_id, $usage_id = 0)
258 {
259 $ilAccess = $this->access;
260
261 // give access if direct usage is readable
262 if ($this->checkAccessObject($obj_id)) {
263 return true;
264 }
265
266 $obj_type = ilObject::_lookupType($obj_id);
267 if ($obj_type == 'qpl') {
268 // give access if question pool is used by readable test
269 // for random selection of questions
270 include_once('./Modules/Test/classes/class.ilObjTestAccess.php');
272 foreach ($tests as $test_id) {
273 if ($this->checkAccessObject($test_id, 'tst')) {
274 return true;
275 }
276 }
277 }
278
279 return false;
280 }
281
282
292 protected function checkAccessGlossaryTerm($obj_id, $page_id)
293 {
294 // give access if glossary is readable
295 if ($this->checkAccessObject($obj_id)) {
296 return true;
297 }
298
299 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
300 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
301 $term_id = ilGlossaryDefinition::_lookupTermId($page_id);
302
303 include_once('./Services/Link/classes/class.ilInternalLink.php');
304 $sources = ilInternalLink::_getSourcesOfTarget('git', $term_id, 0);
305
306 if ($sources) {
307 foreach ($sources as $src) {
308 switch ($src['type']) {
309 // Give access if term is linked by a learning module with read access.
310 // The term including media is shown by the learning module presentation!
311 case 'lm:pg':
312 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
313 $src_obj_id = ilLMObject::_lookupContObjID($src['id']);
314 if ($this->checkAccessObject($src_obj_id, 'lm')) {
315 return true;
316 }
317 break;
318
319 // Don't yet give access if the term is linked by another glossary
320 // The link will lead to the origin glossary which is already checked
321 /*
322 case 'gdf:pg':
323 $src_term_id = ilGlossaryDefinition::_lookupTermId($src['id']);
324 $src_obj_id = ilGlossaryTerm::_lookGlossaryID($src_term_id);
325 if ($this->checkAccessObject($src_obj_id, 'glo'))
326 {
327 return true;
328 }
329 break;
330 */
331 }
332 }
333 }
334 }
335
336
345 protected function checkAccessPortfolioPage($obj_id, $page_id)
346 {
348 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
349 $access_handler = new ilPortfolioAccessHandler();
350 if ($access_handler->checkAccessOfUser($ilUser->getId(), "read", "view", $obj_id, "prtf")) {
351 return true;
352 }
353
354 return false;
355 }
356
357
366 protected function checkAccessBlogPage($obj_id)
367 {
369 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
370 $tree = new ilWorkspaceTree(0);
371 $node_id = $tree->lookupNodeId($obj_id);
372 if (!$node_id) {
373 return $this->checkAccessObject($obj_id);
374 } else {
375 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
376
377 $access_handler = new ilWorkspaceAccessHandler($tree);
378 if ($access_handler->checkAccessOfUser($tree, $ilUser->getId(), "read", "view", $node_id, "blog")) {
379 return true;
380 }
381 }
382
383 return false;
384 }
385
386
393 protected function checkAccessLearningObjectivePage($obj_id, $page_id)
394 {
395 include_once "Modules/Course/classes/class.ilCourseObjective.php";
397
398 return $this->checkAccessObject($crs_obj_id, 'crs');
399 }
400}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const NEWS_PUBLIC
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
Class ilForumDraftHistory.
static newInstanceByDraftId($draft_id)
static _lookupTermId($a_def_id)
Looks up term id for a definition id.
static isActive()
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static lookupUsages($a_id, $a_incl_hist=true)
Lookup usages of media object.
static _lookupVisibility($a_news_id)
Lookup News Visibility.
static _lookupPublicFiles($a_id)
Check wether files should be public.
Class ilObjMediaObjectAccess.
canBeDelivered(ilWACPath $ilWACPath)
checkAccessLearningObjectivePage($obj_id, $page_id)
checkAccessGlossaryTerm($obj_id, $page_id)
Check access rights for glossary terms This checks also learning modules linking the term.
checkAccessPortfolioPage($obj_id, $page_id)
Check access rights for portfolio pages.
checkAccessTestQuestion($obj_id, $usage_id=0)
Check access rights for a test question This checks also tests with random selection of questions.
checkAccessBlogPage($obj_id)
Check access rights for blog pages.
checkAccessObject($obj_id, $obj_type='')
Check access rights for an object by its object id.
static getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible.
static lookupUsages($a_id, $a_include_history=true)
Lookup usages of media object.
static _getRandomTestsForQuestionPool($qpl_id)
Get all tests using a question pool for random selection.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Access handler for portfolio.
Class ilWACPath.
Access handler for personal workspace.
Tree handler for personal workspace.
$tests
Definition: bench.php:104
Class ilWACCheckingClass.
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18