ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilOrgUnitPositionDBRepository Class Reference
+ Inheritance diagram for ilOrgUnitPositionDBRepository:
+ Collaboration diagram for ilOrgUnitPositionDBRepository:

Public Member Functions

 __construct (protected ilDBInterface $db, protected ilOrgUnitAuthorityDBRepository $authorityRepo, protected ilOrgUnitUserAssignmentDBRepository $assignmentRepo, protected ilLanguage $lng)
 
 get (int|string $value, string $field)
 Get one or more positions filtered by field/value. More...
 
 getSingle (int|string $value, string $field)
 Get a single position from a filtered query (see get()) More...
 
 getAllPositions (Range $range=null, Order $order=null)
 Returns all position objects. More...
 
 getArray (?string $key=null, ?string $field=null)
 Returns position data as an array, e.g. More...
 
 getPositionsForOrgUnit (int $orgu_id)
 Returns all core positions plus all positions with user assignments for a certain org unit (kept for compatibility, filtering by ua will be moved to orgu later) More...
 
 create ()
 
 store (ilOrgUnitPosition $position)
 Saves position and its authorities. More...
 
 delete (int $position_id)
 Deletes position and authorities/user assignments attached to it. More...
 
 getAuthority (?int $id)
 Gets or creates an authority object, as the authority repo is encapsulated into this repo. More...
 
 getTotalRowCount (?array $filter_data, ?array $additional_parameters)
 
 getRows (Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 
- Public Member Functions inherited from OrgUnitPositionRepository
 getAllPositions ()
 

Data Fields

const TABLE_NAME = 'il_orgu_positions'
 

Protected Member Functions

 getAllPositionsCount ()
 

Private Member Functions

 insert (ilOrgUnitPosition $position)
 
 update (ilOrgUnitPosition $position)
 
 getAuthorityDescription (array $authorities)
 

Private Attributes

const TABLE_NAME_UA = 'il_orgu_ua'
 

Detailed Description

Definition at line 26 of file class.ilOrgUnitPositionDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitPositionDBRepository::__construct ( protected ilDBInterface  $db,
protected ilOrgUnitAuthorityDBRepository  $authorityRepo,
protected ilOrgUnitUserAssignmentDBRepository  $assignmentRepo,
protected ilLanguage  $lng 
)

Definition at line 31 of file class.ilOrgUnitPositionDBRepository.php.

References ILIAS\Repository\lng().

36  {
37  $this->lng->loadLanguageModule('orgu');
38  }
+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilOrgUnitPositionDBRepository::create ( )

Implements OrgUnitPositionRepository.

Definition at line 214 of file class.ilOrgUnitPositionDBRepository.php.

215  {
216  return new ilOrgUnitPosition();
217  }

◆ delete()

ilOrgUnitPositionDBRepository::delete ( int  $position_id)

Deletes position and authorities/user assignments attached to it.

Implements OrgUnitPositionRepository.

Definition at line 294 of file class.ilOrgUnitPositionDBRepository.php.

294  : void
295  {
296  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
297  . ' WHERE id = ' . $this->db->quote($position_id, 'integer');
298 
299  $this->db->manipulate($query);
300 
301  $authorities = $this->authorityRepo->get($position_id, 'position_id');
302  foreach ($authorities as $authority) {
303  $this->authorityRepo->delete($authority->getId());
304  }
305 
306  $assignments = $this->assignmentRepo->getByPosition($position_id);
307  foreach ($assignments as $assignment) {
308  $this->assignmentRepo->delete($assignment);
309  }
310  }

◆ get()

ilOrgUnitPositionDBRepository::get ( int|string  $value,
string  $field 
)

Get one or more positions filtered by field/value.

Returns
ilOrgUnitPosition[]
Exceptions
Exception

Implements OrgUnitPositionRepository.

Definition at line 46 of file class.ilOrgUnitPositionDBRepository.php.

References $res, ilOrgUnitAuthority\POSITION_ID, and ILIAS\GlobalScreen\Scope\Footer\Factory\withTitle().

46  : array
47  {
48  $fields = [
49  'id' => 'integer',
50  'core_identifier' => 'integer',
51  'title' => 'string'
52  ];
53  if (!in_array($field, array_keys($fields))) {
54  throw new Exception("Invalid field: " . $field);
55  }
56 
57  $query = 'SELECT id, title, description, core_position, core_identifier FROM' . PHP_EOL
58  . self::TABLE_NAME
59  . ' WHERE ' . self::TABLE_NAME . '.' . $field . ' = ' . $this->db->quote($value, $fields[$field]);
60  $res = $this->db->query($query);
61  $ret = [];
62  while ($rec = $this->db->fetchAssoc($res)) {
63  $ret[] = (new ilOrgUnitPosition((int) $rec['id']))
64  ->withTitle((string) $rec['title'])
65  ->withDescription((string) $rec['description'])
66  ->withCorePosition((bool) $rec['core_position'])
67  ->withCoreIdentifier((int) $rec['core_identifier'])
68  ->withAuthorities($this->authorityRepo->get((int) $rec['id'], ilOrgUnitAuthority::POSITION_ID));
69  }
70 
71  return $ret;
72  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getAllPositions()

ilOrgUnitPositionDBRepository::getAllPositions ( Range  $range = null,
Order  $order = null 
)

Returns all position objects.

Returns
ilOrgUnitPosition[]

Definition at line 92 of file class.ilOrgUnitPositionDBRepository.php.

References ILIAS\UI\Implementation\Component\Table\$range, $res, ilOrgUnitAuthority\POSITION_ID, ILIAS\Data\Range\unpack(), and ILIAS\GlobalScreen\Scope\Footer\Factory\withTitle().

95  : array {
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()) : '';
98 
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
102  . $sql_range_part;
103 
104  $res = $this->db->query($query);
105  $ret = [];
106  while ($rec = $this->db->fetchAssoc($res)) {
107  $ret[] = (new ilOrgUnitPosition((int) $rec['id']))
108  ->withTitle((string) $rec['title'])
109  ->withDescription((string) $rec['description'])
110  ->withCorePosition((bool) $rec['core_position'])
111  ->withCoreIdentifier((int) $rec['core_identifier'])
112  ->withAuthorities($this->authorityRepo->get((int) $rec['id'], ilOrgUnitAuthority::POSITION_ID));
113  }
114 
115  return $ret;
116  }
$res
Definition: ltiservices.php:69
join($init, callable $fn)
Definition: Order.php:59
+ Here is the call graph for this function:

◆ getAllPositionsCount()

ilOrgUnitPositionDBRepository::getAllPositionsCount ( )
protected

Definition at line 118 of file class.ilOrgUnitPositionDBRepository.php.

References $res.

Referenced by getTotalRowCount().

118  : int
119  {
120  $query = 'SELECT id FROM ' . self::TABLE_NAME;
121  $res = $this->db->query($query);
122  return $this->db->numRows($res);
123  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getArray()

ilOrgUnitPositionDBRepository::getArray ( ?string  $key = null,
?string  $field = null 
)

Returns position data as an array, e.g.

for using ids in forms

Exceptions
Exception

Implements OrgUnitPositionRepository.

Definition at line 130 of file class.ilOrgUnitPositionDBRepository.php.

References $res, and ILIAS\Repository\int().

130  : array
131  {
132  if (!in_array($key, ['id', null])) {
133  throw new Exception("Invalid key: " . $field);
134  }
135 
136  $fields = [
137  'id' => 'int',
138  'title' => 'string',
139  'description' => 'string',
140  'core_identifier' => 'int',
141  'core_position' => 'int'
142  ];
143  if (!in_array($field, array_keys($fields)) && $field !== null) {
144  throw new Exception("Invalid field: " . $field);
145  }
146 
147  if ($field !== null && $this->db->tableColumnExists(self::TABLE_NAME, $field)) {
148  $query = 'SELECT id, ' . $field . ' FROM' . PHP_EOL
149  . self::TABLE_NAME
150  . ' WHERE 1';
151 
152  $res = $this->db->query($query);
153  $ret = [];
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;
160  }
161  if ($key !== null) {
162  $ret[$rec[$key]] = $value;
163  } else {
164  $ret[] = $value;
165  }
166  }
167  } else {
168  $query = 'SELECT id, title, description, core_identifier, core_position FROM' . PHP_EOL
169  . self::TABLE_NAME
170  . ' WHERE 1';
171  $res = $this->db->query($query);
172  $ret = [];
173  while ($rec = $this->db->fetchAssoc($res)) {
174  if ($key !== null) {
175  $ret[$key] = $rec;
176  } else {
177  $ret[] = $rec;
178  }
179  }
180  }
181 
182  return $ret;
183  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getAuthority()

ilOrgUnitPositionDBRepository::getAuthority ( ?int  $id)

Gets or creates an authority object, as the authority repo is encapsulated into this repo.

Implements OrgUnitPositionRepository.

Definition at line 315 of file class.ilOrgUnitPositionDBRepository.php.

316  {
317  if ($id === null) {
318  return $this->authorityRepo->create();
319  } else {
320  $authority = $this->authorityRepo->get($id, 'id');
321  return array_shift($authority);
322  }
323  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
Class ilOrguAuthority.

◆ getAuthorityDescription()

ilOrgUnitPositionDBRepository::getAuthorityDescription ( array  $authorities)
private

Definition at line 354 of file class.ilOrgUnitPositionDBRepository.php.

References ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), ILIAS\Repository\lng(), ilOrgUnitAuthority\OVER_EVERYONE, ilOrgUnitAuthority\SCOPE_SAME_ORGU, and ilOrgUnitAuthority\SCOPE_SUBSEQUENT_ORGUS.

Referenced by getRows().

354  : array
355  {
356  $lang_keys = [
357  'in',
358  'over',
362  ];
363  $t = [];
364  foreach ($lang_keys as $key) {
365  $t[$key] = $this->lng->txt($key);
366  }
367 
368  $authority_description = [];
369  foreach ($authorities as $authority) {
370  switch ($authority->getOver()) {
372  $over_txt = $t["over_" . $authority->getOver()];
373  break;
374  default:
375  $over_txt = $this
376  ->getSingle($authority->getOver(), 'id')
377  ->getTitle();
378  break;
379  }
380 
381  $authority_description[] = implode(" ", [
382  $t["over"],
383  $over_txt,
384  $t["in"],
385  $t["scope_" . $authority->getScope()]
386  ]);
387  }
388 
389  return $authority_description;
390  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPositionsForOrgUnit()

ilOrgUnitPositionDBRepository::getPositionsForOrgUnit ( int  $orgu_id)

Returns all core positions plus all positions with user assignments for a certain org unit (kept for compatibility, filtering by ua will be moved to orgu later)

Returns
ilOrgUnitPosition[]

Implements OrgUnitPositionRepository.

Definition at line 191 of file class.ilOrgUnitPositionDBRepository.php.

References $res, ilOrgUnitAuthority\POSITION_ID, and ILIAS\GlobalScreen\Scope\Footer\Factory\withTitle().

191  : array
192  {
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);
201  $ret = [];
202  while ($rec = $this->db->fetchAssoc($res)) {
203  $ret[] = (new ilOrgUnitPosition((int) $rec['id']))
204  ->withTitle((string) $rec['title'])
205  ->withDescription((string) $rec['description'])
206  ->withCorePosition((bool) $rec['core_position'])
207  ->withCoreIdentifier((int) $rec['core_identifier'])
208  ->withAuthorities($this->authorityRepo->get((int) $rec['id'], ilOrgUnitAuthority::POSITION_ID));
209  }
210 
211  return $ret;
212  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getRows()

ilOrgUnitPositionDBRepository::getRows ( Table\DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
?array  $filter_data,
?array  $additional_parameters 
)

Definition at line 332 of file class.ilOrgUnitPositionDBRepository.php.

References OrgUnitPositionRepository\getAllPositions(), and getAuthorityDescription().

339  : \Generator {
340  foreach ($this->getAllPositions($range, $order) as $pos) {
341  $row_id = (string) $pos->getId();
342  $record = [
343  'title' => $pos->getTitle(),
344  'description' => $pos->getDescription(),
345  'authorities' => implode("<br>", $this->getAuthorityDescription($pos->getAuthorities())),
346  'is_core_position' => $pos->isCorePosition(),
347  ];
348 
349  yield $row_builder->buildDataRow($row_id, $record)
350  ->withDisabledAction('delete', $record['is_core_position']);
351  }
352  }
+ Here is the call graph for this function:

◆ getSingle()

ilOrgUnitPositionDBRepository::getSingle ( int|string  $value,
string  $field 
)

Get a single position from a filtered query (see get())

Implements OrgUnitPositionRepository.

Definition at line 77 of file class.ilOrgUnitPositionDBRepository.php.

78  {
79  $pos = $this->get($value, $field);
80  if (count($pos) === 0) {
81  return null;
82  }
83 
84  return (array_shift($pos));
85  }

◆ getTotalRowCount()

ilOrgUnitPositionDBRepository::getTotalRowCount ( ?array  $filter_data,
?array  $additional_parameters 
)

Definition at line 325 of file class.ilOrgUnitPositionDBRepository.php.

References getAllPositionsCount().

328  : ?int {
329  return $this->getAllPositionsCount();
330  }
+ Here is the call graph for this function:

◆ insert()

ilOrgUnitPositionDBRepository::insert ( ilOrgUnitPosition  $position)
private

Definition at line 253 of file class.ilOrgUnitPositionDBRepository.php.

References $id, ilOrgUnitPosition\getAuthorities(), ilOrgUnitPosition\getCoreIdentifier(), ilOrgUnitPosition\getDescription(), ilOrgUnitPosition\getTitle(), ilOrgUnitPosition\isCorePosition(), and ILIAS\GlobalScreen\Scope\Footer\Factory\withTitle().

Referenced by store().

254  {
255  $id = $this->db->nextId(self::TABLE_NAME);
256 
257  $values = [
258  'id' => [ 'integer', $id],
259  'title' => [ 'text', $position->getTitle() ],
260  'description' => [ 'text', $position->getDescription() ],
261  'core_position' => [ 'integer', ($position->isCorePosition()) ? 1 : 0 ],
262  'core_identifier' => [ 'integer', $position->getCoreIdentifier() ]
263  ];
264 
265  $this->db->insert(self::TABLE_NAME, $values);
266 
267  $ret = (new ilOrgUnitPosition($id))
268  ->withTitle($position->getTitle())
269  ->withDescription($position->getDescription())
270  ->withCorePosition($position->isCorePosition())
271  ->withCoreIdentifier($position->getCoreIdentifier())
272  ->withAuthorities($position->getAuthorities());
273 
274  return $ret;
275  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store()

ilOrgUnitPositionDBRepository::store ( ilOrgUnitPosition  $position)

Saves position and its authorities.

Implements OrgUnitPositionRepository.

Definition at line 222 of file class.ilOrgUnitPositionDBRepository.php.

References ilOrgUnitPosition\getAuthorities(), ilOrgUnitPosition\getId(), insert(), update(), and ilOrgUnitPosition\withAuthorities().

223  {
224  if ($position->getId() === 0) {
225  $position = $this->insert($position);
226  } else {
227  $this->update($position);
228  }
229 
230  $authorities = $position->getAuthorities();
231  $ids = [];
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;
237  }
238  $position = $position->withAuthorities($new_authorities);
239 
240  if (count($ids) > 0) {
241  $this->authorityRepo->deleteLeftoverAuthorities($ids, $position->getId());
242  }
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());
247  }
248  }
249 
250  return $position;
251  }
withAuthorities(array $authorities)
+ Here is the call graph for this function:

