ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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...
 
 getTotalRowCount (?array $filter_data, ?array $additional_parameters)
 
 getRows (Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 

Data Fields

const TABLE_NAME = 'il_orgu_ua'
 

Protected Member Functions

 getPositionRepo ()
 
 insert (ilOrgUnitUserAssignment $assignment)
 
 update (ilOrgUnitUserAssignment $assignment)
 
 raiseEvent (string $event, ilOrgUnitUserAssignment $assignment)
 
 getUserDataByOrgUnitsAndPosition (array $orgu_ids, int $position_id, bool $count_only=false, Range $range=null, Order $order=null)
 

Protected Attributes

ilDBInterface $db
 
ilAppEventHandler $ilAppEventHandler
 
ilOrgUnitPositionDBRepository $positionRepo
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $db, $DIC, and $handler.

34  {
35  $this->db = $db;
36 
37  if ($handler) {
38  $this->ilAppEventHandler = $handler;
39  } else {
40  global $DIC;
41  $this->ilAppEventHandler = $DIC->event();
42  }
43  }
Global event handler.
global $DIC
Definition: shib_login.php:25
$handler
Definition: oai.php:14

Member Function Documentation

◆ delete()

ilOrgUnitUserAssignmentDBRepository::delete ( ilOrgUnitUserAssignment  $assignment)

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

Implements OrgUnitUserAssignmentRepository.

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

References raiseEvent().

147  : bool
148  {
149  if ($assignment->getId() === 0) {
150  return false;
151  }
152 
153  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
154  . ' WHERE id = ' . $this->db->quote($assignment->getId(), 'integer');
155  $rows = $this->db->manipulate($query);
156 
157  if ($rows > 0) {
158  $this->raiseEvent('deassignUserFromPosition', $assignment);
159  return true;
160  }
161 
162  return false;
163  }
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 165 of file class.ilOrgUnitUserAssignmentDBRepository.php.

Referenced by ilOrgUnitUserAssignmentQueries\deleteAllAssignmentsOfUser().

165  : bool
166  {
167  if ($user_id <= 0) {
168  return false;
169  }
170 
171  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
172  . ' WHERE user_id = ' . $this->db->quote($user_id, 'integer');
173  $rows = $this->db->manipulate($query);
174 
175  if ($rows > 0) {
176  return true;
177  }
178 
179  return false;
180  }
+ 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 80 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getAssignmentOrFail().

81  {
82  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
83  . self::TABLE_NAME
84  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
85  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
86  . ' AND ' . self::TABLE_NAME . '.orgu_id = ' . $this->db->quote($orgu_id, 'integer');
87 
88  $res = $this->db->query($query);
89  if ($res->numRows() === 0) {
90  return null;
91  }
92 
93  $rec = $this->db->fetchAssoc($res);
94  return (new ilOrgUnitUserAssignment((int) $rec['id']))
95  ->withUserId((int) $rec['user_id'])
96  ->withPositionId((int) $rec['position_id'])
97  ->withOrguId((int) $rec['orgu_id']);
98  }
$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 55 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and store().

56  {
57  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
58  . self::TABLE_NAME
59  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
60  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
61  . ' AND ' . self::TABLE_NAME . '.orgu_id = ' . $this->db->quote($orgu_id, 'integer');
62 
63  $res = $this->db->query($query);
64  if ($res->numRows() > 0) {
65  $rec = $this->db->fetchAssoc($res);
66  return (new ilOrgUnitUserAssignment((int) $rec['id']))
67  ->withUserId((int) $rec['user_id'])
68  ->withPositionId((int) $rec['position_id'])
69  ->withOrguId((int) $rec['orgu_id']);
70  }
71 
72  $assignment = (new ilOrgUnitUserAssignment())
73  ->withUserId($user_id)
74  ->withPositionId($position_id)
75  ->withOrguId($orgu_id);
76  $assignment = $this->store($assignment);
77  return $assignment;
78  }
$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 214 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

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

◆ getByPosition()

ilOrgUnitUserAssignmentDBRepository::getByPosition ( int  $position_id)

Get all assignments for a position.

Returns
ilOrgUnitUserAssignment[]

Implements OrgUnitUserAssignmentRepository.

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

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getUserAssignmentsOfPosition().

198  : array
199  {
200  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
201  . self::TABLE_NAME
202  . ' WHERE ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
203  $res = $this->db->query($query);
204  $ret = [];
205  while ($rec = $this->db->fetchAssoc($res)) {
206  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
207  ->withUserId((int) $rec['user_id'])
208  ->withPositionId((int) $rec['position_id'])
209  ->withOrguId((int) $rec['orgu_id']);
210  }
211  return $ret;
212  }
$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 231 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

Referenced by ilOrgUnitUserAssignmentQueries\getAssignmentsOfUserIdAndPosition().

231  : array
232  {
233  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
234  . self::TABLE_NAME
235  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
236  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
237  $res = $this->db->query($query);
238  $ret = [];
239  while ($rec = $this->db->fetchAssoc($res)) {
240  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
241  ->withUserId((int) $rec['user_id'])
242  ->withPositionId((int) $rec['position_id'])
243  ->withOrguId((int) $rec['orgu_id']);
244  }
245  return $ret;
246  }
$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 182 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res.

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

182  : array
183  {
184  $query = 'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
185  . self::TABLE_NAME
186  . ' WHERE ' . $this->db->in('user_id', $user_ids, false, 'integer');
187  $res = $this->db->query($query);
188  $ret = [];
189  while ($rec = $this->db->fetchAssoc($res)) {
190  $ret[] = (new ilOrgUnitUserAssignment((int) $rec['id']))
191  ->withUserId((int) $rec['user_id'])
192  ->withPositionId((int) $rec['position_id'])
193  ->withOrguId((int) $rec['orgu_id']);
194  }
195  return $ret;
196  }
$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 303 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfUsersOrgUnitsInPosition().

303  : array
304  {
305  $orgu_ids = $this->getOrgUnitsByUserAndPosition($user_id, $position_id, $recursive);
306 
307  $query = 'SELECT user_id FROM' . PHP_EOL
308  . self::TABLE_NAME
309  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer') . PHP_EOL
310  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_filter_id, 'integer');
311  $res = $this->db->query($query);
312  $users = [];
313  while ($rec = $this->db->fetchAssoc($res)) {
314  $users[] = (int) $rec['user_id'];
315  }
316  return $users;
317  }
$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 319 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by ilOrgUnitUserAssignmentQueries\getOrgUnitIdsofUser().

