ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
121 if ($this->checkAccessObject($oid, 'mcst')) {
122 return true;
124 return true;
125 }
126 break;
127
128 case 'frm~:html':
129 case 'exca~:html':
130 // $oid = userid
131 // foreach ($this->check_users as $user_id) {
132 if ($ilObjDataCache->lookupType($oid) == 'usr' && $oid == $user_id) {
133 return true;
134 }
135 // }
136 break;
137
138 case 'frm~d:html':
139 $draft_id = $usage['id'];
140
141 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
142 $oDraft = ilForumPostDraft::newInstanceByDraftId($draft_id);
143 if ($user_id == $oDraft->getPostAuthorId()) {
144 return true;
145 }
146 break;
147 case 'frm~h:html':
148 $history_id = $usage['id'];
149 include_once 'Modules/Forum/classes/class.ilForumDraftsHistory.php';
150 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
151
152 $oHistoryDraft = new ilForumDraftsHistory($history_id);
153 $oDraft = ilForumPostDraft::newInstanceByDraftId($oHistoryDraft->getDraftId());
154 if ($user_id == $oDraft->getPostAuthorId()) {
155 return true;
156 }
157 break;
158 case 'qpl:pg':
159 case 'qpl:html':
160 // test questions
161 if ($this->checkAccessTestQuestion($oid, $usage['id'])) {
162 return true;
163 }
164 break;
165
166 case 'gdf:pg':
167 // special check for glossary terms
168 if ($this->checkAccessGlossaryTerm($oid, $usage['id'])) {
169 return true;
170 }
171 break;
172
173 case 'sahs:pg':
174 // check for scorm pages
175 if ($this->checkAccessObject($oid, 'sahs')) {
176 return true;
177 }
178 break;
179
180 case 'prtf:pg':
181 // special check for portfolio pages
182 if ($this->checkAccessPortfolioPage($oid, $usage['id'])) {
183 return true;
184 }
185 break;
186
187 case 'blp:pg':
188 // special check for blog pages
189 if ($this->checkAccessBlogPage($oid, $usage['id'])) {
190 return true;
191 }
192 break;
193
194 case 'lobj:pg':
195 // special check for learning objective pages
196 if ($this->checkAccessLearningObjectivePage($oid, $usage['id'])) {
197 return true;
198 }
199 break;
200
201 case 'impr:pg':
202 include_once 'Services/Imprint/classes/class.ilImprint.php';
203
204 return (ilImprint::isActive() || $this->checkAccessObject(SYSTEM_FOLDER_ID, 'adm'));
205
206 case 'cstr:pg':
207 default:
208 // standard object check
209 if ($this->checkAccessObject($oid)) {
210 return true;
211 }
212 break;
213 }
214
215 return false;
216 }
217
218
226 protected function checkAccessObject($obj_id, $obj_type = '')
227 {
228 $ilAccess = $this->access;
230 $user_id = $ilUser->getId();
231
232 if (!$obj_type) {
233 $obj_type = ilObject::_lookupType($obj_id);
234 }
235 $ref_ids = ilObject::_getAllReferences($obj_id);
236
237 foreach ($ref_ids as $ref_id) {
238 // foreach ($this->check_users as $user_id) {
239 if ($ilAccess->checkAccessOfUser($user_id, "read", "view", $ref_id, $obj_type, $obj_id)) {
240 return true;
241 }
242 // }
243 }
244
245 return false;
246 }
247
248
258 protected function checkAccessTestQuestion($obj_id, $usage_id = 0)
259 {
260 $ilAccess = $this->access;
261
262 // give access if direct usage is readable
263 if ($this->checkAccessObject($obj_id)) {
264 return true;
265 }
266
267 $obj_type = ilObject::_lookupType($obj_id);
268 if ($obj_type == 'qpl') {
269 // give access if question pool is used by readable test
270 // for random selection of questions
271 include_once('./Modules/Test/classes/class.ilObjTestAccess.php');
273 foreach ($tests as $test_id) {
274 if ($this->checkAccessObject($test_id, 'tst')) {
275 return true;
276 }
277 }
278 }
279
280 return false;
281 }
282
283
293 protected function checkAccessGlossaryTerm($obj_id, $page_id)
294 {
295 // give access if glossary is readable
296 if ($this->checkAccessObject($obj_id)) {
297 return true;
298 }
299
300 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
301 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
302 $term_id = ilGlossaryDefinition::_lookupTermId($page_id);
303
304 include_once('./Services/Link/classes/class.ilInternalLink.php');
305 $sources = ilInternalLink::_getSourcesOfTarget('git', $term_id, 0);
306
307 if ($sources) {
308 foreach ($sources as $src) {
309 switch ($src['type']) {
310 // Give access if term is linked by a learning module with read access.
311 // The term including media is shown by the learning module presentation!
312 case 'lm:pg':
313 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
314 $src_obj_id = ilLMObject::_lookupContObjID($src['id']);
315 if ($this->checkAccessObject($src_obj_id, 'lm')) {
316 return true;
317 }
318 break;
319
320 // Don't yet give access if the term is linked by another glossary
321 // The link will lead to the origin glossary which is already checked
322 /*
323 case 'gdf:pg':
324 $src_term_id = ilGlossaryDefinition::_lookupTermId($src['id']);
325 $src_obj_id = ilGlossaryTerm::_lookGlossaryID($src_term_id);
326 if ($this->checkAccessObject($src_obj_id, 'glo'))
327 {
328 return true;
329 }
330 break;
331 */
332 }
333 }
334 }
335 }
336
337
346 protected function checkAccessPortfolioPage($obj_id, $page_id)
347 {
349 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
350 $access_handler = new ilPortfolioAccessHandler();
351 if ($access_handler->checkAccessOfUser($ilUser->getId(), "read", "view", $obj_id, "prtf")) {
352 return true;
353 }
354
355 return false;
356 }
357
358
367 protected function checkAccessBlogPage($obj_id)
368 {
370 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
371 $tree = new ilWorkspaceTree(0);
372 $node_id = $tree->lookupNodeId($obj_id);
373 if (!$node_id) {
374 return $this->checkAccessObject($obj_id);
375 } else {
376 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
377
378 $access_handler = new ilWorkspaceAccessHandler($tree);
379 if ($access_handler->checkAccessOfUser($tree, $ilUser->getId(), "read", "view", $node_id, "blog")) {
380 return true;
381 }
382 }
383
384 return false;
385 }
386
387
394 protected function checkAccessLearningObjectivePage($obj_id, $page_id)
395 {
396 include_once "Modules/Course/classes/class.ilCourseObjective.php";
398
399 return $this->checkAccessObject($crs_obj_id, 'crs');
400 }
401}
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.
Class ilWACCheckingClass.
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18