ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclTableHelper.php
Go to the documentation of this file.
1 <?php
2 
9 
13  protected $obj_id = 0;
17  protected $ref_id = 0;
21  protected $rbac_review;
25  protected $user;
29  protected $database;
30 
31 
42  $this->obj_id = $obj_id;
43  $this->ref_id = $ref_id;
44  $this->rbac_review = $rbac_review;
45  $this->user = $user;
46  $this->database = $database;
47  }
48 
49 
54  $visible_tables_for_data_collection = $this->getAllVisibleTablesForDataColleciton();
55  $standard_views_for_data_collection = $this->getStandardViewsByVisibleTables($visible_tables_for_data_collection);
56 
57  $roles_ids = $this->getRolesIdsByViews($standard_views_for_data_collection);
58 
59  $roles_with_read_acces_ids = $this->getRolesIdsWithReadAccessOnDataCollection();
60 
61  //check if there are roles with rbac read right on the datacollection but without read right on any table view
62  $roles_with_no_read_right_on_any_standard_view = array_diff($roles_with_read_acces_ids, $roles_ids);
63 
64  $roles_data = $this->rbac_review->getRolesForIDs($roles_with_no_read_right_on_any_standard_view, true);
65  $role_titles = [];
66  if (!empty($roles_data)) {
67  foreach ($roles_data as $role_data) {
68  $role_titles[] = $role_data['title'];
69  }
70  }
71 
72  return $role_titles;
73  }
74 
75 
80  $rbac_roles = $this->rbac_review->getParentRoleIds($this->ref_id);
81  $roles_with_read_acces_ids = [];
82  //get all roles with read access on data collection
83  foreach ($rbac_roles as $role) {
84  $operations = $this->rbac_review->getActiveOperationsOfRole($this->ref_id, $role['rol_id']);
85  //3 corresponds to the read rbac right
86  if (!empty($operations) && in_array(3, $operations)) {
87  $roles_with_read_acces_ids[] = $role['rol_id'];
88  }
89  }
90 
91  return $roles_with_read_acces_ids;
92  }
93 
94 
100  protected function getRolesIdsByViews($views_for_data_collection) {
101  $roles_ids = [];
106  foreach ($views_for_data_collection as $key => $view_for_data_collection_array_of_objects) {
107  foreach ($view_for_data_collection_array_of_objects as $view_for_data_collection_object) {
108  $ilDclTableView = ilDclTableView::find($view_for_data_collection_object->getId());
109  $roles_of_view = $ilDclTableView->getRoles();
110  $roles_ids = array_merge($roles_ids, $roles_of_view);
111  }
112  }
113 
114  return $roles_ids;
115  }
116 
117 
123  protected function getStandardViewsByVisibleTables($visible_tables_for_data_collection) {
124  $standard_views_for_data_collection = [];
125  foreach ($visible_tables_for_data_collection as $visible_table) {
126  $standard_views_for_data_collection[] = ilDclTableView::where(
127  [
128  'table_id' => $visible_table['id']
129  ]
130  )->get();
131  }
132 
133  return $standard_views_for_data_collection;
134  }
135 
136 
141  $visible_tables_for_data_collection = [];
142  $res = $this->database->queryF(
143  "SELECT * FROM il_dcl_table WHERE obj_id = %s AND is_visible = 1", array('integer'), array($this->obj_id)
144  );
145  while ($rec = $this->database->fetchAssoc($res)) {
146  $visible_tables_for_data_collection[] = $rec;
147  }
148 
149  return $visible_tables_for_data_collection;
150  }
151 
152 
154  // admin user has always access to the views of a data collection
155  if ($this->user->getId() == 6) {
156  return true;
157  }
158 
159  $visible_tables_for_data_collection = $this->getAllVisibleTablesForDataColleciton();
160  $standard_views_for_data_collection = $this->getStandardViewsByVisibleTables($visible_tables_for_data_collection);
161 
162  $roles_ids = $this->getRolesIdsByViews($standard_views_for_data_collection);
163 
164  $user_ids_with_read_right_on_any_standard_view = [];
165  foreach ($roles_ids as $role_id) {
166  $assigned_users = $this->rbac_review->assignedUsers($role_id);
167  if (!empty($assigned_users)) {
168  $user_ids_with_read_right_on_any_standard_view[] = array_merge($user_ids_with_read_right_on_any_standard_view, $assigned_users);
169  }
170  }
171 
172  //check if current user id is in the array of user ids with read right on standard view
173  if ($this->in_array_r($this->user->getId(), $user_ids_with_read_right_on_any_standard_view)) {
174  return true;
175  } else {
176  return false;
177  }
178  }
179 
180 
188  protected function in_array_r($needle, $haystack, $strict = false) {
189  foreach ($haystack as $item) {
190  if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && $this->in_array_r($needle, $item, $strict))) {
191  return true;
192  }
193  }
194 
195  return false;
196  }
197 }
getStandardViewsByVisibleTables($visible_tables_for_data_collection)
Class ilDclTableHelper.
in_array_r($needle, $haystack, $strict=false)
static where($where, $operator=null)
user()
Definition: user.php:4
Interface ilDBInterface.
__construct(int $obj_id, int $ref_id, ilRbacReview $rbac_review, ilObjUser $user, ilDBInterface $database)
ilDclTableHelper constructor.
Create styles array
The data for the language used.
class ilRbacReview Contains Review functions of core Rbac.