319  : array
320  {
321  $query = 'SELECT orgu_id FROM' . PHP_EOL
322  . self::TABLE_NAME
323  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer');
324  $res = $this->db->query($query);
325  $orgu_ids = [];
326  while ($rec = $this->db->fetchAssoc($res)) {
327  $orgu_ids[] = (int) $rec['orgu_id'];
328  }
329  return $orgu_ids;
330  }
$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 332 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

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

332  : array
333  {
334  $query = 'SELECT orgu_id FROM' . PHP_EOL
335  . self::TABLE_NAME
336  . ' WHERE ' . self::TABLE_NAME . '.user_id = ' . $this->db->quote($user_id, 'integer') . PHP_EOL
337  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
338  $res = $this->db->query($query);
339  $orgu_ids = [];
340  while ($rec = $this->db->fetchAssoc($res)) {
341  $orgu_ids[] = (int) $rec['orgu_id'];
342  }
343 
344  if (!$recursive) {
345  return $orgu_ids;
346  }
347 
348  $recursive_orgu_ids = [];
350  foreach ($orgu_ids as $orgu_id) {
351  $recursive_orgu_ids = array_merge($recursive_orgu_ids, $tree->getAllChildren($orgu_id));
352  }
353  return $recursive_orgu_ids;
354  }
$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 45 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by getPositionsByUser().

46  {
47  if (!isset($this->positionRepo)) {
49  $this->positionRepo = $dic["repo.Positions"];
50  }
51 
52  return $this->positionRepo;
53  }
$dic
Definition: ltiresult.php:33
+ 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 356 of file class.ilOrgUnitUserAssignmentDBRepository.php.

References $res, and getPositionRepo().

Referenced by ilOrgUnitUserAssignmentQueries\getPositionsOfUserId().

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

◆ getRows()

ilOrgUnitUserAssignmentDBRepository::getRows ( Table\DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
?array  $filter_data,
?array  $additional_parameters 
)

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

References ilObjUserTracking\_enabledLearningProgress(), ilObjUserTracking\_enabledUserRelatedData(), and getUserDataByOrgUnitsAndPosition().

457  : \Generator {
458  $orgu_ids = $additional_parameters['orgu_ids'];
459  $position_id = $additional_parameters['position_id'];
460  $lp_visible = $additional_parameters['lp_visible_ref_ids'];
461  $write_access = $additional_parameters['write_access'];
462 
463  foreach ($this->getUserDataByOrgUnitsAndPosition($orgu_ids, $position_id, false, $range, $order) as $record) {
464  $row_id = implode('_', [(string) $position_id, (string) $record['usr_id']]);
465  yield $row_builder->buildDataRow($row_id, $record)
466  ->withDisabledAction(
467  'show_learning_progress',
468  !(
469  in_array($record['orgu_id'], $lp_visible)
472  )
473  )
474  ->withDisabledAction(
475  'remove',
476  !$write_access
477  );
478 
479  }
480  }
getUserDataByOrgUnitsAndPosition(array $orgu_ids, int $position_id, bool $count_only=false, Range $range=null, Order $order=null)
+ Here is the call 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 370 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

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

◆ getTotalRowCount()

ilOrgUnitUserAssignmentDBRepository::getTotalRowCount ( ?array  $filter_data,
?array  $additional_parameters 
)

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

References getUserDataByOrgUnitsAndPosition().

444  : ?int {
445  $orgu_ids = $additional_parameters['orgu_ids'];
446  $position_id = $additional_parameters['position_id'];
447  return $this->getUserDataByOrgUnitsAndPosition($orgu_ids, $position_id, true);
448  }
getUserDataByOrgUnitsAndPosition(array $orgu_ids, int $position_id, bool $count_only=false, Range $range=null, Order $order=null)
+ Here is the call graph for this function:

◆ getUserDataByOrgUnitsAndPosition()

ilOrgUnitUserAssignmentDBRepository::getUserDataByOrgUnitsAndPosition ( array  $orgu_ids,
int  $position_id,
bool  $count_only = false,
Range  $range = null,
Order  $order = null 
)
protected

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

References ILIAS\UI\Implementation\Component\Table\$range, $res, and ILIAS\Data\Range\unpack().

Referenced by getRows(), and getTotalRowCount().

411  {
412  $sql_order_part = $order ? $order->join('ORDER BY', fn(...$o) => implode(' ', $o)) : '';
413  $sql_range_part = $range ? sprintf('LIMIT %2$s OFFSET %1$s', ...$range->unpack()) : '';
414 
415  $query = 'SELECT usr_id, login, firstname, lastname, active, orgu_id' . PHP_EOL
416  . ', GROUP_CONCAT (od.title SEPARATOR ", ") as orgu_title ' . PHP_EOL
417  . 'FROM ' . self::TABLE_NAME . PHP_EOL
418  . 'JOIN usr_data ud on ud.usr_id = user_id' . PHP_EOL
419  . 'JOIN object_reference oref on oref.ref_id = orgu_id' . PHP_EOL
420  . 'JOIN object_data od on od.obj_id = oref.obj_id' . PHP_EOL
421  . 'WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer') . PHP_EOL
422  . 'AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
423  . 'group by login' . PHP_EOL
424  . $sql_order_part . PHP_EOL
425  . $sql_range_part . PHP_EOL
426  ;
427  $res = $this->db->query($query);
428 
429  if ($count_only) {
430  return $this->db->numRows($res);
431  }
432 
433  $users = [];
434  while ($rec = $this->db->fetchAssoc($res)) {
435  $rec['active'] = (bool) $rec['active'];
436  $users[] = $rec;
437  }
438  return $users;
439  }
$res
Definition: ltiservices.php:69
join($init, callable $fn)
Definition: Order.php:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 248 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

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

