ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjDataCollectionAccess.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
16{
17
30 public static function _getCommands()
31 {
32 $commands = array(
33 array("permission" => "read", "cmd" => "render", "lang_var" => "show", "default" => true),
34 array("permission" => "write", "cmd" => "listRecords", "lang_var" => "edit_content"),
35 array("permission" => "write", "cmd" => "edit", "lang_var" => "settings"),
36 );
37
38 return $commands;
39 }
40
41
45 public static function _checkGoto($a_target)
46 {
47 global $DIC;
48 $ilAccess = $DIC['ilAccess'];
49
50 $t_arr = explode("_", $a_target);
51
52 if ($t_arr[0] != "dcl" || ((int) $t_arr[1]) <= 0) {
53 return false;
54 }
55
56 if ($ilAccess->checkAccess("read", "", $t_arr[1])) {
57 return true;
58 }
59
60 return false;
61 }
62
63
70 protected static function isTableInDataCollection($table, $ref_id)
71 {
72 foreach (ilObjDataCollection::_getAllReferences($table->getObjId()) as $reference) {
73 if ($reference == $ref_id) {
74 return true;
75 }
76 }
77 return false;
78 }
79
80
93 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
94 {
95 global $DIC;
96 $ilUser = $DIC['ilUser'];
97 $lng = $DIC['lng'];
98 $rbacsystem = $DIC['rbacsystem'];
99 $ilAccess = $DIC['ilAccess'];
100
101 if ($a_user_id == "") {
102 $a_user_id = $ilUser->getId();
103 }
104 switch ($a_cmd) {
105 case "view":
106
108 && !$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id)
109 ) {
110 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
111
112 return false;
113 }
114 break;
115
116 // for permission query feature
117 case "infoScreen":
119 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
120 } else {
121 $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
122 }
123 break;
124 }
125 switch ($a_permission) {
126 case "read":
127 case "visible":
129 && (!$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id))
130 ) {
131 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
132
133 return false;
134 }
135 break;
136 }
137
138 return true;
139 }
140
141
147 public static function _lookupOnline($a_id)
148 {
149 global $DIC;
150 $ilDB = $DIC['ilDB'];
151
152 $q = "SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($a_id, "integer");
153 $dcl_set = $ilDB->query($q);
154 $dcl_rec = $ilDB->fetchAssoc($dcl_set);
155
156 return $dcl_rec["is_online"];
157 }
158
159 //
160 // DataCollection specific Access-Checks
161 //
162
169 public static function checkAccessForDataCollectionId($data_collection_id)
170 {
171 global $DIC;
172 $ilAccess = $DIC['ilAccess'];
173
174 $perm = false;
175 $references = ilObject2::_getAllReferences($data_collection_id);
176
177 if ($ilAccess->checkAccess("add_entry", "", array_shift($references))) {
178 $perm = true;
179 }
180
181 return $perm;
182 }
183
184
191 public static function checkActionForObjId($action, $obj_id)
192 {
193 foreach (ilObject2::_getAllReferences($obj_id) as $ref_id) {
194 if (self::checkActionForRefId($action, $ref_id)) {
195 return true;
196 }
197 }
198
199 return false;
200 }
201
202
209 public static function checkActionForRefId($action, $ref_id)
210 {
211 global $DIC;
212 $ilAccess = $DIC['ilAccess'];
213
218 return $ilAccess->checkAccess($action, "", $ref_id);
219 }
220
221
229 public static function hasWriteAccess($ref, $user_id = 0)
230 {
231 global $DIC;
232 $ilAccess = $DIC['ilAccess'];
233
234 if ($user_id) {
235 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
236 }
237
238 return $ilAccess->checkAccess("write", "", $ref);
239 }
240
241
250 public static function hasEditAccess($ref, $user_id = 0)
251 {
252 global $DIC;
253 $ilAccess = $DIC['ilAccess'];
254
255 if ($user_id) {
256 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
257 }
258
259 return $ilAccess->checkAccess("edit_content", "", $ref);
260 }
261
262
269 public static function hasAddRecordAccess($ref, $user_id = 0)
270 {
271 global $DIC;
272 $ilAccess = $DIC['ilAccess'];
273
274 if ($user_id) {
275 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
276 }
277
278 return $ilAccess->checkAccess("add_entry", "", $ref);
279 }
280
281
288 public static function hasReadAccess($ref, $user_id = 0)
289 {
290 global $DIC;
291 $ilAccess = $DIC['ilAccess'];
292
293 if ($user_id) {
294 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
295 }
296
297 return $ilAccess->checkAccess("read", "", $ref);
298 }
299
300
309 public static function hasAccessToTableView($tableview, $user_id = 0)
310 {
311 global $DIC;
312 $rbacreview = $DIC['rbacreview'];
313 $ilUser = $DIC['ilUser'];
314 if (!$tableview) {
315 return false;
316 }
317
318 if (is_numeric($tableview)) {
319 $tableview = ilDclTableView::find($tableview);
320 }
321
322 $assigned_roles = $rbacreview->assignedRoles($user_id ? $user_id : $ilUser->getId());
323 $allowed_roles = $tableview->getRoles();
324
325 return !empty(array_intersect($assigned_roles, $allowed_roles));
326 }
327
328
337 protected static function hasAccessToTable($table_id)
338 {
340 return $table->getIsVisible() || ($table_id == $table->getCollectionObject()->getFirstVisibleTableId());
341 }
342
343
351 public static function hasAccessTo($ref_id, $table_id, $tableview_id)
352 {
354 $tableview = ilDclTableView::find($tableview_id);
356
357 // is tableview in table and is table in datacollection
358 if (($tableview->getTableId() != $table_id)
359 || !self::isTableInDataCollection($table, $ref_id)) {
360 return false;
361 }
362
363 // check access
364 return self::hasWriteAccess($ref_id) || (
365 self::hasReadAccess($ref_id) && self::hasAccessToTable($table_id) && self::hasAccessToTableView($tableview)
366 );
367 }
368
369
376 public static function hasAccessToFields($ref_id, $table_id)
377 {
379 && (self::hasWriteAccess($ref_id));
380 }
381
382
389 public static function hasAccessToEditTable($ref_id, $table_id)
390 {
391 return self::hasAccessToFields($ref_id, $table_id);
392 }
393
394
402 public static function hasAccessToField($ref_id, $table_id, $field_id)
403 {
405 return in_array($field_id, $table->getFieldIds()) && self::hasAccessToFields($ref_id, $table_id);
406 }
407
414 public static function hasPermissionToAddRecord($ref_id, $table_id)
415 {
417 if (!self::isTableInDataCollection($table, $ref_id)) {
418 return false;
419 }
420
422 || (ilObjDataCollectionAccess::hasAddRecordAccess($ref_id) && $table->getAddPerm() && $table->checkLimit());
423 }
424}
An exception for terminatinating execution or to throw for unit testing.
const IL_STATUS_MESSAGE
const IL_NO_OBJECT_ACCESS
static getTableCache($table_id=0)
Class ilObjDataCollectionAccess.
_checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcce...
static isTableInDataCollection($table, $ref_id)
static checkAccessForDataCollectionId($data_collection_id)
static hasAccessToEditTable($ref_id, $table_id)
static hasAccessToTableView($tableview, $user_id=0)
This only checks access to the tableview - if the full access check is required, use hasAccessTo($ref...
static checkActionForObjId($action, $obj_id)
static _lookupOnline($a_id)
Check wether datacollection is online.
static hasAccessToFields($ref_id, $table_id)
static hasEditAccess($ref, $user_id=0)
Has permission to view and edit all entries event when he is not the owner.
static _checkGoto($a_target)
check whether goto script will succeed
static hasPermissionToAddRecord($ref_id, $table_id)
static hasAccessToField($ref_id, $table_id, $field_id)
static hasAccessToTable($table_id)
returns true if either the table is visible for all users, or no tables are visible and this is the t...
static _getAllReferences($a_id)
get all reference ids of object
Class ilObjectAccess.
$action
if(empty($password)) $table
Definition: pwgen.php:24
global $DIC
Definition: saml.php:7
$lng
global $ilDB
$ilUser
Definition: imgupload.php:18