19 declare(strict_types=1);
36 $this->
lng->loadLanguageModule(
'orgu');
45 public function get(
int|
string $value,
string $field): array
49 'core_identifier' =>
'integer',
52 if (!in_array($field, array_keys($fields))) {
53 throw new Exception(
"Invalid field: " . $field);
56 $query =
'SELECT id, title, description, core_position, core_identifier FROM' . PHP_EOL
58 .
' WHERE ' . self::TABLE_NAME .
'.' . $field .
' = ' . $this->db->quote($value, $fields[$field]);
59 $res = $this->db->query($query);
61 while ($rec = $this->db->fetchAssoc(
$res)) {
64 ->withDescription((
string) $rec[
'description'])
65 ->withCorePosition((
bool) $rec[
'core_position'])
66 ->withCoreIdentifier((
int) $rec[
'core_identifier'])
78 $pos = $this->
get($value, $field);
79 if (count($pos) === 0) {
83 return (array_shift($pos));
95 $sql_order_part = $order ? $order->join(
'ORDER BY', fn(...$o) => implode(
' ', $o)) :
'';
96 $sql_range_part =
$range ? sprintf(
'LIMIT %2$s OFFSET %1$s', ...
$range->
unpack()) :
'';
98 $query =
'SELECT id, title, description, core_position, core_identifier FROM' . PHP_EOL
99 . self::TABLE_NAME . PHP_EOL
100 . $sql_order_part . PHP_EOL
103 $res = $this->db->query($query);
105 while ($rec = $this->db->fetchAssoc(
$res)) {
108 ->withDescription((
string) $rec[
'description'])
109 ->withCorePosition((
bool) $rec[
'core_position'])
110 ->withCoreIdentifier((
int) $rec[
'core_identifier'])
119 $query =
'SELECT id FROM ' . self::TABLE_NAME;
120 $res = $this->db->query($query);
121 return $this->db->numRows(
$res);
131 if (!in_array($key, [
'id',
null])) {
132 throw new Exception(
"Invalid key: " . $field);
138 'description' =>
'string',
139 'core_identifier' =>
'int',
140 'core_position' =>
'int' 142 if (!in_array($field, array_keys($fields)) && $field !==
null) {
143 throw new Exception(
"Invalid field: " . $field);
146 if ($field !==
null && $this->db->tableColumnExists(self::TABLE_NAME, $field)) {
147 $query =
'SELECT id, ' . $field .
' FROM' . PHP_EOL
151 $res = $this->db->query($query);
153 while ($rec = $this->db->fetchAssoc(
$res)) {
154 $value = $rec[$field];
155 if ($fields[$field] ==
'int') {
156 $value = (
int) $value;
157 } elseif ($fields[$field] ==
'string') {
158 $value = (string) $value;
161 $ret[$rec[$key]] = $value;
167 $query =
'SELECT id, title, description, core_identifier, core_position FROM' . PHP_EOL
170 $res = $this->db->query($query);
172 while ($rec = $this->db->fetchAssoc(
$res)) {
192 $query =
'SELECT DISTINCT ' . self::TABLE_NAME .
'.id, ' . self::TABLE_NAME .
'.*' . PHP_EOL
193 .
'FROM ' . self::TABLE_NAME . PHP_EOL
194 .
'LEFT JOIN ' . self::TABLE_NAME_UA . PHP_EOL
195 .
'ON ' . self::TABLE_NAME .
'.id = ' . self::TABLE_NAME_UA .
'.position_id' . PHP_EOL
196 .
'AND ' . self::TABLE_NAME_UA .
'.orgu_id = ' . $this->db->quote($orgu_id,
'integer') . PHP_EOL
197 .
'WHERE ' . self::TABLE_NAME_UA .
'.user_id IS NOT NULL' . PHP_EOL
198 .
'OR ' . self::TABLE_NAME .
'.core_position = 1';
199 $res = $this->db->query($query);
201 while ($rec = $this->db->fetchAssoc(
$res)) {
204 ->withDescription((
string) $rec[
'description'])
205 ->withCorePosition((
bool) $rec[
'core_position'])
206 ->withCoreIdentifier((
int) $rec[
'core_identifier'])
223 if ($position->
getId() === 0) {
224 $position = $this->
insert($position);
231 $new_authorities = [];
232 foreach ($authorities as $authority) {
233 $auth = $this->authorityRepo->store($authority->withPositionId($position->
getId()));
234 $ids[] = $auth->getId();
235 $new_authorities[] = $auth;
239 if (count($ids) > 0) {
240 $this->authorityRepo->deleteLeftoverAuthorities($ids, $position->
getId());
242 if (count($ids) === 0) {
243 $authorities = $this->authorityRepo->get($position->
getId(),
'position_id');
244 foreach ($authorities as $authority) {
245 $this->authorityRepo->delete($authority->getId());
254 $id = $this->db->nextId(self::TABLE_NAME);
257 'id' => [
'integer',
$id],
258 'title' => [
'text', $position->
getTitle() ],
260 'core_position' => [
'integer', ($position->
isCorePosition()) ? 1 : 0 ],
264 $this->db->insert(self::TABLE_NAME, $values);
278 $where = [
'id' => [
'integer', $position->
getId() ] ];
281 'title' => [
'text', $position->
getTitle() ],
283 'core_position' => [
'integer', (($position->
isCorePosition()) ? 1 : 0) ],
287 $this->db->update(self::TABLE_NAME, $values, $where);
293 public function delete(
int $position_id):
void 295 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
296 .
' WHERE id = ' . $this->db->quote($position_id,
'integer');
298 $this->db->manipulate($query);
300 $authorities = $this->authorityRepo->get($position_id,
'position_id');
301 foreach ($authorities as $authority) {
302 $this->authorityRepo->delete($authority->getId());
305 $assignments = $this->assignmentRepo->getByPosition($position_id);
306 foreach ($assignments as $assignment) {
307 $this->assignmentRepo->delete($assignment);
317 return $this->authorityRepo->create();
319 $authority = $this->authorityRepo->get($id,
'id');
320 return array_shift($authority);
326 ?array $additional_parameters
333 array $visible_column_ids,
337 ?array $additional_parameters
340 $row_id = (string) $pos->getId();
342 'title' => $pos->getTitle(),
343 'description' => $pos->getDescription(),
345 'is_core_position' => $pos->isCorePosition(),
348 yield $row_builder->buildDataRow($row_id, $record)
349 ->withDisabledAction(
'delete', $record[
'is_core_position']);
363 foreach ($lang_keys as $key) {
364 $t[$key] = $this->
lng->txt($key);
367 $authority_description = [];
368 foreach ($authorities as $authority) {
369 switch ($authority->getOver()) {
371 $over_txt = $t[
"over_" . $authority->getOver()];
375 ->getSingle($authority->getOver(),
'id')
380 $authority_description[] = implode(
" ", [
384 $t[
"scope_" . $authority->getScope()]
388 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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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