ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilOrgUnitUserAssignmentDBRepository Class Reference
+ Inheritance diagram for ilOrgUnitUserAssignmentDBRepository:
+ Collaboration diagram for ilOrgUnitUserAssignmentDBRepository:

Public Member Functions

 __construct (ilDBInterface $db, ilAppEventHandler $handler=null)
 
 get (int $user_id, int $position_id, int $orgu_id)
 Get existing user assignment or create a new one. More...
 
 find (int $user_id, int $position_id, int $orgu_id)
 Find assignment for user, position and org-unit Does not create new assigment, returns null if no assignment exists. More...
 
 store (ilOrgUnitUserAssignment $assignment)
 Store assignment to db. More...
 
 delete (ilOrgUnitUserAssignment $assignment)
 Delete a single assignment Returns false if no assignment was found. More...
 
 deleteByUser (int $user_id)
 Delete all assignments for a user_id Returns false if no assignments were found. More...
 
 getByUsers (array $user_ids)
 Get assignments for one or more users. More...
 
 getByPosition (int $position_id)
 Get all assignments for a position. More...
 
 getByOrgUnit (int $orgu_id)
 Get all assignments for an org-unit. More...
 
 getByUserAndPosition (int $user_id, int $position_id)
 Get assignments for a user in a dedicated position. More...
 
 getUsersByOrgUnits (array $orgu_ids)
 Get all users for a given set of org-units. More...
 
 getUsersByPosition (int $position_id)
 Get all users with a certain position. More...
 
 getUsersByOrgUnitsAndPosition (array $orgu_ids, int $position_id)
 Get all users in a specific position for a given set of org-units. More...
 
 getUsersByUserAndPosition (int $user_id, int $position_id, bool $recursive=false)
 Get all users from org-units where the user has a certain position i.e. More...
 
 getFilteredUsersByUserAndPosition (int $user_id, int $position_id, int $position_filter_id, bool $recursive=false)
 Get all users with position $position_filter_id from those org-units, where the user has position $position_id i.e. More...
 
 getOrgUnitsByUser (int $user_id)
 Get all org-units a user is assigned to. More...
 
 getOrgUnitsByUserAndPosition (int $user_id, int $position_id, bool $recursive=false)
 Get all org-units where a user has a dedicated position. More...
 
 getPositionsByUser (int $user_id)
 Get all positions a user is assigned to. More...
 
 getSuperiorsByUsers (array $user_ids)
 Get all superiors of one or more users $user_id => [ $superior_ids ]. More...
 

Data Fields

const TABLE_NAME = 'il_orgu_ua'
 

Protected Member Functions

 getPositionRepo ()
 
 insert (ilOrgUnitUserAssignment $assignment)
 
 update (ilOrgUnitUserAssignment $assignment)
 
 raiseEvent (string $event, ilOrgUnitUserAssignment $assignment)
 

Protected Attributes

ilDBInterface $db
 
ilAppEventHandler $ilAppEventHandler
 
ilOrgUnitPositionDBRepository $positionRepo
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitUserAssignmentDBRepository::__construct ( ilDBInterface  $db,
ilAppEventHandler  $handler = null 
)

Definition at line 28 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $db, $DIC, and $handler.

29  {
30  $this->db = $db;
31 
32  if ($handler) {
33  $this->ilAppEventHandler = $handler;
34  } else {
35  global $DIC;
36  $this->ilAppEventHandler = $DIC->event();
37  }
38  }
Global event handler.
global $DIC
Definition: feed.php:28
$handler
Definition: index.php:18

Member Function Documentation

◆ delete()

ilOrgUnitUserAssignmentDBRepository::delete ( ilOrgUnitUserAssignment  $assignment)

Delete a single assignment Returns false if no assignment was found.

Implements OrgUnitUserAssignmentRepository.

Definition at line 142 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References raiseEvent().

