ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitUserAssignmentQueries.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
14  protected static $instance;
15 
16 
20  public static function getInstance()
21  {
22  if (!isset(self::$instance)) {
23  self::$instance = new self();
24  }
25 
26  return self::$instance;
27  }
28 
29 
35  public function getPositionsOfUserId($user_id)
36  {
40  $positions = [];
41  foreach ($this->getAssignmentsOfUserId($user_id) as $assignment) {
42  $positions[] = ilOrgUnitPosition::find($assignment->getPositionId());
43  }
44 
45  return $positions;
46  }
47 
48 
57  public function getAssignmentOrFail($user_id, $position_id, $orgu_id)
58  {
60  'user_id' => $user_id,
61  'position_id' => $position_id,
62  'orgu_id' => $orgu_id,
63  ])->first();
64  if (!$ua) {
65  throw new ilException('UserAssignement not found');
66  }
67 
68  return $ua;
69  }
70 
71 
72  public function filterUserIdsDueToAuthorities($user_id, array $user_ids)
73  {
74  }
75 
76 
82  public function getAssignmentsOfUserId($user_id)
83  {
84  return ilOrgUnitUserAssignment::where(['user_id' => $user_id])->get();
85  }
86 
92  public function getAssignmentsOfUserIdAndPosition(int $user_id, int $position_id) : array
93  {
95  [
96  'user_id' => $user_id,
97  'position_id' => $position_id
98  ]
99  )->get();
100  }
101 
107  public function getUserIdsOfOrgUnit($orgunit_ref_id)
108  {
109  return ilOrgUnitUserAssignment::where(['orgu_id' => $orgunit_ref_id])
110  ->getArray(null, 'user_id');
111  }
112 
113 
119  public function getUserIdsOfOrgUnits(array $orgunit_ref_id)
120  {
121  return ilOrgUnitUserAssignment::where(['orgu_id' => $orgunit_ref_id])
122  ->getArray(null, 'user_id');
123  }
124 
125 
135  public function getUserIdsOfOrgUnitsOfUsersPosition($position_id, $user_id, $recursive = false)
136  {
137  return ilOrgUnitUserAssignment::where(['orgu_id' => $this->getOrgUnitIdsOfUsersPosition($position_id, $user_id, $recursive)])
138  ->getArray(null, 'user_id');
139  }
140 
141 
148  public function getUserIdsOfOrgUnitsInPosition(array $orgu_ids, $position_id)
149  {
151  'orgu_id' => $orgu_ids,
152  'position_id' => $position_id,
153  ])->getArray(null, 'user_id');
154  }
155 
156 
166  public function getUserIdsOfUsersOrgUnitsInPosition($user_id, $users_position_id, $position_id, $recursive = false)
167  {
169  'orgu_id' => $this->getOrgUnitIdsOfUsersPosition($users_position_id, $user_id, $recursive),
170  'position_id' => $position_id,
171  ])->getArray(null, 'user_id');
172  }
173 
174 
183  public function getOrgUnitIdsOfUsersPosition($position_id, $user_id, $recursive = false)
184  {
185  $orgu_ids = ilOrgUnitUserAssignment::where([
186  'position_id' => $position_id,
187  'user_id' => $user_id,
188  ])->getArray(null, 'orgu_id');
189 
190  if (!$recursive) {
191  return $orgu_ids;
192  }
193 
194  $recursive_orgu_ids = [];
196  foreach ($orgu_ids as $orgu_id) {
197  $recursive_orgu_ids = $recursive_orgu_ids + $tree->getAllChildren($orgu_id);
198  }
199 
200  return $recursive_orgu_ids;
201  }
202 
203 
209  public function getUserIdsOfPosition($position_id)
210  {
212  'position_id' => $position_id,
213  ])->getArray(null, 'user_id');
214  }
215 
216 
222  public function getUserAssignmentsOfPosition($position_id)
223  {
225  'position_id' => $position_id,
226  ])->get();
227  }
228 
229 
235  public function deleteAllAssignmentsOfUser($user_id)
236  {
237  global $DIC;
238  $q = "DELETE FROM il_orgu_ua WHERE user_id = " . $DIC->database()->quote($user_id, "integer");
239  $DIC->database()->manipulate($q);
240  }
241 }
getUserIdsOfOrgUnitsInPosition(array $orgu_ids, $position_id)
static where($where, $operator=null)
getAssignmentsOfUserIdAndPosition(int $user_id, int $position_id)
getAssignmentOrFail($user_id, $position_id, $orgu_id)
getOrgUnitIdsOfUsersPosition($position_id, $user_id, $recursive=false)
getUserIdsOfUsersOrgUnitsInPosition($user_id, $users_position_id, $position_id, $recursive=false)
$DIC
Definition: xapitoken.php:46
getUserIdsOfOrgUnitsOfUsersPosition($position_id, $user_id, $recursive=false)