ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 25 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 30 of file class.ilOrgUnitPositionDBRepository.php.

References ILIAS\Repository\lng().

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

Member Function Documentation

◆ create()

ilOrgUnitPositionDBRepository::create ( )

Implements OrgUnitPositionRepository.

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

214  {
215  return new ilOrgUnitPosition();
216  }

◆ delete()

ilOrgUnitPositionDBRepository::delete ( int  $position_id)

Deletes position and authorities/user assignments attached to it.

Implements OrgUnitPositionRepository.

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

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

◆ 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 45 of file class.ilOrgUnitPositionDBRepository.php.

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

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

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

◆ getAllPositionsCount()

ilOrgUnitPositionDBRepository::getAllPositionsCount ( )
protected

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

References $res.

Referenced by getTotalRowCount().

117  : int
118  {
119  $query = 'SELECT id FROM ' . self::TABLE_NAME;
120  $res = $this->db->query($query);
121  return $this->db->numRows($res);
122  }
$res
Definition: ltiservices.php:66
+ 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 129 of file class.ilOrgUnitPositionDBRepository.php.

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

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

References null.

315  {
316  if ($id === null) {
317  return $this->authorityRepo->create();
318  } else {
319  $authority = $this->authorityRepo->get($id, 'id');
320  return array_shift($authority);
321  }
322  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilOrguAuthority.

◆ getAuthorityDescription()

ilOrgUnitPositionDBRepository::getAuthorityDescription ( array  $authorities)
private

Definition at line 353 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().

353  : array
354  {
355  $lang_keys = [
356  'in',
357  'over',
361  ];
362  $t = [];
363  foreach ($lang_keys as $key) {
364  $t[$key] = $this->lng->txt($key);
365  }
366 
367  $authority_description = [];
368  foreach ($authorities as $authority) {
369  switch ($authority->getOver()) {
371  $over_txt = $t["over_" . $authority->getOver()];
372  break;
373  default:
374  $over_txt = $this
375  ->getSingle($authority->getOver(), 'id')
376  ->getTitle();
377  break;
378  }
379 
380  $authority_description[] = implode(" ", [
381  $t["over"],
382  $over_txt,
383  $t["in"],
384  $t["scope_" . $authority->getScope()]
385  ]);
386  }
387 
388  return $authority_description;
389  }
+ 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 190 of file class.ilOrgUnitPositionDBRepository.php.

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

190  : array
191  {
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);
200  $ret = [];
201  while ($rec = $this->db->fetchAssoc($res)) {
202  $ret[] = (new ilOrgUnitPosition((int) $rec['id']))
203  ->withTitle((string) $rec['title'])
204  ->withDescription((string) $rec['description'])
205  ->withCorePosition((bool) $rec['core_position'])
206  ->withCoreIdentifier((int) $rec['core_identifier'])
207  ->withAuthorities($this->authorityRepo->get((int) $rec['id'], ilOrgUnitAuthority::POSITION_ID));
208  }
209 
210  return $ret;
211  }
$res
Definition: ltiservices.php:66
+ 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 331 of file class.ilOrgUnitPositionDBRepository.php.

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

338  : \Generator {
339  foreach ($this->getAllPositions($range, $order) as $pos) {
340  $row_id = (string) $pos->getId();
341  $record = [
342  'title' => $pos->getTitle(),
343  'description' => $pos->getDescription() . 'dd',
344  'authorities' => implode("<br>", $this->getAuthorityDescription($pos->getAuthorities())),
345  'is_core_position' => $pos->isCorePosition(),
346  ];
347 
348  yield $row_builder->buildDataRow($row_id, $record)
349  ->withDisabledAction('delete', $record['is_core_position']);
350  }
351  }
+ 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 76 of file class.ilOrgUnitPositionDBRepository.php.

References null.

77  {
78  $pos = $this->get($value, $field);
79  if (count($pos) === 0) {
80  return null;
81  }
82 
83  return (array_shift($pos));
84  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getTotalRowCount()

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

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

References getAllPositionsCount().

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

◆ insert()

ilOrgUnitPositionDBRepository::insert ( ilOrgUnitPosition  $position)
private

Definition at line 252 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().

253  {
254  $id = $this->db->nextId(self::TABLE_NAME);
255 
256  $values = [
257  'id' => [ 'integer', $id],
258  'title' => [ 'text', $position->getTitle() ],
259  'description' => [ 'text', $position->getDescription() ],
260  'core_position' => [ 'integer', ($position->isCorePosition()) ? 1 : 0 ],
261  'core_identifier' => [ 'integer', $position->getCoreIdentifier() ]
262  ];
263 
264  $this->db->insert(self::TABLE_NAME, $values);
265 
266  $ret = (new ilOrgUnitPosition($id))
267  ->withTitle($position->getTitle())
268  ->withDescription($position->getDescription())
269  ->withCorePosition($position->isCorePosition())
270  ->withCoreIdentifier($position->getCoreIdentifier())
271  ->withAuthorities($position->getAuthorities());
272 
273  return $ret;
274  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ 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 221 of file class.ilOrgUnitPositionDBRepository.php.

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

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

◆ update()

ilOrgUnitPositionDBRepository::update ( ilOrgUnitPosition  $position)
private

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

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

Referenced by store().

276  : void
277  {
278  $where = [ 'id' => [ 'integer', $position->getId() ] ];
279 
280  $values = [
281  'title' => [ 'text', $position->getTitle() ],
282  'description' => [ 'text', $position->getDescription() ],
283  'core_position' => [ 'integer', (($position->isCorePosition()) ? 1 : 0) ],
284  'core_identifier' => [ 'integer', $position->getCoreIdentifier() ]
285  ];
286 
287  $this->db->update(self::TABLE_NAME, $values, $where);
288  }
+ 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 27 of file class.ilOrgUnitPositionDBRepository.php.

◆ TABLE_NAME_UA

const ilOrgUnitPositionDBRepository::TABLE_NAME_UA = 'il_orgu_ua'
private

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


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