142  : bool
143  {
144  if ($assignment->getId() === 0) {
145  return false;
146  }
147 
148  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
149  . ' WHERE id = ' . $this->db->quote($assignment->getId(), 'integer');
150  $rows = $this->db->manipulate($query);
151 
152  if ($rows > 0) {
153  $this->raiseEvent('deassignUserFromPosition', $assignment);
154  return true;
155  }
156 
157  return false;
158  }
raiseEvent(string $event, ilOrgUnitUserAssignment $assignment)
+ Here is the call graph for this function:

◆ deleteByUser()

ilOrgUnitUserAssignmentDBRepository::deleteByUser ( int  $user_id)

Delete all assignments for a user_id Returns false if no assignments were found.

Implements OrgUnitUserAssignmentRepository.

Definition at line 160 of file class.ilOrgUnitUserAssignmentDBRepository.php.

Referenced by ilOrgUnitUserAssignmentQueries\deleteAllAssignmentsOfUser().

160  : bool
161  {
162  if ($user_id <= 0) {
163  return false;
164  }
165 
166  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
167  . ' WHERE user_id = ' . $this->db->quote($user_id, 'integer');
168  $rows = $this->db->manipulate($query);
169 
170  if ($rows > 0) {
171  return true;
172  }
173 
174  return false;
175  }
+ Here is the caller graph for this function:

◆ find()

ilOrgUnitUserAssignmentDBRepository::find ( int  $user_id,
int  $position_id,
int  $orgu_id 
)

Find assignment for user, position and org-unit Does not create new assigment, returns null if no assignment exists.

Implements OrgUnitUserAssignmentRepository.

Definition at line 75 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getAssignmentOrFail().

