19 declare(strict_types=1);
46 if (!isset($this->positionRepo)) {
48 $this->positionRepo =
$dic[
"repo.Positions"];
56 $query =
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
58 .
' WHERE ' . self::TABLE_NAME .
'.user_id = ' . $this->db->quote($user_id,
'integer') . PHP_EOL
59 .
' AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer') . PHP_EOL
60 .
' AND ' . self::TABLE_NAME .
'.orgu_id = ' . $this->db->quote($orgu_id,
'integer');
62 $res = $this->db->query($query);
63 if (
$res->numRows() > 0) {
64 $rec = $this->db->fetchAssoc(
$res);
66 ->withUserId((
int) $rec[
'user_id'])
67 ->withPositionId((
int) $rec[
'position_id'])
68 ->withOrguId((
int) $rec[
'orgu_id']);
72 ->withUserId($user_id)
73 ->withPositionId($position_id)
74 ->withOrguId($orgu_id);
75 $assignment = $this->
store($assignment);
81 $query =
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
83 .
' WHERE ' . self::TABLE_NAME .
'.user_id = ' . $this->db->quote($user_id,
'integer') . PHP_EOL
84 .
' AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer') . PHP_EOL
85 .
' AND ' . self::TABLE_NAME .
'.orgu_id = ' . $this->db->quote($orgu_id,
'integer');
87 $res = $this->db->query($query);
88 if (
$res->numRows() === 0) {
92 $rec = $this->db->fetchAssoc(
$res);
94 ->withUserId((
int) $rec[
'user_id'])
95 ->withPositionId((
int) $rec[
'position_id'])
96 ->withOrguId((
int) $rec[
'orgu_id']);
101 if ($assignment->
getId() === 0) {
102 $assignment = $this->
insert($assignment);
104 $this->
update($assignment);
107 $this->
raiseEvent(
'assignUserToPosition', $assignment);
114 $id = $this->db->nextId(self::TABLE_NAME);
117 'id' => [
'integer',
$id ],
118 'user_id' => [
'integer', $assignment->
getUserId() ],
119 'position_id' => [
'integer', $assignment->
getPositionId() ],
120 'orgu_id' => [
'integer', $assignment->
getOrguId() ]
123 $this->db->insert(self::TABLE_NAME, $values);
135 $where = [
'id' => [
'integer', $assignment->
getId() ] ];
138 'user_id' => [
'integer', $assignment->
getUserId() ],
140 'orgu_id' => [
'integer', $assignment->
getOrguId() ]]
143 $this->db->update(self::TABLE_NAME, $values, $where);
148 if ($assignment->getId() === 0) {
152 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
153 .
' WHERE id = ' . $this->db->quote($assignment->getId(),
'integer');
154 $rows = $this->db->manipulate($query);
157 $this->
raiseEvent(
'deassignUserFromPosition', $assignment);
170 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
171 .
' WHERE user_id = ' . $this->db->quote($user_id,
'integer');
172 $rows = $this->db->manipulate($query);
183 $query =
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
185 .
' WHERE ' . $this->db->in(
'user_id', $user_ids,
false,
'integer');
186 $res = $this->db->query($query);
188 while ($rec = $this->db->fetchAssoc(
$res)) {
190 ->withUserId((
int) $rec[
'user_id'])
191 ->withPositionId((
int) $rec[
'position_id'])
192 ->withOrguId((
int) $rec[
'orgu_id']);
199 $query =
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
201 .
' WHERE ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer');
202 $res = $this->db->query($query);
204 while ($rec = $this->db->fetchAssoc(
$res)) {
206 ->withUserId((
int) $rec[
'user_id'])
207 ->withPositionId((
int) $rec[
'position_id'])
208 ->withOrguId((
int) $rec[
'orgu_id']);
215 $query =
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
217 .
' WHERE ' . self::TABLE_NAME .
'.orgu_id = ' . $this->db->quote($orgu_id,
'integer');
218 $res = $this->db->query($query);
220 while ($rec = $this->db->fetchAssoc(
$res)) {
222 ->withUserId((
int) $rec[
'user_id'])
223 ->withPositionId((
int) $rec[
'position_id'])
224 ->withOrguId((
int) $rec[
'orgu_id']);
232 $query =
'SELECT id, user_id, position_id, orgu_id FROM' . PHP_EOL
234 .
' WHERE ' . self::TABLE_NAME .
'.user_id = ' . $this->db->quote($user_id,
'integer') . PHP_EOL
235 .
' AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer');
236 $res = $this->db->query($query);
238 while ($rec = $this->db->fetchAssoc(
$res)) {
240 ->withUserId((
int) $rec[
'user_id'])
241 ->withPositionId((
int) $rec[
'position_id'])
242 ->withOrguId((
int) $rec[
'orgu_id']);
249 $query =
'SELECT user_id FROM' . PHP_EOL
251 .
' WHERE ' . $this->db->in(self::TABLE_NAME .
'.orgu_id', $orgu_ids,
false,
'integer');
252 $res = $this->db->query($query);
254 while ($rec = $this->db->fetchAssoc(
$res)) {
255 $users[] = (
int) $rec[
'user_id'];
262 $query =
'SELECT user_id FROM' . PHP_EOL
264 .
' WHERE ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer');
265 $res = $this->db->query($query);
267 while ($rec = $this->db->fetchAssoc(
$res)) {
268 $users[] = (
int) $rec[
'user_id'];
275 $query =
'SELECT user_id FROM' . PHP_EOL
277 .
' WHERE ' . $this->db->in(self::TABLE_NAME .
'.orgu_id', $orgu_ids,
false,
'integer') . PHP_EOL
278 .
' AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer');
279 $res = $this->db->query($query);
281 while ($rec = $this->db->fetchAssoc(
$res)) {
282 $users[] = (
int) $rec[
'user_id'];
291 $query =
'SELECT user_id FROM' . PHP_EOL
293 .
' WHERE ' . $this->db->in(self::TABLE_NAME .
'.orgu_id', $orgu_ids,
false,
'integer');
294 $res = $this->db->query($query);
296 while ($rec = $this->db->fetchAssoc(
$res)) {
297 $users[] = (
int) $rec[
'user_id'];
306 $query =
'SELECT user_id FROM' . PHP_EOL
308 .
' WHERE ' . $this->db->in(self::TABLE_NAME .
'.orgu_id', $orgu_ids,
false,
'integer') . PHP_EOL
309 .
' AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_filter_id,
'integer');
310 $res = $this->db->query($query);
312 while ($rec = $this->db->fetchAssoc(
$res)) {
313 $users[] = (
int) $rec[
'user_id'];
320 $query =
'SELECT orgu_id FROM' . PHP_EOL
322 .
' WHERE ' . self::TABLE_NAME .
'.user_id = ' . $this->db->quote($user_id,
'integer');
323 $res = $this->db->query($query);
325 while ($rec = $this->db->fetchAssoc(
$res)) {
326 $orgu_ids[] = (
int) $rec[
'orgu_id'];
333 $query =
'SELECT orgu_id FROM' . PHP_EOL
335 .
' WHERE ' . self::TABLE_NAME .
'.user_id = ' . $this->db->quote($user_id,
'integer') . PHP_EOL
336 .
' AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer');
337 $res = $this->db->query($query);
339 while ($rec = $this->db->fetchAssoc(
$res)) {
340 $orgu_ids[] = (
int) $rec[
'orgu_id'];
347 $recursive_orgu_ids = [];
349 foreach ($orgu_ids as $orgu_id) {
350 $recursive_orgu_ids = array_merge($recursive_orgu_ids, $tree->getAllChildren($orgu_id));
352 return $recursive_orgu_ids;
357 $query =
'SELECT DISTINCT position_id FROM' . PHP_EOL
359 .
' WHERE ' . self::TABLE_NAME .
'.user_id = ' . $this->db->quote($user_id,
'integer');
360 $res = $this->db->query($query);
363 while ($rec = $this->db->fetchAssoc(
$res)) {
364 $positions[] = $this->
getPositionRepo()->getSingle((
int) $rec[
'position_id'],
'id');
371 $query =
'SELECT ' . PHP_EOL
372 .
' ua.orgu_id AS orgu_id,' . PHP_EOL
373 .
' ua.user_id AS empl,' . PHP_EOL
374 .
' ua2.user_id as sup' . PHP_EOL
376 . self::TABLE_NAME .
' as ua,' . PHP_EOL
377 . self::TABLE_NAME .
' as ua2' . PHP_EOL
378 .
' WHERE ua.orgu_id = ua2.orgu_id' . PHP_EOL
379 .
' AND ua.user_id <> ua2.user_id' . PHP_EOL
382 .
' AND ' . $this->db->in(
'ua.user_id', $user_ids,
false,
'integer');
383 $res = $this->db->query($query);
384 if (
$res->numRows() === 0) {
389 while ($rec = $this->db->fetchAssoc(
$res)) {
390 $ret[$rec[
'empl']][] = $rec[
'sup'];
407 bool $count_only =
false,
411 $sql_order_part = $order ? $order->join(
'ORDER BY', fn(...$o) => implode(
' ', $o)) :
'';
412 $sql_range_part =
$range ? sprintf(
'LIMIT %2$s OFFSET %1$s', ...
$range->
unpack()) :
'';
414 $query =
'SELECT usr_id, login, firstname, lastname, active, orgu_id' . PHP_EOL
415 .
', GROUP_CONCAT (od.title SEPARATOR ", ") as orgu_title ' . PHP_EOL
416 .
'FROM ' . self::TABLE_NAME . PHP_EOL
417 .
'JOIN usr_data ud on ud.usr_id = user_id' . PHP_EOL
418 .
'JOIN object_reference oref on oref.ref_id = orgu_id' . PHP_EOL
419 .
'JOIN object_data od on od.obj_id = oref.obj_id' . PHP_EOL
420 .
'WHERE ' . $this->db->in(self::TABLE_NAME .
'.orgu_id', $orgu_ids,
false,
'integer') . PHP_EOL
421 .
'AND ' . self::TABLE_NAME .
'.position_id = ' . $this->db->quote($position_id,
'integer') . PHP_EOL
422 .
'group by login' . PHP_EOL
423 . $sql_order_part . PHP_EOL
424 . $sql_range_part . PHP_EOL
426 $res = $this->db->query($query);
429 return $this->db->numRows(
$res);
433 while ($rec = $this->db->fetchAssoc(
$res)) {
434 $rec[
'active'] = (bool) $rec[
'active'];
442 ?array $additional_parameters
444 $orgu_ids = $additional_parameters[
'orgu_ids'];
445 $position_id = $additional_parameters[
'position_id'];
451 array $visible_column_ids,
455 ?array $additional_parameters
457 $orgu_ids = $additional_parameters[
'orgu_ids'];
458 $position_id = $additional_parameters[
'position_id'];
459 $lp_visible = $additional_parameters[
'lp_visible_ref_ids'];
460 $write_access = $additional_parameters[
'write_access'];
463 $row_id = implode(
'_', [(
string) $position_id, (
string) $record[
'usr_id']]);
464 yield $row_builder->buildDataRow($row_id, $record)
465 ->withDisabledAction(
466 'show_learning_progress',
468 in_array($record[
'orgu_id'], $lp_visible)
473 ->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)
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. ...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(ilDBInterface $db, ?ilAppEventHandler $handler=null)
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()
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.
getUserDataByOrgUnitsAndPosition(array $orgu_ids, int $position_id, bool $count_only=false, ?Range $range=null, ?Order $order=null)
$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.