248  : array
249  {
250  $query = 'SELECT user_id FROM' . PHP_EOL
251  . self::TABLE_NAME
252  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer');
253  $res = $this->db->query($query);
254  $users = [];
255  while ($rec = $this->db->fetchAssoc($res)) {
256  $users[] = (int) $rec['user_id'];
257  }
258  return $users;
259  }
$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 274 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfOrgUnitsInPosition().

274  : array
275  {
276  $query = 'SELECT user_id FROM' . PHP_EOL
277  . self::TABLE_NAME
278  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer') . PHP_EOL
279  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
280  $res = $this->db->query($query);
281  $users = [];
282  while ($rec = $this->db->fetchAssoc($res)) {
283  $users[] = (int) $rec['user_id'];
284  }
285  return $users;
286  }
$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 261 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfPosition().

261  : array
262  {
263  $query = 'SELECT user_id FROM' . PHP_EOL
264  . self::TABLE_NAME
265  . ' WHERE ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer');
266  $res = $this->db->query($query);
267  $users = [];
268  while ($rec = $this->db->fetchAssoc($res)) {
269  $users[] = (int) $rec['user_id'];
270  }
271  return $users;
272  }
$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 288 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by ilOrgUnitUserAssignmentQueries\getUserIdsOfOrgUnitsOfUsersPosition().

288  : array
289  {
290  $orgu_ids = $this->getOrgUnitsByUserAndPosition($user_id, $position_id, $recursive);
291 
292  $query = 'SELECT user_id FROM' . PHP_EOL
293  . self::TABLE_NAME
294  . ' WHERE ' . $this->db->in(self::TABLE_NAME . '.orgu_id', $orgu_ids, false, 'integer');
295  $res = $this->db->query($query);
296  $users = [];
297  while ($rec = $this->db->fetchAssoc($res)) {
298  $users[] = (int) $rec['user_id'];
299  }
300  return $users;
301  }
$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 113 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by store().

114  {
115  $id = $this->db->nextId(self::TABLE_NAME);
116 
117  $values = [
118  'id' => [ 'integer', $id ],
119  'user_id' => [ 'integer', $assignment->getUserId() ],
120  'position_id' => [ 'integer', $assignment->getPositionId() ],
121  'orgu_id' => [ 'integer', $assignment->getOrguId() ]
122  ];
123 
124  $this->db->insert(self::TABLE_NAME, $values);
125 
126  $ret = (new ilOrgUnitUserAssignment($id))
127  ->withUserId($assignment->getUserId())
128  ->withPositionId($assignment->getPositionId())
129  ->withOrguId($assignment->getOrguId());
130 
131  return $ret;
132  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ 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 396 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by delete(), and store().

396  : void
397  {
398  $this->ilAppEventHandler->raise('components/ILIAS/OrgUnit', $event, array(
399  'obj_id' => $assignment->getOrguId(),
400  'usr_id' => $assignment->getUserId(),
401  'position_id' => $assignment->getPositionId()
402  ));
403  }
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 100 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by get().

101  {
102  if ($assignment->getId() === 0) {
103  $assignment = $this->insert($assignment);
104  } else {
105  $this->update($assignment);
106  }
107 
108  $this->raiseEvent('assignUserToPosition', $assignment);
109 
110  return $assignment;
111  }
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 134 of file class.ilOrgUnitUserAssignmentDBRepository.php.

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

Referenced by store().

134  : void
135  {
136  $where = [ 'id' => [ 'integer', $assignment->getId() ] ];
137 
138  $values = [
139  'user_id' => [ 'integer', $assignment->getUserId() ],
140  'position_id' => [ 'integer', $assignment->getPositionId(),
141  'orgu_id' => [ 'integer', $assignment->getOrguId() ]]
142  ];
143 
144  $this->db->update(self::TABLE_NAME, $values, $where);
145  }
+ 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 29 of file class.ilOrgUnitUserAssignmentDBRepository.php.

Referenced by __construct().

◆ $ilAppEventHandler

ilAppEventHandler ilOrgUnitUserAssignmentDBRepository::$ilAppEventHandler
protected

◆ $positionRepo

ilOrgUnitPositionDBRepository ilOrgUnitUserAssignmentDBRepository::$positionRepo
protected

Definition at line 31 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: