19 declare(strict_types=1);
    42         if (!isset($this->positionRepo)) {
    44             $this->positionRepo = 
$dic[
"repo.Positions"];
    52         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
    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');
    58         $res = $this->db->query($query);
    59         if (
$res->numRows() > 0) {
    60             $rec = $this->db->fetchAssoc(
$res);
    62                 ->withUserId((
int) $rec[
'user_id'])
    63                 ->withPositionId((
int) $rec[
'position_id'])
    64                 ->withOrguId((
int) $rec[
'orgu_id']);
    68             ->withUserId($user_id)
    69             ->withPositionId($position_id)
    70             ->withOrguId($orgu_id);
    71         $assignment = $this->
store($assignment);
    77         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
    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');
    83         $res = $this->db->query($query);
    84         if (
$res->numRows() === 0) {
    88         $rec = $this->db->fetchAssoc(
$res);
    90             ->withUserId((
int) $rec[
'user_id'])
    91             ->withPositionId((
int) $rec[
'position_id'])
    92             ->withOrguId((
int) $rec[
'orgu_id']);
    97         if ($assignment->
getId() === 0) {
    98             $assignment = $this->
insert($assignment);
   100             $this->
update($assignment);
   103         $this->
raiseEvent(
'assignUserToPosition', $assignment);
   110         $id = $this->db->nextId(self::TABLE_NAME);
   113             'id' => [ 
'integer', 
$id ],
   114             'user_id' => [ 
'integer', $assignment->
getUserId() ],
   115             'position_id' => [ 
'integer', $assignment->
getPositionId() ],
   116             'orgu_id' => [ 
'integer', $assignment->
getOrguId() ]
   119         $this->db->insert(self::TABLE_NAME, $values);
   131         $where = [ 
'id' => [ 
'integer', $assignment->
getId() ] ];
   134             'user_id' => [ 
'integer', $assignment->
getUserId() ],
   136             'orgu_id' => [ 
'integer', $assignment->
getOrguId() ]]
   139         $this->db->update(self::TABLE_NAME, $values, $where);
   144         if ($assignment->getId() === 0) {
   148         $query = 
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
   149             . 
' WHERE id = ' . $this->db->quote($assignment->getId(), 
'integer');
   150         $rows = $this->db->manipulate($query);
   153             $this->
raiseEvent(
'deassignUserFromPosition', $assignment);
   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);
   179         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   181             . 
' WHERE ' . $this->db->in(
'user_id', $user_ids, 
false, 
'integer');
   182         $res = $this->db->query($query);
   184         while ($rec = $this->db->fetchAssoc(
$res)) {
   186                 ->withUserId((
int) $rec[
'user_id'])
   187                 ->withPositionId((
int) $rec[
'position_id'])
   188                 ->withOrguId((
int) $rec[
'orgu_id']);
   195         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   197             . 
' WHERE ' . self::TABLE_NAME . 
'.position_id = ' . $this->db->quote($position_id, 
'integer');
   198         $res = $this->db->query($query);
   200         while ($rec = $this->db->fetchAssoc(
$res)) {
   202                 ->withUserId((
int) $rec[
'user_id'])
   203                 ->withPositionId((
int) $rec[
'position_id'])
   204                 ->withOrguId((
int) $rec[
'orgu_id']);
   211         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   213             . 
' WHERE ' . self::TABLE_NAME . 
'.orgu_id = ' . $this->db->quote($orgu_id, 
'integer');
   214         $res = $this->db->query($query);
   216         while ($rec = $this->db->fetchAssoc(
$res)) {
   218                 ->withUserId((
int) $rec[
'user_id'])
   219                 ->withPositionId((
int) $rec[
'position_id'])
   220                 ->withOrguId((
int) $rec[
'orgu_id']);
   228         $query = 
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
   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);
   234         while ($rec = $this->db->fetchAssoc(
$res)) {
   236                 ->withUserId((
int) $rec[
'user_id'])
   237                 ->withPositionId((
int) $rec[
'position_id'])
   238                 ->withOrguId((
int) $rec[
'orgu_id']);
   245         $query = 
'SELECT user_id FROM' . PHP_EOL
   247             . 
' WHERE ' . $this->db->in(self::TABLE_NAME . 
'.orgu_id', $orgu_ids, 
false, 
'integer');
   248         $res = $this->db->query($query);
   250         while ($rec = $this->db->fetchAssoc(
$res)) {
   251             $users[] = (
int) $rec[
'user_id'];
   258         $query = 
'SELECT user_id FROM' . PHP_EOL
   260             . 
' WHERE ' . self::TABLE_NAME . 
'.position_id = ' . $this->db->quote($position_id, 
'integer');
   261         $res = $this->db->query($query);
   263         while ($rec = $this->db->fetchAssoc(
$res)) {
   264             $users[] = (
int) $rec[
'user_id'];
   271         $query = 
'SELECT user_id FROM' . PHP_EOL
   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);
   277         while ($rec = $this->db->fetchAssoc(
$res)) {
   278             $users[] = (
int) $rec[
'user_id'];
   287         $query = 
'SELECT user_id FROM' . PHP_EOL
   289             . 
' WHERE ' . $this->db->in(self::TABLE_NAME . 
'.orgu_id', $orgu_ids, 
false, 
'integer');
   290         $res = $this->db->query($query);
   292         while ($rec = $this->db->fetchAssoc(
$res)) {
   293             $users[] = (
int) $rec[
'user_id'];
   302         $query = 
'SELECT user_id FROM' . PHP_EOL
   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);
   308         while ($rec = $this->db->fetchAssoc(
$res)) {
   309             $users[] = (
int) $rec[
'user_id'];
   316         $query = 
'SELECT orgu_id FROM' . PHP_EOL
   318             . 
' WHERE ' . self::TABLE_NAME . 
'.user_id = ' . $this->db->quote($user_id, 
'integer');
   319         $res = $this->db->query($query);
   321         while ($rec = $this->db->fetchAssoc(
$res)) {
   322             $orgu_ids[] = (
int) $rec[
'orgu_id'];
   329         $query = 
'SELECT orgu_id FROM' . PHP_EOL
   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);
   335         while ($rec = $this->db->fetchAssoc(
$res)) {
   336             $orgu_ids[] = (
int) $rec[
'orgu_id'];
   343         $recursive_orgu_ids = [];
   345         foreach ($orgu_ids as $orgu_id) {
   346             $recursive_orgu_ids = array_merge($recursive_orgu_ids, $tree->getAllChildren($orgu_id));
   348         return $recursive_orgu_ids;
   353         $query = 
'SELECT DISTINCT position_id FROM' . PHP_EOL
   355             . 
' WHERE ' . self::TABLE_NAME . 
'.user_id = ' . $this->db->quote($user_id, 
'integer');
   356         $res = $this->db->query($query);
   359         while ($rec = $this->db->fetchAssoc(
$res)) {
   360             $positions[] = $this->
getPositionRepo()->getSingle((
int) $rec[
'position_id'], 
'id');
   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
   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
   378             . 
' AND ' . $this->db->in(
'ua.user_id', $user_ids, 
false, 
'integer');
   379         $res = $this->db->query($query);
   380         if (
$res->numRows() === 0) {
   385         while ($rec = $this->db->fetchAssoc(
$res)) {
   386             $ret[$rec[
'empl']][] = $rec[
'sup'];
 getUsersByPosition(int $position_id)
Get all users with a certain position. 
 
getPositionsByUser(int $user_id)
Get all positions a user is assigned to. 
 
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)
 
getUsersByOrgUnits(array $orgu_ids)
Get all users for a given set of org-units. 
 
ilAppEventHandler $ilAppEventHandler
 
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. 
 
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. 
 
__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. 
 
const CORE_POSITION_SUPERIOR
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
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. 
 
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.