ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDclTableHelper.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
14  protected $obj_id = 0;
18  protected $ref_id = 0;
22  protected $rbac_review;
26  protected $user;
30  protected $database;
31 
32 
43  {
44  $this->obj_id = $obj_id;
45  $this->ref_id = $ref_id;
46  $this->rbac_review = $rbac_review;
47  $this->user = $user;
48  $this->database = $database;
49  }
50 
51 
56  {
57  $visible_tables_for_data_collection = $this->getAllVisibleTablesForDataColleciton();
58  $standard_views_for_data_collection = $this->getStandardViewsByVisibleTables($visible_tables_for_data_collection);
59 
60  $roles_ids = $this->getRolesIdsByViews($standard_views_for_data_collection);
61 
62  $roles_with_read_acces_ids = $this->getRolesIdsWithReadAccessOnDataCollection();
63 
64  //check if there are roles with rbac read right on the datacollection but without read right on any table view
65  $roles_with_no_read_right_on_any_standard_view = array_diff($roles_with_read_acces_ids, $roles_ids);
66 
67  $roles_data = $this->rbac_review->getRolesForIDs($roles_with_no_read_right_on_any_standard_view, true);
68  $role_titles = [];
69  if (!empty($roles_data)) {
70  foreach ($roles_data as $role_data) {
71  $role_titles[] = $role_data['title'];
72  }
73  }
74 
75  return $role_titles;
76  }
77 
78 
83  {
84  $rbac_roles = $this->rbac_review->getParentRoleIds($this->ref_id);
85  $roles_with_read_acces_ids = [];
86  //get all roles with read access on data collection
87  foreach ($rbac_roles as $role) {
88  $operations = $this->rbac_review->getActiveOperationsOfRole($this->ref_id, $role['rol_id']);
89  //3 corresponds to the read rbac right
90  if (!empty($operations) && in_array(3, $operations)) {
91  $roles_with_read_acces_ids[] = $role['rol_id'];
92  }
93  }
94 
95  return $roles_with_read_acces_ids;
96  }
97 
98 
104  protected function getRolesIdsByViews($views_for_data_collection)
105  {
106  $roles_ids = [];
111  foreach ($views_for_data_collection as $key => $view_for_data_collection_array_of_objects) {
112  foreach ($view_for_data_collection_array_of_objects as $view_for_data_collection_object) {
113  $ilDclTableView = ilDclTableView::find($view_for_data_collection_object->getId());
114  $roles_of_view = $ilDclTableView->getRoles();
115  $roles_ids = array_merge($roles_ids, $roles_of_view);
116  }
117  }
118 
119  return $roles_ids;
120  }
121 
122 
128  protected function getStandardViewsByVisibleTables($visible_tables_for_data_collection)
129  {
130  $standard_views_for_data_collection = [];
131  foreach ($visible_tables_for_data_collection as $visible_table) {
132  $standard_views_for_data_collection[] = ilDclTableView::where(
133  [
134  'table_id' => $visible_table['id']
135  ]
136  )->get();
137  }
138 
139  return $standard_views_for_data_collection;
140  }
141 
142 
147  {
148  $visible_tables_for_data_collection = [];
149  $res = $this->database->queryF(
150  "SELECT * FROM il_dcl_table WHERE obj_id = %s AND is_visible = 1",
151  array('integer'),
152  array($this->obj_id)
153  );
154  while ($rec = $this->database->fetchAssoc($res)) {
155  $visible_tables_for_data_collection[] = $rec;
156  }
157 
158  return $visible_tables_for_data_collection;
159  }
160 
161 
163  {
164  // admin user has always access to the views of a data collection
165  if ($this->user->getId() == 6) {
166  return true;
167  }
168 
169  $visible_tables_for_data_collection = $this->getAllVisibleTablesForDataColleciton();
170  $standard_views_for_data_collection = $this->getStandardViewsByVisibleTables($visible_tables_for_data_collection);
171 
172  $roles_ids = $this->getRolesIdsByViews($standard_views_for_data_collection);
173 
174  $user_ids_with_read_right_on_any_standard_view = [];
175  foreach ($roles_ids as $role_id) {
176  $assigned_users = $this->rbac_review->assignedUsers($role_id);
177  if (!empty($assigned_users)) {
178  $user_ids_with_read_right_on_any_standard_view[] = array_merge($user_ids_with_read_right_on_any_standard_view, $assigned_users);
179  }
180  }
181 
182  //check if current user id is in the array of user ids with read right on standard view
183  if ($this->in_array_r($this->user->getId(), $user_ids_with_read_right_on_any_standard_view)) {
184  return true;
185  } else {
186  return false;
187  }
188  }
189 
190 
198  protected function in_array_r($needle, $haystack, $strict = false)
199  {
200  foreach ($haystack as $item) {
201  if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && $this->in_array_r($needle, $item, $strict))) {
202  return true;
203  }
204  }
205 
206  return false;
207  }
208 }
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.
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18
__construct($obj_id, $ref_id, ilRbacReview $rbac_review, ilObjUser $user, ilDBInterface $database)
ilDclTableHelper constructor.
class ilRbacReview Contains Review functions of core Rbac.