ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_once("./Services/Object/classes/class.ilObjectAccess.php");
6
18
31 static function _getCommands() {
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 static function _checkGoto($a_target) {
46 global $DIC;
47 $ilAccess = $DIC['ilAccess'];
48
49 $t_arr = explode("_", $a_target);
50
51 if ($t_arr[0] != "dcl" || ((int)$t_arr[1]) <= 0) {
52 return false;
53 }
54
55 if ($ilAccess->checkAccess("read", "", $t_arr[1])) {
56 return true;
57 }
58
59 return false;
60 }
61
62
69 protected static function isTableInDataCollection($table, $ref_id) {
70 foreach (ilObjDataCollection::_getAllReferences($table->getObjId()) as $reference) {
71 if ($reference == $ref_id) {
72 return true;
73 }
74 }
75 return false;
76 }
77
78
91 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "") {
92 global $DIC;
93 $ilUser = $DIC['ilUser'];
94 $lng = $DIC['lng'];
95 $rbacsystem = $DIC['rbacsystem'];
96 $ilAccess = $DIC['ilAccess'];
97
98 if ($a_user_id == "") {
99 $a_user_id = $ilUser->getId();
100 }
101 switch ($a_cmd) {
102 case "view":
103
105 && ! $rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id)
106 ) {
107 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
108
109 return false;
110 }
111 break;
112
113 // for permission query feature
114 case "infoScreen":
116 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
117 } else {
118 $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
119 }
120 break;
121 }
122 switch ($a_permission) {
123 case "read":
124 case "visible":
126 && (! $rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id))
127 ) {
128 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
129
130 return false;
131 }
132 break;
133 }
134
135 return true;
136 }
137
138
144 public static function _lookupOnline($a_id) {
145 global $DIC;
146 $ilDB = $DIC['ilDB'];
147
148 $q = "SELECT * FROM il_dcl_data WHERE id = " . $ilDB->quote($a_id, "integer");
149 $dcl_set = $ilDB->query($q);
150 $dcl_rec = $ilDB->fetchAssoc($dcl_set);
151
152 return $dcl_rec["is_online"];
153 }
154
155 //
156 // DataCollection specific Access-Checks
157 //
158
165 public static function checkAccessForDataCollectionId($data_collection_id) {
166 global $DIC;
167 $ilAccess = $DIC['ilAccess'];
168
169 $perm = false;
170 $references = ilObject2::_getAllReferences($data_collection_id);
171
172 if ($ilAccess->checkAccess("add_entry", "", array_shift($references))) {
173 $perm = true;
174 }
175
176 return $perm;
177 }
178
179
186 public static function checkActionForObjId($action, $obj_id) {
187 foreach (ilObject2::_getAllReferences($obj_id) as $ref_id) {
188 if (self::checkActionForRefId($action, $ref_id)) {
189 return true;
190 }
191 }
192
193 return false;
194 }
195
196
203 public static function checkActionForRefId($action, $ref_id) {
204 global $DIC;
205 $ilAccess = $DIC['ilAccess'];
206
211 return $ilAccess->checkAccess($action, "", $ref_id);
212 }
213
214
222 public static function hasWriteAccess($ref, $user_id = 0) {
223 global $DIC;
224 $ilAccess = $DIC['ilAccess'];
225
226 if ($user_id) {
227 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
228 }
229 return $ilAccess->checkAccess("write", "", $ref);
230 }
231
232
240 public static function hasEditAccess($ref, $user_id = 0) {
241 global $DIC;
242 $ilAccess = $DIC['ilAccess'];
243
244 if ($user_id) {
245 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
246 }
247 return $ilAccess->checkAccess("edit_content", "", $ref);
248 }
249
250
256 public static function hasAddRecordAccess($ref, $user_id = 0) {
257 global $DIC;
258 $ilAccess = $DIC['ilAccess'];
259
260 if ($user_id) {
261 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
262 }
263 return $ilAccess->checkAccess("add_entry", "", $ref);
264 }
265
266
272 public static function hasReadAccess($ref, $user_id = 0) {
273 global $DIC;
274 $ilAccess = $DIC['ilAccess'];
275
276 if ($user_id) {
277 return $ilAccess->checkAccessOfUser($user_id, "write", "", $ref);
278 }
279 return $ilAccess->checkAccess("read", "", $ref);
280 }
281
289 public static function hasAccessToTableView($tableview, $user_id = 0)
290 {
291 global $DIC;
292 $rbacreview = $DIC['rbacreview'];
293 $ilUser = $DIC['ilUser'];
294 if (!$tableview) {
295 return false;
296 }
297
298
299 if (is_numeric($tableview)) {
300 $tableview = ilDclTableView::find($tableview);
301 }
302
303 $assigned_roles = $rbacreview->assignedRoles($user_id ? $user_id : $ilUser->getId());
304 $allowed_roles = $tableview->getRoles();
305
306 return !empty(array_intersect($assigned_roles, $allowed_roles));
307 }
308
309
318 protected static function hasAccessToTable($table_id) {
319 $table = ilDclCache::getTableCache($table_id);
320 return $table->getIsVisible() || ($table_id == $table->getCollectionObject()->getFirstVisibleTableId());
321 }
322
323
331 public static function hasAccessTo($ref_id, $table_id, $tableview_id) {
333 $tableview = ilDclTableView::find($tableview_id);
334 $table = ilDclCache::getTableCache($table_id);
335
336 // is tableview in table and is table in datacollection
337 if (($tableview->getTableId() != $table_id)
338 || !self::isTableInDataCollection($table, $ref_id)) {
339 return false;
340 }
341
342 // check access
343 return self::hasWriteAccess($ref_id) || (
345 }
346
347
354 public static function hasAccessToFields($ref_id, $table_id) {
357 }
358
359
366 public static function hasAccessToEditTable($ref_id, $table_id) {
367 return self::hasAccessToFields($ref_id, $table_id);
368 }
369
370
378 public static function hasAccessToField($ref_id, $table_id, $field_id) {
379 $table = ilDclCache::getTableCache($table_id);
380 return in_array($field_id, $table->getFieldIds()) && self::hasAccessToFields($ref_id, $table_id);
381 }
382
389 public static function hasPermissionToAddRecord($ref_id, $table_id) {
390 $table = ilDclCache::getTableCache($table_id);
391 if (!self::isTableInDataCollection($table, $ref_id)){
392 return false;
393 }
394
396 || (ilObjDataCollectionAccess::hasAddRecordAccess($ref_id) && $table->getAddPerm() && $table->checkLimit());
397 }
398}
399
400?>
An exception for terminatinating execution or to throw for unit testing.
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.
global $lng
Definition: privfeed.php:17
$ref_id
Definition: sahs_server.php:39
global $ilDB
global $DIC
$ilUser
Definition: imgupload.php:18