76  {
77  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
78  . self::TABLE_NAME
79  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
80  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
81  . ' AND ' . self::TABLE_NAME . '.orgu_id = ' . $this->db->quote($orgu_id, 'integer');
82 
83  $res = $this->db->query($query);
84  if ($res->numRows() === 0) {
85  return null;
86  }
87 
88  $rec = $this->db->fetchAssoc($res);
89  return (new ilOrgUnitUserAssignment((int) $rec['id']))
90  ->withUserId((int) $rec['user_id'])
91  ->withPositionId((int) $rec['position_id'])
92  ->withOrguId((int) $rec['orgu_id']);
93  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ get()

ilOrgUnitUserAssignmentDBRepository::get ( int  $user_id,
int  $position_id,
int  $orgu_id 
)

Get existing user assignment or create a new one.

Implements OrgUnitUserAssignmentRepository.

Definition at line 50 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and store().

51  {
52  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
53  . self::TABLE_NAME
54  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
55  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
56  . ' AND ' . self::TABLE_NAME . '.orgu_id = ' . $this->db->quote($orgu_id, 'integer');
57 
58  $res = $this->db->query($query);
59  if ($res->numRows() > 0) {
60  $rec = $this->db->fetchAssoc($res);
61  return (new ilOrgUnitUserAssignment((int) $rec['id']))
62  ->withUserId((int) $rec['user_id'])
63  ->withPositionId((int) $rec['position_id'])
64  ->withOrguId((int) $rec['orgu_id']);
65  }
66 
67  $assignment = (new ilOrgUnitUserAssignment())
68  ->withUserId($user_id)
69  ->withPositionId($position_id)
70  ->withOrguId($orgu_id);
71  $assignment = $this->store($assignment);
72  return $assignment;
73  }
$res
Definition: ltiservices.php:69
store(ilOrgUnitUserAssignment $assignment)
Store assignment to db.
+ Here is the call graph for this function:

◆ getByOrgUnit()

ilOrgUnitUserAssignmentDBRepository::getByOrgUnit ( int  $orgu_id)

Get all assignments for an org-unit.

Returns
ilOrgUnitUserAssignment[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 209 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

209  : array
210  {
211  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
212  . self::TABLE_NAME
213  . ' WHERE ' . self::TABLE_NAME . '.orgu_id = ' . $this->db->quote($orgu_id, 'integer');
214  $res = $this->db->query($query);
215  $ret = [];
216  while ($rec = $this->db->fetchAssoc($res)) {
217  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
218  ->withUserId((int) $rec['user_id'])
219  ->withPositionId((int) $rec['position_id'])
220  ->withOrguId((int) $rec['orgu_id']);
221  }
222  return $ret;
223  }
$res
Definition: ltiservices.php:69

◆ getByPosition()

ilOrgUnitUserAssignmentDBRepository::getByPosition ( int  $position_id)

Get all assignments for a position.

Returns
ilOrgUnitUserAssignment[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 193 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getUserAssignmentsOfPosition().

193  : array
194  {
195  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
196  . self::TABLE_NAME
197  . ' WHERE ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
198  $res = $this->db->query($query);
199  $ret = [];
200  while ($rec = $this->db->fetchAssoc($res)) {
201  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
202  ->withUserId((int) $rec['user_id'])
203  ->withPositionId((int) $rec['position_id'])
204  ->withOrguId((int) $rec['orgu_id']);
205  }
206  return $ret;
207  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getByUserAndPosition()

ilOrgUnitUserAssignmentDBRepository::getByUserAndPosition ( int  $user_id,
int  $position_id 
)

Get assignments for a user in a dedicated position.

Returns
ilOrgUnitUserAssignment[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 226 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getAssignmentsOfUserIdAndPosition().

226  : array
227  {
228  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
229  . self::TABLE_NAME
230  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
231  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
232  $res = $this->db->query($query);
233  $ret = [];
234  while ($rec = $this->db->fetchAssoc($res)) {
235  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
236  ->withUserId((int) $rec['user_id'])
237  ->withPositionId((int) $rec['position_id'])
238  ->withOrguId((int) $rec['orgu_id']);
239  }
240  return $ret;
241  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getByUsers()

ilOrgUnitUserAssignmentDBRepository::getByUsers ( array  $user_ids)

Get assignments for one or more users.

Parameters
int[]$user_ids
Returns
ilOrgUnitUserAssignment[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 177 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getAssignmentsOfUserId(), and ilOrgUnitUserAssignmentQueries\getAssignmentsOfUserIds().

177  : array
178  {
179  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
180  . self::TABLE_NAME
181  . ' WHERE ' . $this->db->in('user_id', $user_ids, false, 'integer');
182  $res = $this->db->query($query);
183  $ret = [];
184  while ($rec = $this->db->fetchAssoc($res)) {
185  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
186  ->withUserId((int) $rec['user_id'])
187  ->withPositionId((int) $rec['position_id'])
188  ->withOrguId((int) $rec['orgu_id']);
189  }
190  return $ret;
191  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getFilteredUsersByUserAndPosition()

ilOrgUnitUserAssignmentDBRepository::getFilteredUsersByUserAndPosition ( int  $user_id,
int  $position_id,
int  $position_filter_id,
bool  $recursive = false 
)

Get all users with position $position_filter_id from those org-units, where the user has position $position_id i.e.

all employees of all org-units where the user is a superior

Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 298 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, getOrgUnitsByUserAndPosition(), and ILIAS\Repository\int().

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfUsersOrgUnitsInPosition().

298  : array
299  {
300  $orgu_ids = $this->getOrgUnitsByUserAndPosition($user_id, $position_id, $recursive);
301 
302  $query = 'SELECT user_id FROM' . PHP_EOL
303  . self::TABLE_NAME
304  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer') . PHP_EOL
305  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_filter_id, 'integer');
306  $res = $this->db->query($query);
307  $users = [];
308  while ($rec = $this->db->fetchAssoc($res)) {
309  $users[] = (int) $rec['user_id'];
310  }
311  return $users;
312  }
$res
Definition: ltiservices.php:69
getOrgUnitsByUserAndPosition(int $user_id, int $position_id, bool $recursive=false)
Get all org-units where a user has a dedicated position.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrgUnitsByUser()

ilOrgUnitUserAssignmentDBRepository::getOrgUnitsByUser ( int  $user_id)

Get all org-units a user is assigned to.

Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 314 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and ILIAS\Repository\int().

Referenced by ilOrgUnitUserAssignmentQueries\getOrgUnitIdsofUser().

314  : array
315  {
316  $query = 'SELECT orgu_id FROM' . PHP_EOL
317  . self::TABLE_NAME
318  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer');
319  $res = $this->db->query($query);
320  $orgu_ids = [];
321  while ($rec = $this->db->fetchAssoc($res)) {
322  $orgu_ids[] = (int) $rec['orgu_id'];
323  }
324  return $orgu_ids;
325  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrgUnitsByUserAndPosition()

ilOrgUnitUserAssignmentDBRepository::getOrgUnitsByUserAndPosition ( int  $user_id,
int  $position_id,
bool  $recursive = false 
)

Get all org-units where a user has a dedicated position.

Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 327 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, ilObjOrgUnitTree\_getInstance(), and ILIAS\Repository\int().

Referenced by getFilteredUsersByUserAndPosition(), ilOrgUnitUserAssignmentQueries\getOrgUnitIdsOfUsersPosition(), and getUsersByUserAndPosition().

327  : array
328  {
329  $query = 'SELECT orgu_id FROM' . PHP_EOL
330  . self::TABLE_NAME
331  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
332  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
333  $res = $this->db->query($query);
334  $orgu_ids = [];
335  while ($rec = $this->db->fetchAssoc($res)) {
336  $orgu_ids[] = (int) $rec['orgu_id'];
337  }
338 
339  if (!$recursive) {
340  return $orgu_ids;
341  }
342 
343  $recursive_orgu_ids = [];
345  foreach ($orgu_ids as $orgu_id) {
346  $recursive_orgu_ids = array_merge($recursive_orgu_ids, $tree->getAllChildren($orgu_id));
347  }
348  return $recursive_orgu_ids;
349  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPositionRepo()

ilOrgUnitUserAssignmentDBRepository::getPositionRepo ( )
protected

Definition at line 40 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $dic, $positionRepo, and ilOrgUnitLocalDIC\dic().

Referenced by getPositionsByUser().

41  {
42  if (!isset($this->positionRepo)) {
44  $this->positionRepo = $dic["repo.Positions"];
45  }
46 
47  return $this->positionRepo;
48  }
$dic
Definition: result.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPositionsByUser()

ilOrgUnitUserAssignmentDBRepository::getPositionsByUser ( int  $user_id)

Get all positions a user is assigned to.

Returns
ilOrgUnitPosition[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 351 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and getPositionRepo().

Referenced by ilOrgUnitUserAssignmentQueries\getPositionsOfUserId().

351  : array
352  {
353  $query = 'SELECT DISTINCT position_id FROM' . PHP_EOL
354  . self::TABLE_NAME
355  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer');
356  $res = $this->db->query($query);
357 
358  $positions = [];
359  while ($rec = $this->db->fetchAssoc($res)) {
360  $positions[] = $this->getPositionRepo()->getSingle((int) $rec['position_id'], 'id');
361  }
362  return $positions;
363  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSuperiorsByUsers()

ilOrgUnitUserAssignmentDBRepository::getSuperiorsByUsers ( array  $user_ids)

Get all superiors of one or more users $user_id => [ $superior_ids ].

Parameters
int[]$user_ids
Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 365 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, ilOrgUnitPosition\CORE_POSITION_EMPLOYEE, and ilOrgUnitPosition\CORE_POSITION_SUPERIOR.

365  : array
366  {
367  $query = 'SELECT ' . PHP_EOL
368  . ' ua.orgu_id AS orgu_id,' . PHP_EOL
369  . ' ua.user_id AS empl,' . PHP_EOL
370  . ' ua2.user_id as sup' . PHP_EOL
371  . ' FROM' . PHP_EOL
372  . self::TABLE_NAME . ' as ua,' . PHP_EOL
373  . self::TABLE_NAME . ' as ua2' . PHP_EOL
374  . ' WHERE ua.orgu_id = ua2.orgu_id' . PHP_EOL
375  . ' AND ua.user_id <> ua2.user_id' . PHP_EOL
376  . ' AND ua.position_id = ' . $this->db->quote(ilOrgUnitPosition::CORE_POSITION_EMPLOYEE, 'integer') . PHP_EOL
377  . ' AND ua2.position_id = ' . $this->db->quote(ilOrgUnitPosition::CORE_POSITION_SUPERIOR, 'integer') . PHP_EOL
378  . ' AND ' . $this->db->in('ua.user_id', $user_ids, false, 'integer');
379  $res = $this->db->query($query);
380  if ($res->numRows() === 0) {
381  return [];
382  }
383 
384  $ret = [];
385  while ($rec = $this->db->fetchAssoc($res)) {
386  $ret[$rec['empl']][] = $rec['sup'];
387  }
388  return $ret;
389  }
$res
Definition: ltiservices.php:69

◆ getUsersByOrgUnits()

ilOrgUnitUserAssignmentDBRepository::getUsersByOrgUnits ( array  $orgu_ids)

Get all users for a given set of org-units.

Parameters
int[]$orgu_ids
Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 243 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and ILIAS\Repository\int().

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfOrgUnit(), and ilOrgUnitUserAssignmentQueries\getUserIdsOfOrgUnits().

243  : array
244  {
245  $query = 'SELECT user_id FROM' . PHP_EOL
246  . self::TABLE_NAME
247  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer');
248  $res = $this->db->query($query);
249  $users = [];
250  while ($rec = $this->db->fetchAssoc($res)) {
251  $users[] = (int) $rec['user_id'];
252  }
253  return $users;
254  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsersByOrgUnitsAndPosition()

ilOrgUnitUserAssignmentDBRepository::getUsersByOrgUnitsAndPosition ( array  $orgu_ids,
int  $position_id 
)

Get all users in a specific position for a given set of org-units.

Parameters
int[]$orgu_ids
Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 269 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and ILIAS\Repository\int().

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfOrgUnitsInPosition().

269  : array
270  {
271  $query = 'SELECT user_id FROM' . PHP_EOL
272  . self::TABLE_NAME
273  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer') . PHP_EOL
274  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
275  $res = $this->db->query($query);
276  $users = [];
277  while ($rec = $this->db->fetchAssoc($res)) {
278  $users[] = (int) $rec['user_id'];
279  }
280  return $users;
281  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsersByPosition()

ilOrgUnitUserAssignmentDBRepository::getUsersByPosition ( int  $position_id)

Get all users with a certain position.

Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 256 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and ILIAS\Repository\int().

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfPosition().

256  : array
257  {
258  $query = 'SELECT user_id FROM' . PHP_EOL
259  . self::TABLE_NAME
260  . ' WHERE ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
261  $res = $this->db->query($query);
262  $users = [];
263  while ($rec = $this->db->fetchAssoc($res)) {
264  $users[] = (int) $rec['user_id'];
265  }
266  return $users;
267  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsersByUserAndPosition()

ilOrgUnitUserAssignmentDBRepository::getUsersByUserAndPosition ( int  $user_id,
int  $position_id,
bool  $recursive = false 
)

Get all users from org-units where the user has a certain position i.e.

all users from all org-units where the user is an employee

Returns
int[]

Implements OrgUnitUserAssignmentRepository.

Definition at line 283 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, getOrgUnitsByUserAndPosition(), and ILIAS\Repository\int().

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfOrgUnitsOfUsersPosition().

283  : array
284  {
285  $orgu_ids = $this->getOrgUnitsByUserAndPosition($user_id, $position_id, $recursive);
286 
287  $query = 'SELECT user_id FROM' . PHP_EOL
288  . self::TABLE_NAME
289  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer');
290  $res = $this->db->query($query);
291  $users = [];
292  while ($rec = $this->db->fetchAssoc($res)) {
293  $users[] = (int) $rec['user_id'];
294  }
295  return $users;
296  }
$res
Definition: ltiservices.php:69
getOrgUnitsByUserAndPosition(int $user_id, int $position_id, bool $recursive=false)
Get all org-units where a user has a dedicated position.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert()

ilOrgUnitUserAssignmentDBRepository::insert ( ilOrgUnitUserAssignment  $assignment)
protected

Definition at line 108 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $id, ilOrgUnitUserAssignment\getOrguId(), ilOrgUnitUserAssignment\getPositionId(), and ilOrgUnitUserAssignment\getUserId().

Referenced by store().

109  {
110  $id = $this->db->nextId(self::TABLE_NAME);
111 
112  $values = [
113  'id' => [ 'integer', $id ],
114  'user_id' => [ 'integer', $assignment->getUserId() ],
115  'position_id' => [ 'integer', $assignment->getPositionId() ],
116  'orgu_id' => [ 'integer', $assignment->getOrguId() ]
117  ];
118 
119  $this->db->insert(self::TABLE_NAME, $values);
120 
121  $ret = (new ilOrgUnitUserAssignment($id))
122  ->withUserId($assignment->getUserId())
123  ->withPositionId($assignment->getPositionId())
124  ->withOrguId($assignment->getOrguId());
125 
126  return $ret;
127  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raiseEvent()

ilOrgUnitUserAssignmentDBRepository::raiseEvent ( string  $event,
ilOrgUnitUserAssignment  $assignment 
)
protected

Definition at line 391 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References ilOrgUnitUserAssignment\getOrguId(), ilOrgUnitUserAssignment\getPositionId(), ilOrgUnitUserAssignment\getUserId(), and ilAppEventHandler\raise().

Referenced by delete(), and store().

391  : void
392  {
393  $this->ilAppEventHandler->raise('Modules/OrgUnit', $event, array(
394  'obj_id' => $assignment->getOrguId(),
395  'usr_id' => $assignment->getUserId(),
396  'position_id' => $assignment->getPositionId()
397  ));
398  }
Global event handler.
raise(string $a_component, string $a_event, array $a_parameter=[])
Raise an event.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store()

ilOrgUnitUserAssignmentDBRepository::store ( ilOrgUnitUserAssignment  $assignment)

Store assignment to db.

Implements OrgUnitUserAssignmentRepository.

Definition at line 95 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References ilOrgUnitUserAssignment\getId(), insert(), raiseEvent(), and update().

Referenced by get().

96  {
97  if ($assignment->getId() === 0) {
98  $assignment = $this->insert($assignment);
99  } else {
100  $this->update($assignment);
101  }
102 
103  $this->raiseEvent('assignUserToPosition', $assignment);
104 
105  return $assignment;
106  }
raiseEvent(string $event, ilOrgUnitUserAssignment $assignment)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilOrgUnitUserAssignmentDBRepository::update ( ilOrgUnitUserAssignment  $assignment)
protected

Definition at line 129 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References ilOrgUnitUserAssignment\getId(), ilOrgUnitUserAssignment\getOrguId(), ilOrgUnitUserAssignment\getPositionId(), and ilOrgUnitUserAssignment\getUserId().

Referenced by store().

129  : void
130  {
131  $where = [ 'id' => [ 'integer', $assignment->getId() ] ];
132 
133  $values = [
134  'user_id' => [ 'integer', $assignment->getUserId() ],
135  'position_id' => [ 'integer', $assignment->getPositionId(),
136  'orgu_id' => [ 'integer', $assignment->getOrguId() ]]
137  ];
138 
139  $this->db->update(self::TABLE_NAME, $values, $where);
140  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilOrgUnitUserAssignmentDBRepository::$db
protected

Definition at line 24 of file class.ilOrgUnitUserAssignmentDBRepository.php.

Referenced by __construct().

◆ $ilAppEventHandler

ilAppEventHandler ilOrgUnitUserAssignmentDBRepository::$ilAppEventHandler
protected

◆ $positionRepo

ilOrgUnitPositionDBRepository ilOrgUnitUserAssignmentDBRepository::$positionRepo
protected

Definition at line 26 of file class.ilOrgUnitUserAssignmentDBRepository.php.

Referenced by getPositionRepo().

◆ TABLE_NAME

const ilOrgUnitUserAssignmentDBRepository::TABLE_NAME = 'il_orgu_ua'

The documentation for this class was generated from the following file: