ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitUserAssignmentRepository.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use ilException;
9 
11 {
12 
16  protected static $instance;
17 
18 
22  public static function getInstance()
23  {
24  if (!isset(self::$instance)) {
25  self::$instance = new self();
26  }
27 
28  return self::$instance;
29  }
30 
31 
39  public function findOrCreateAssignment($user_id, $position_id, $orgu_id)
40  {
44  $user_assignment = ilOrgUnitUserAssignment::where(array(
45  'user_id' => $user_id,
46  'position_id' => $position_id,
47  'orgu_id' => $orgu_id,
48  ))->first();
49  if (!$user_assignment) {
53  $user_assignment = new ilOrgUnitUserAssignment();
54  $user_assignment->setPositionId($position_id);
55  $user_assignment->setUserId($user_id);
56  $user_assignment->setOrguId($orgu_id);
57  $user_assignment->create();
58  }
59 
60  return $user_assignment;
61  }
62 
63 
71  public function findAllUserAssingmentsByUserIds($arr_user_ids) : array
72  {
73  $user_assignment_list = ilOrgUnitUserAssignment::where(['user_id' => $arr_user_ids], 'IN')->get();
74 
75  $user_assignment_list_by_user = [];
76  foreach ($user_assignment_list as $user_assignment) {
80  $user_assignment_list_by_user[$user_assignment->getUserId()][] = $user_assignment;
81  }
82 
83  return $user_assignment_list_by_user;
84  }
85 
86 
93  public function getEmplSuperiorList($arr_empl_user_ids) : array
94  {
95  global $DIC;
96 
97  $sql = "SELECT
98  orgu_ua.orgu_id AS orgu_id,
99  orgu_ua.user_id AS empl,
100  orgu_ua2.user_id as sup
101  FROM
102  il_orgu_ua as orgu_ua,
103  il_orgu_ua as orgu_ua2
104  WHERE
105  orgu_ua.orgu_id = orgu_ua2.orgu_id
106  and orgu_ua.user_id <> orgu_ua2.user_id
107  and orgu_ua.position_id = " . ilOrgUnitPosition::CORE_POSITION_EMPLOYEE . "
108  and orgu_ua2.position_id = " . ilOrgUnitPosition::CORE_POSITION_SUPERIOR . "
109  AND " . $DIC->database()->in('orgu_ua.user_id', $arr_empl_user_ids, false, 'integer');
110 
111  $st = $DIC->database()->query($sql);
112 
113  $empl_id__sup_ids = [];
114  while ($data = $DIC->database()->fetchAssoc($st)) {
115  $empl_id__sup_ids[$data['empl']][] = $data['sup'];
116  }
117  $this->arr_empl_user_ids = $empl_id__sup_ids;
118 
119  return $empl_id__sup_ids;
120  }
121 
122 
128  public function getPositionsOfUserId($user_id)
129  {
133  $positions = [];
134  foreach ($this->getAssignmentsOfUserId($user_id) as $assignment) {
135  $positions[] = ilOrgUnitPosition::find($assignment->getPositionId());
136  }
137 
138  return $positions;
139  }
140 
141 
150  public function getAssignmentOrFail($user_id, $position_id, $orgu_id)
151  {
153  'user_id' => $user_id,
154  'position_id' => $position_id,
155  'orgu_id' => $orgu_id,
156  ])->first();
157  if (!$ua) {
158  throw new ilException('UserAssignement not found');
159  }
160 
161  return $ua;
162  }
163 
164 
165  public function filterUserIdsDueToAuthorities($user_id, array $user_ids)
166  {
167  }
168 
169 
175  public function getAssignmentsOfUserId($user_id)
176  {
177  return ilOrgUnitUserAssignment::where(['user_id' => $user_id])->get();
178  }
179 
180 
186  public function getUserIdsOfOrgUnit($orgunit_ref_id)
187  {
188  return ilOrgUnitUserAssignment::where(['orgu_id' => $orgunit_ref_id])->getArray(null, 'user_id');
189  }
190 
191 
197  public function getUserIdsOfOrgUnits(array $orgunit_ref_id)
198  {
199  return ilOrgUnitUserAssignment::where(['orgu_id' => $orgunit_ref_id])->getArray(null, 'user_id');
200  }
201 
202 
212  public function getUserIdsOfOrgUnitsOfUsersPosition($position_id, $user_id, $recursive = false)
213  {
214  return ilOrgUnitUserAssignment::where(['orgu_id' => $this->getOrgUnitIdsOfUsersPosition($position_id, $user_id, $recursive)])
215  ->getArray(null, 'user_id');
216  }
217 
218 
225  public function getUserIdsOfOrgUnitsInPosition(array $orgu_ids, $position_id)
226  {
228  'orgu_id' => $orgu_ids,
229  'position_id' => $position_id,
230  ])->getArray(null, 'user_id');
231  }
232 
233 
243  public function getUserIdsOfUsersOrgUnitsInPosition($user_id, $users_position_id, $position_id, $recursive = false)
244  {
246  'orgu_id' => $this->getOrgUnitIdsOfUsersPosition($users_position_id, $user_id, $recursive),
247  'position_id' => $position_id,
248  ])->getArray(null, 'user_id');
249  }
250 
251 
260  public function getOrgUnitIdsOfUsersPosition($position_id, $user_id, $recursive = false)
261  {
262  $orgu_ids = ilOrgUnitUserAssignment::where([
263  'position_id' => $position_id,
264  'user_id' => $user_id,
265  ])->getArray(null, 'orgu_id');
266 
267  if (!$recursive) {
268  return $orgu_ids;
269  }
270 
271  $recursive_orgu_ids = [];
273  foreach ($orgu_ids as $orgu_id) {
274  $recursive_orgu_ids = $recursive_orgu_ids + $tree->getAllChildren($orgu_id);
275  }
276 
277  return $recursive_orgu_ids;
278  }
279 
280 
286  public function getUserIdsOfPosition($position_id)
287  {
289  'position_id' => $position_id,
290  ])->getArray(null, 'user_id');
291  }
292 
293 
299  public function getUserAssignmentsOfPosition($position_id)
300  {
302  'position_id' => $position_id,
303  ])->get();
304  }
305 
306 
312  public function deleteAllAssignmentsOfUser($user_id)
313  {
314  global $DIC;
315  $q = "DELETE FROM il_orgu_ua WHERE user_id = " . $DIC->database()->quote($user_id, "integer");
316  $DIC->database()->manipulate($q);
317  }
318 }
$data
Definition: storeScorm.php:23
getUserIdsOfUsersOrgUnitsInPosition($user_id, $users_position_id, $position_id, $recursive=false)
static where($where, $operator=null)
$DIC
Definition: xapitoken.php:46