20 declare(strict_types=1);
    47         if (!isset($this->positionRepo)) {
    49             $this->positionRepo = 
$dic[
"repo.Positions"];
    57         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
    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');
    63         $res = $this->db->query($query);
    64         if (
$res->numRows() > 0) {
    65             $rec = $this->db->fetchAssoc(
$res);
    67                 ->withUserId((
int) $rec[
'user_id'])
    68                 ->withPositionId((
int) $rec[
'position_id'])
    69                 ->withOrguId((
int) $rec[
'orgu_id']);
    73             ->withUserId($user_id)
    74             ->withPositionId($position_id)
    75             ->withOrguId($orgu_id);
    76         $assignment = $this->
store($assignment);
    82         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
    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');
    88         $res = $this->db->query($query);
    89         if (
$res->numRows() === 0) {
    93         $rec = $this->db->fetchAssoc(
$res);
    95             ->withUserId((
int) $rec[
'user_id'])
    96             ->withPositionId((
int) $rec[
'position_id'])
    97             ->withOrguId((
int) $rec[
'orgu_id']);
   102         if ($assignment->
getId() === 0) {
   103             $assignment = $this->
insert($assignment);
   105             $this->
update($assignment);
   108         $this->
raiseEvent(
'assignUserToPosition', $assignment);
   115         $id = $this->db->nextId(self::TABLE_NAME);
   118             'id' => [ 
'integer', 
$id ],
   119             'user_id' => [ 
'integer', $assignment->
getUserId() ],
   120             'position_id' => [ 
'integer', $assignment->
getPositionId() ],
   121             'orgu_id' => [ 
'integer', $assignment->
getOrguId() ]
   124         $this->db->insert(self::TABLE_NAME, $values);
   136         $where = [ 
'id' => [ 
'integer', $assignment->
getId() ] ];
   139             'user_id' => [ 
'integer', $assignment->
getUserId() ],
   141             'orgu_id' => [ 
'integer', $assignment->
getOrguId() ]]
   144         $this->db->update(self::TABLE_NAME, $values, $where);
   149         if ($assignment->getId() === 0) {
   153         $query = 
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
   154             . 
' WHERE id = ' . $this->db->quote($assignment->getId(), 
'integer');
   155         $rows = $this->db->manipulate($query);
   158             $this->
raiseEvent(
'deassignUserFromPosition', $assignment);
   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);
   184         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   186             . 
' WHERE ' . $this->db->in(
'user_id', $user_ids, 
false, 
'integer');
   187         $res = $this->db->query($query);
   189         while ($rec = $this->db->fetchAssoc(
$res)) {
   191                 ->withUserId((
int) $rec[
'user_id'])
   192                 ->withPositionId((
int) $rec[
'position_id'])
   193                 ->withOrguId((
int) $rec[
'orgu_id']);
   200         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   202             . 
' WHERE ' . self::TABLE_NAME . 
'.position_id = ' . $this->db->quote($position_id, 
'integer');
   203         $res = $this->db->query($query);
   205         while ($rec = $this->db->fetchAssoc(
$res)) {
   207                 ->withUserId((
int) $rec[
'user_id'])
   208                 ->withPositionId((
int) $rec[
'position_id'])
   209                 ->withOrguId((
int) $rec[
'orgu_id']);
   216         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   218             . 
' WHERE ' . self::TABLE_NAME . 
'.orgu_id = ' . $this->db->quote($orgu_id, 
'integer');
   219         $res = $this->db->query($query);
   221         while ($rec = $this->db->fetchAssoc(
$res)) {
   223                 ->withUserId((
int) $rec[
'user_id'])
   224                 ->withPositionId((
int) $rec[
'position_id'])
   225                 ->withOrguId((
int) $rec[
'orgu_id']);
   233         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   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);
   239         while ($rec = $this->db->fetchAssoc(
$res)) {
   241                 ->withUserId((
int) $rec[
'user_id'])
   242                 ->withPositionId((
int) $rec[
'position_id'])
   243                 ->withOrguId((
int) $rec[
'orgu_id']);
   250         $query = 
'SELECT user_id FROM' . PHP_EOL
   252             . 
' WHERE ' . $this->db->in(self::TABLE_NAME . 
'.orgu_id', $orgu_ids, 
false, 
'integer');
   253         $res = $this->db->query($query);
   255         while ($rec = $this->db->fetchAssoc(
$res)) {
   256             $users[] = (
int) $rec[
'user_id'];
   263         $query = 
'SELECT user_id FROM' . PHP_EOL
   265             . 
' WHERE ' . self::TABLE_NAME . 
'.position_id = ' . $this->db->quote($position_id, 
'integer');
   266         $res = $this->db->query($query);
   268         while ($rec = $this->db->fetchAssoc(
$res)) {
   269             $users[] = (
int) $rec[
'user_id'];
   276         $query = 
'SELECT user_id FROM' . PHP_EOL
   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);
   282         while ($rec = $this->db->fetchAssoc(
$res)) {
   283             $users[] = (
int) $rec[
'user_id'];
   292         $query = 
'SELECT user_id FROM' . PHP_EOL
   294             . 
' WHERE ' . $this->db->in(self::TABLE_NAME . 
'.orgu_id', $orgu_ids, 
false, 
'integer');
   295         $res = $this->db->query($query);
   297         while ($rec = $this->db->fetchAssoc(
$res)) {
   298             $users[] = (
int) $rec[
'user_id'];
   307         $query = 
'SELECT user_id FROM' . PHP_EOL
   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);
   313         while ($rec = $this->db->fetchAssoc(
$res)) {
   314             $users[] = (
int) $rec[
'user_id'];
   321         $query = 
'SELECT orgu_id FROM' . PHP_EOL
   323             . 
' WHERE ' . self::TABLE_NAME . 
'.user_id = ' . $this->db->quote($user_id, 
'integer');
   324         $res = $this->db->query($query);
   326         while ($rec = $this->db->fetchAssoc(
$res)) {
   327             $orgu_ids[] = (
int) $rec[
'orgu_id'];
   334         $query = 
'SELECT orgu_id FROM' . PHP_EOL
   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);
   340         while ($rec = $this->db->fetchAssoc(
$res)) {
   341             $orgu_ids[] = (
int) $rec[
'orgu_id'];
   348         $recursive_orgu_ids = [];
   350         foreach ($orgu_ids as $orgu_id) {
   351             $recursive_orgu_ids = array_merge($recursive_orgu_ids, $tree->getAllChildren($orgu_id));
   353         return $recursive_orgu_ids;
   358         $query = 
'SELECT DISTINCT position_id FROM' . PHP_EOL
   360             . 
' WHERE ' . self::TABLE_NAME . 
'.user_id = ' . $this->db->quote($user_id, 
'integer');
   361         $res = $this->db->query($query);
   364         while ($rec = $this->db->fetchAssoc(
$res)) {
   365             $positions[] = $this->
getPositionRepo()->getSingle((
int) $rec[
'position_id'], 
'id');
   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
   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
   383             . 
' AND ' . $this->db->in(
'ua.user_id', $user_ids, 
false, 
'integer');
   384         $res = $this->db->query($query);
   385         if (
$res->numRows() === 0) {
   390         while ($rec = $this->db->fetchAssoc(
$res)) {
   391             $ret[$rec[
'empl']][] = $rec[
'sup'];
   408         bool $count_only = 
false,
   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()) : 
'';
   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
   427         $res = $this->db->query($query);
   430             return $this->db->numRows(
$res);
   434         while ($rec = $this->db->fetchAssoc(
$res)) {
   435             $rec[
'active'] = (bool) $rec[
'active'];
   443         ?array $additional_parameters
   445         $orgu_ids = $additional_parameters[
'orgu_ids'];
   446         $position_id = $additional_parameters[
'position_id'];
   452         array $visible_column_ids,
   456         ?array $additional_parameters
   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'];
   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',
   469                         in_array($record[
'orgu_id'], $lp_visible)
   474                 ->withDisabledAction(
 getUsersByPosition(int $position_id)
Get all users with a certain position. 
 
getPositionsByUser(int $user_id)
Get all positions a user is assigned to. 
 
getRows(Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 
const CORE_POSITION_EMPLOYEE
 
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 $po...
 
insert(ilOrgUnitUserAssignment $assignment)
 
getUserDataByOrgUnitsAndPosition(array $orgu_ids, int $position_id, bool $count_only=false, Range $range=null, Order $order=null)
 
getUsersByOrgUnits(array $orgu_ids)
Get all users for a given set of org-units. 
 
ilAppEventHandler $ilAppEventHandler
 
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
 
getByUserAndPosition(int $user_id, int $position_id)
Get assignments for a user in a dedicated position. 
 
getOrgUnitsByUser(int $user_id)
Get all org-units a user is assigned to. 
 
Both the subject and the direction need to be specified when expressing an order. ...
 
deleteByUser(int $user_id)
Delete all assignments for a user_id Returns false if no assignments were found. 
 
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. 
 
getByOrgUnit(int $orgu_id)
Get all assignments for an org-unit. 
 
static _enabledUserRelatedData()
 
static _enabledLearningProgress()
 
__construct(ilDBInterface $db, ilAppEventHandler $handler=null)
 
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 ass...
 
ilOrgUnitPositionDBRepository $positionRepo
 
getSuperiorsByUsers(array $user_ids)
Get all superiors of one or more users $user_id => [ $superior_ids ]. 
 
store(ilOrgUnitUserAssignment $assignment)
Store assignment to db. 
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
const CORE_POSITION_SUPERIOR
 
update(ilOrgUnitUserAssignment $assignment)
 
getByPosition(int $position_id)
Get all assignments for a position. 
 
getOrgUnitsByUserAndPosition(int $user_id, int $position_id, bool $recursive=false)
Get all org-units where a user has a dedicated position. 
 
A simple class to express a naive range of whole positive numbers. 
 
raiseEvent(string $event, ilOrgUnitUserAssignment $assignment)
 
getUsersByOrgUnitsAndPosition(array $orgu_ids, int $position_id)
Get all users in a specific position for a given set of org-units. 
 
raise(string $a_component, string $a_event, array $a_parameter=[])
Raise an event. 
 
getByUsers(array $user_ids)
Get assignments for one or more users.