20 declare(strict_types=1);
37 $this->
lng->loadLanguageModule(
'orgu');
46 public function get(
int|
string $value,
string $field): array
50 'core_identifier' =>
'integer',
53 if (!in_array($field, array_keys($fields))) {
54 throw new Exception(
"Invalid field: " . $field);
57 $query =
'SELECT id, title, description, core_position, core_identifier FROM' . PHP_EOL
59 .
' WHERE ' . self::TABLE_NAME .
'.' . $field .
' = ' . $this->db->quote($value, $fields[$field]);
60 $res = $this->db->query($query);
62 while ($rec = $this->db->fetchAssoc(
$res)) {
65 ->withDescription((
string) $rec[
'description'])
66 ->withCorePosition((
bool) $rec[
'core_position'])
67 ->withCoreIdentifier((
int) $rec[
'core_identifier'])
79 $pos = $this->
get($value, $field);
80 if (count($pos) === 0) {
84 return (array_shift($pos));
96 $sql_order_part = $order ? $order->join(
'ORDER BY', fn(...$o) => implode(
' ', $o)) :
'';
97 $sql_range_part =
$range ? sprintf(
'LIMIT %2$s OFFSET %1$s', ...
$range->
unpack()) :
'';
99 $query =
'SELECT id, title, description, core_position, core_identifier FROM' . PHP_EOL
100 . self::TABLE_NAME . PHP_EOL
101 . $sql_order_part . PHP_EOL
104 $res = $this->db->query($query);
106 while ($rec = $this->db->fetchAssoc(
$res)) {
109 ->withDescription((
string) $rec[
'description'])
110 ->withCorePosition((
bool) $rec[
'core_position'])
111 ->withCoreIdentifier((
int) $rec[
'core_identifier'])
120 $query =
'SELECT id FROM ' . self::TABLE_NAME;
121 $res = $this->db->query($query);
122 return $this->db->numRows(
$res);
130 public function getArray(?
string $key = null, ?
string $field = null): array
132 if (!in_array($key, [
'id', null])) {
133 throw new Exception(
"Invalid key: " . $field);
139 'description' =>
'string',
140 'core_identifier' =>
'int',
141 'core_position' =>
'int' 143 if (!in_array($field, array_keys($fields)) && $field !== null) {
144 throw new Exception(
"Invalid field: " . $field);
147 if ($field !== null && $this->db->tableColumnExists(self::TABLE_NAME, $field)) {
148 $query =
'SELECT id, ' . $field .
' FROM' . PHP_EOL
152 $res = $this->db->query($query);
154 while ($rec = $this->db->fetchAssoc(
$res)) {
155 $value = $rec[$field];
156 if ($fields[$field] ==
'int') {
157 $value = (
int) $value;
158 } elseif ($fields[$field] ==
'string') {
159 $value = (string) $value;
162 $ret[$rec[$key]] = $value;
168 $query =
'SELECT id, title, description, core_identifier, core_position FROM' . PHP_EOL
171 $res = $this->db->query($query);
173 while ($rec = $this->db->fetchAssoc(
$res)) {
193 $query =
'SELECT DISTINCT ' . self::TABLE_NAME .
'.id, ' . self::TABLE_NAME .
'.*' . PHP_EOL
194 .
'FROM ' . self::TABLE_NAME . PHP_EOL
195 .
'LEFT JOIN ' . self::TABLE_NAME_UA . PHP_EOL
196 .
'ON ' . self::TABLE_NAME .
'.id = ' . self::TABLE_NAME_UA .
'.position_id' . PHP_EOL
197 .
'AND ' . self::TABLE_NAME_UA .
'.orgu_id = ' . $this->db->quote($orgu_id,
'integer') . PHP_EOL
198 .
'WHERE ' . self::TABLE_NAME_UA .
'.user_id IS NOT NULL' . PHP_EOL
199 .
'OR ' . self::TABLE_NAME .
'.core_position = 1';
200 $res = $this->db->query($query);
202 while ($rec = $this->db->fetchAssoc(
$res)) {
205 ->withDescription((
string) $rec[
'description'])
206 ->withCorePosition((
bool) $rec[
'core_position'])
207 ->withCoreIdentifier((
int) $rec[
'core_identifier'])
224 if ($position->
getId() === 0) {
225 $position = $this->
insert($position);
232 $new_authorities = [];
233 foreach ($authorities as $authority) {
234 $auth = $this->authorityRepo->store($authority->withPositionId($position->
getId()));
235 $ids[] = $auth->getId();
236 $new_authorities[] = $auth;
240 if (count($ids) > 0) {
241 $this->authorityRepo->deleteLeftoverAuthorities($ids, $position->
getId());
243 if (count($ids) === 0) {
244 $authorities = $this->authorityRepo->get($position->
getId(),
'position_id');
245 foreach ($authorities as $authority) {
246 $this->authorityRepo->delete($authority->getId());
255 $id = $this->db->nextId(self::TABLE_NAME);
258 'id' => [
'integer',
$id],
259 'title' => [
'text', $position->
getTitle() ],
261 'core_position' => [
'integer', ($position->
isCorePosition()) ? 1 : 0 ],
265 $this->db->insert(self::TABLE_NAME, $values);
279 $where = [
'id' => [
'integer', $position->
getId() ] ];
282 'title' => [
'text', $position->
getTitle() ],
284 'core_position' => [
'integer', (($position->
isCorePosition()) ? 1 : 0) ],
288 $this->db->update(self::TABLE_NAME, $values, $where);
294 public function delete(
int $position_id):
void 296 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
297 .
' WHERE id = ' . $this->db->quote($position_id,
'integer');
299 $this->db->manipulate($query);
301 $authorities = $this->authorityRepo->get($position_id,
'position_id');
302 foreach ($authorities as $authority) {
303 $this->authorityRepo->delete($authority->getId());
306 $assignments = $this->assignmentRepo->getByPosition($position_id);
307 foreach ($assignments as $assignment) {
308 $this->assignmentRepo->delete($assignment);
318 return $this->authorityRepo->create();
320 $authority = $this->authorityRepo->get($id,
'id');
321 return array_shift($authority);
327 ?array $additional_parameters
334 array $visible_column_ids,
338 ?array $additional_parameters
341 $row_id = (string) $pos->getId();
343 'title' => $pos->getTitle(),
344 'description' => $pos->getDescription(),
346 'is_core_position' => $pos->isCorePosition(),
349 yield $row_builder->buildDataRow($row_id, $record)
350 ->withDisabledAction(
'delete', $record[
'is_core_position']);
364 foreach ($lang_keys as $key) {
365 $t[$key] = $this->
lng->txt($key);
368 $authority_description = [];
369 foreach ($authorities as $authority) {
370 switch ($authority->getOver()) {
372 $over_txt = $t[
"over_" . $authority->getOver()];
376 ->getSingle($authority->getOver(),
'id')
381 $authority_description[] = implode(
" ", [
385 $t[
"scope_" . $authority->getScope()]
389 return $authority_description;
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
__construct(protected ilDBInterface $db, protected ilOrgUnitAuthorityDBRepository $authorityRepo, protected ilOrgUnitUserAssignmentDBRepository $assignmentRepo, protected ilLanguage $lng)
getAuthority(?int $id)
Gets or creates an authority object, as the authority repo is encapsulated into this repo...
getSingle(int|string $value, string $field)
Get a single position from a filtered query (see get())
Both the subject and the direction need to be specified when expressing an order. ...
getRows(Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
withAuthorities(array $authorities)
getAllPositions(Range $range=null, Order $order=null)
Returns all position objects.
getAuthorityDescription(array $authorities)
getArray(?string $key=null, ?string $field=null)
Returns position data as an array, e.g.
getPositionsForOrgUnit(int $orgu_id)
Returns all core positions plus all positions with user assignments for a certain org unit (kept for ...
insert(ilOrgUnitPosition $position)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
update(ilOrgUnitPosition $position)
store(ilOrgUnitPosition $position)
Saves position and its authorities.
A simple class to express a naive range of whole positive numbers.
const SCOPE_SUBSEQUENT_ORGUS