◆ update()

ilOrgUnitPositionDBRepository::update ( ilOrgUnitPosition  $position)
private

Definition at line 277 of file class.ilOrgUnitPositionDBRepository.php.

References ilOrgUnitPosition\getCoreIdentifier(), ilOrgUnitPosition\getDescription(), ilOrgUnitPosition\getId(), ilOrgUnitPosition\getTitle(), and ilOrgUnitPosition\isCorePosition().

Referenced by store().

277  : void
278  {
279  $where = [ 'id' => [ 'integer', $position->getId() ] ];
280 
281  $values = [
282  'title' => [ 'text', $position->getTitle() ],
283  'description' => [ 'text', $position->getDescription() ],
284  'core_position' => [ 'integer', (($position->isCorePosition()) ? 1 : 0) ],
285  'core_identifier' => [ 'integer', $position->getCoreIdentifier() ]
286  ];
287 
288  $this->db->update(self::TABLE_NAME, $values, $where);
289  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ TABLE_NAME

const ilOrgUnitPositionDBRepository::TABLE_NAME = 'il_orgu_positions'

Definition at line 28 of file class.ilOrgUnitPositionDBRepository.php.

◆ TABLE_NAME_UA

const ilOrgUnitPositionDBRepository::TABLE_NAME_UA = 'il_orgu_ua'
private

Definition at line 29 of file class.ilOrgUnitPositionDBRepository.php.


The documentation for this class was generated from the following file: