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

Public Member Functions

 __construct (ilDBInterface $db, ilOrgUnitOperationDBRepository $operationRepo, ilOrgUnitOperationContextDBRepository $contextRepo)
 
 get (int $parent_id, int $position_id)
 Get local permission for parent and position If no permission exists yet, it is created from the default setting. More...
 
 find (int $parent_id, int $position_id)
 Find local permission for parent and position Does not create new local permissions, returns null if no local permission exists. More...
 
 store (ilOrgUnitPermission $permission)
 Store permission to db Returns permission with updated fields (see update()) More...
 
 delete (int $parent_id, int $position_id)
 Delete local permission for parent and position Returns false if no local permission exists. More...
 
 update (ilOrgUnitPermission $permission)
 Update/refresh the additional fields of the permssion object (e.g. More...
 
 getLocalorDefault (int $parent_id, int $position_id)
 Get an existing local permission. More...
 
 getDefaultForContext (string $context_name, int $position_id, bool $editable=false)
 Get the default setting for a specified context If the setting does not exist, it is created (if permissions are enabled for this context) More...
 
 getDefaultsForActiveContexts (int $position_id, bool $editable=false)
 Get an array of default settings for all active contexts If the settings don't exist yet, they will be created (if permissions are enabled for these contexts) More...
 

Data Fields

const TABLE_NAME = 'il_orgu_permissions'
 

Protected Attributes

ilOrgUnitOperationContextDBRepository $contextRepo
 
ilDBInterface $db
 
ilOrgUnitOperationDBRepository $operationRepo
 

Private Member Functions

 insertDB (ilOrgUnitPermission $permission)
 
 updateDB (ilOrgUnitPermission $permission)
 
 isContextEnabled (string $context)
 
 convertToArray (string $operations)
 This will be replaced in a future update including a migration for existing db entries. More...
 
 convertToJson (array $operations)
 This will be replaced in a future update including a migration for existing db entries. More...
 

Detailed Description

Definition at line 22 of file class.ilOrgUnitPermissionDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitPermissionDBRepository::__construct ( ilDBInterface  $db,
ilOrgUnitOperationDBRepository  $operationRepo,
ilOrgUnitOperationContextDBRepository  $contextRepo 
)

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

References $contextRepo, $db, and $operationRepo.

30  {
31  $this->db = $db;
32  $this->operationRepo = $operationRepo;
33  $this->contextRepo = $contextRepo;
34  }
ilOrgUnitOperationContextDBRepository $contextRepo

Member Function Documentation

◆ convertToArray()

ilOrgUnitPermissionDBRepository::convertToArray ( string  $operations)
private

This will be replaced in a future update including a migration for existing db entries.

Definition at line 326 of file class.ilOrgUnitPermissionDBRepository.php.

Referenced by find(), and getDefaultForContext().

327  {
328  $ids = json_decode($operations);
329  $ret = [];
330  foreach ($ids as $operation_id) {
331  $ret[] = $this->operationRepo->getById((int) $operation_id);
332  }
333  return $ret;
334  }
+ Here is the caller graph for this function:

◆ convertToJson()

ilOrgUnitPermissionDBRepository::convertToJson ( array  $operations)
private

This will be replaced in a future update including a migration for existing db entries.

Definition at line 340 of file class.ilOrgUnitPermissionDBRepository.php.

Referenced by insertDB(), and updateDB().

341  {
342  $ids = [];
343  foreach ($operations as $operation) {
344  $ids[] = $operation->getOperationId();
345  }
346  return json_encode($ids);
347  }
+ Here is the caller graph for this function:

◆ delete()

ilOrgUnitPermissionDBRepository::delete ( int  $parent_id,
int  $position_id 
)

Delete local permission for parent and position Returns false if no local permission exists.

Exceptions
ilException
ilPositionPermissionsNotActive

Implements OrgUnitPermissionRepository.

Definition at line 170 of file class.ilOrgUnitPermissionDBRepository.php.

References $context, find(), and isContextEnabled().

170  : bool
171  {
172  if ($position_id === 0) {
173  throw new ilException('$position_id cannot be 0');
174  }
175  if ($parent_id <= 0) {
176  throw new ilException('$parent_id cannot be <=0');
177  }
178 
179  $context = $this->contextRepo->getByRefId($parent_id);
180  if (!$context) {
181  throw new ilException('Context for ref_id ' . $parent_id . ' not found');
182  }
183 
184  if (!$this->isContextEnabled($context->getContext())) {
186  "Position-related permissions not active in {$context->getContext()}",
187  $context->getContext()
188  );
189  }
190 
191  $permission = $this->find($parent_id, $position_id);
192  if ($permission) {
193  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
194  . ' WHERE id = ' . $this->db->quote($permission->getId(), 'integer');
195  $this->db->manipulate($query);
196 
197  return true;
198  }
199 
200  return false;
201  }
$context
Definition: webdav.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
find(int $parent_id, int $position_id)
Find local permission for parent and position Does not create new local permissions, returns null if no local permission exists.
+ Here is the call graph for this function:

◆ find()

ilOrgUnitPermissionDBRepository::find ( int  $parent_id,
int  $position_id 
)

Find local permission for parent and position Does not create new local permissions, returns null if no local permission exists.

Implements OrgUnitPermissionRepository.

Definition at line 74 of file class.ilOrgUnitPermissionDBRepository.php.

References $context, $res, convertToArray(), isContextEnabled(), and update().

Referenced by delete(), get(), and getLocalorDefault().

75  {
76  if ($position_id === 0) {
77  throw new ilException('$position_id cannot be 0');
78  }
79  if ($parent_id <= 0) {
80  throw new ilException('$parent_id cannot be <=0');
81  }
82 
83  $context = $this->contextRepo->getByRefId($parent_id);
84  if (!$context) {
85  return null;
86  }
87 
88  if (!$this->isContextEnabled($context->getContext())) {
89  return null;
90  }
91 
92  $query = 'SELECT id, parent_id, context_id, position_id, protected, operations FROM' . PHP_EOL
93  . self::TABLE_NAME
94  . ' WHERE ' . self::TABLE_NAME . '.parent_id = ' . $this->db->quote($parent_id, 'integer') . PHP_EOL
95  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
96  . ' AND ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($context->getId(), 'integer') . PHP_EOL;
97  $res = $this->db->query($query);
98  if ($res->numRows() === 0) {
99  return null;
100  }
101 
102  $rec = $this->db->fetchAssoc($res);
103  $ret = (new ilOrgUnitPermission((int) $rec['id']))
104  ->withParentId((int) $rec["parent_id"])
105  ->withContextId((int) $rec['context_id'])
106  ->withPositionId((int) $rec['position_id'])
107  ->withProtected((bool) $rec['protected'])
108  ->withOperations($this->convertToArray((string) $rec["operations"]));
109 
110  $ret = $this->update($ret);
111  return $ret;
112  }
$res
Definition: ltiservices.php:69
$context
Definition: webdav.php:31
convertToArray(string $operations)
This will be replaced in a future update including a migration for existing db entries.
update(ilOrgUnitPermission $permission)
Update/refresh the additional fields of the permssion object (e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

ilOrgUnitPermissionDBRepository::get ( int  $parent_id,
int  $position_id 
)

Get local permission for parent and position If no permission exists yet, it is created from the default setting.

Exceptions
ilException
ilPositionPermissionsNotActive

Implements OrgUnitPermissionRepository.

Definition at line 36 of file class.ilOrgUnitPermissionDBRepository.php.

References $context, find(), getDefaultForContext(), isContextEnabled(), and store().

37  {
38  if ($position_id === 0) {
39  throw new ilException('$position_id cannot be 0');
40  }
41  if ($parent_id <= 0) {
42  throw new ilException('$parent_id cannot be <=0');
43  }
44 
45  $context = $this->contextRepo->getByRefId($parent_id);
46  if (!$context) {
47  throw new ilException('Context for ref_id ' . $parent_id . ' not found');
48  }
49 
50  if (!$this->isContextEnabled($context->getContext())) {
52  "Position-related permissions not active in {$context->getContext()}",
53  $context->getContext()
54  );
55  }
56 
57  $permission = $this->find($parent_id, $position_id);
58  if ($permission) {
59  return $permission;
60  }
61 
62  $template = $this->getDefaultForContext($context->getContext(), $position_id);
63  $permission = (new ilOrgUnitPermission())
64  ->withParentId($parent_id)
65  ->withContextId($context->getId())
66  ->withPositionId($position_id)
67  ->withOperations($template->getOperations())
68  ->withProtected(false);
69  $permission = $this->store($permission);
70 
71  return $permission;
72  }
$context
Definition: webdav.php:31
store(ilOrgUnitPermission $permission)
Store permission to db Returns permission with updated fields (see update())
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
find(int $parent_id, int $position_id)
Find local permission for parent and position Does not create new local permissions, returns null if no local permission exists.
getDefaultForContext(string $context_name, int $position_id, bool $editable=false)
Get the default setting for a specified context If the setting does not exist, it is created (if perm...
+ Here is the call graph for this function:

◆ getDefaultForContext()

ilOrgUnitPermissionDBRepository::getDefaultForContext ( string  $context_name,
int  $position_id,
bool  $editable = false 
)

Get the default setting for a specified context If the setting does not exist, it is created (if permissions are enabled for this context)

Implements OrgUnitPermissionRepository.

Definition at line 250 of file class.ilOrgUnitPermissionDBRepository.php.

References $context, $res, convertToArray(), ilOrgUnitPermission\PARENT_TEMPLATE, store(), and update().

Referenced by get(), getDefaultsForActiveContexts(), and getLocalorDefault().

251  {
252  if ($position_id === 0) {
253  throw new ilException('$position_id cannot be 0');
254  }
255 
256  $context = $this->contextRepo->find($context_name);
257  if (!$context) {
258  throw new ilException('Context ' . $context_name . ' not found');
259  }
260 
261  $template = false;
262  $query = 'SELECT id, parent_id, context_id, position_id, protected, operations FROM' . PHP_EOL
263  . self::TABLE_NAME
264  . ' WHERE ' . self::TABLE_NAME . '.parent_id = ' . $this->db->quote(ilOrgUnitPermission::PARENT_TEMPLATE, 'integer') . PHP_EOL
265  . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
266  . ' AND ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($context->getId(), 'integer') . PHP_EOL;
267  $res = $this->db->query($query);
268  if ($res->numRows() > 0) {
269  $rec = $this->db->fetchAssoc($res);
270  $template = (new ilOrgUnitPermission((int) $rec['id']))
271  ->withParentId((int) $rec["parent_id"])
272  ->withContextId((int) $rec['context_id'])
273  ->withPositionId((int) $rec['position_id'])
274  ->withProtected((bool) $rec['protected'])
275  ->withOperations($this->convertToArray((string) $rec["operations"]));
276  $template = $this->update($template);
277  }
278 
279  if (!$template) {
280  $template = (new ilOrgUnitPermission())
282  ->withContextId($context->getId())
283  ->withPositionId($position_id)
284  ->withProtected(true);
285  $template = $this->store($template);
286  }
287 
288  $template = $template->withProtected(!$editable);
289  $template = $this->update($template);
290 
291  return $template;
292  }
$res
Definition: ltiservices.php:69
$context
Definition: webdav.php:31
convertToArray(string $operations)
This will be replaced in a future update including a migration for existing db entries.
update(ilOrgUnitPermission $permission)
Update/refresh the additional fields of the permssion object (e.g.
store(ilOrgUnitPermission $permission)
Store permission to db Returns permission with updated fields (see update())
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultsForActiveContexts()

ilOrgUnitPermissionDBRepository::getDefaultsForActiveContexts ( int  $position_id,
bool  $editable = false 
)

Get an array of default settings for all active contexts If the settings don't exist yet, they will be created (if permissions are enabled for these contexts)

Returns
array ilOrgUnitPermission[]

Implements OrgUnitPermissionRepository.

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

References $context, getDefaultForContext(), and ilOrgUnitGlobalSettings\getInstance().

294  : array
295  {
296  $active_contexts = [];
297  foreach (ilOrgUnitGlobalSettings::getInstance()->getPositionSettings() as $ilOrgUnitObjectPositionSetting) {
298  if ($ilOrgUnitObjectPositionSetting->isActive()) {
299  $active_contexts[] = $ilOrgUnitObjectPositionSetting->getType();
300  }
301  }
302 
303  $permissions = [];
304  foreach ($active_contexts as $context) {
305  $permissions[] = $this->getDefaultForContext($context, $position_id, $editable);
306  }
307 
308  return $permissions;
309  }
$context
Definition: webdav.php:31
getDefaultForContext(string $context_name, int $position_id, bool $editable=false)
Get the default setting for a specified context If the setting does not exist, it is created (if perm...
+ Here is the call graph for this function:

◆ getLocalorDefault()

ilOrgUnitPermissionDBRepository::getLocalorDefault ( int  $parent_id,
int  $position_id 
)

Get an existing local permission.

If a local permission does not exist, return a protected default setting (if permissions are enabled for the context of the parent_id)

Exceptions
ilException
ilPositionPermissionsNotActive

Implements OrgUnitPermissionRepository.

Definition at line 224 of file class.ilOrgUnitPermissionDBRepository.php.

References $context, find(), getDefaultForContext(), and isContextEnabled().

225  {
226  if ($position_id === 0) {
227  throw new ilException('$position_id cannot be 0');
228  }
229 
230  $context = $this->contextRepo->getByRefId($parent_id);
231  if (!$context) {
232  throw new ilException('Context for ref_id ' . $parent_id . ' not found');
233  }
234 
235  if (!$this->isContextEnabled($context->getContext())) {
237  "Position-related permissions not active in {$context->getContext()}",
238  $context->getContext()
239  );
240  }
241 
242  $permission = $this->find($parent_id, $position_id);
243  if ($permission) {
244  return $permission;
245  }
246 
247  return $this->getDefaultForContext($context->getContext(), $position_id);
248  }
$context
Definition: webdav.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
find(int $parent_id, int $position_id)
Find local permission for parent and position Does not create new local permissions, returns null if no local permission exists.
getDefaultForContext(string $context_name, int $position_id, bool $editable=false)
Get the default setting for a specified context If the setting does not exist, it is created (if perm...
+ Here is the call graph for this function:

◆ insertDB()

ilOrgUnitPermissionDBRepository::insertDB ( ilOrgUnitPermission  $permission)
private

Definition at line 132 of file class.ilOrgUnitPermissionDBRepository.php.

References $id, convertToJson(), ilOrgUnitPermission\getContextId(), ilOrgUnitPermission\getOperations(), ilOrgUnitPermission\getParentId(), ilOrgUnitPermission\getPositionId(), and ilOrgUnitPermission\isProtected().

Referenced by store().

133  {
134  $id = $this->db->nextId(self::TABLE_NAME);
135 
136  $values = [
137  'id' => [ 'integer', $id ],
138  'parent_id' => [ 'string', $permission->getParentId()],
139  'context_id' => [ 'string', $permission->getContextId()],
140  'position_id' => [ 'integer', $permission->getPositionId() ],
141  'protected' => [ 'integer', ($permission->isProtected()) ? 1 : 0],
142  'operations' => [ 'string', $this->convertToJson($permission->getOperations())]
143  ];
144 
145  $this->db->insert(self::TABLE_NAME, $values);
146 
147  return (new ilOrgUnitPermission($id))
148  ->withParentId($permission->getParentId())
149  ->withContextId($permission->getContextId())
150  ->withPositionId($permission->getPositionId())
151  ->withProtected($permission->isProtected())
152  ->withOperations($permission->getOperations());
153  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
convertToJson(array $operations)
This will be replaced in a future update including a migration for existing db entries.
$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:

◆ isContextEnabled()

ilOrgUnitPermissionDBRepository::isContextEnabled ( string  $context)
private

Definition at line 311 of file class.ilOrgUnitPermissionDBRepository.php.

References ilOrgUnitGlobalSettings\getInstance().

Referenced by delete(), find(), get(), and getLocalorDefault().

311  : bool
312  {
313  $ilOrgUnitGlobalSettings = ilOrgUnitGlobalSettings::getInstance();
314  $ilOrgUnitObjectPositionSetting = $ilOrgUnitGlobalSettings->getObjectPositionSettingsByType($context);
315  if (!$ilOrgUnitObjectPositionSetting->isActive()) {
316  return false;
317  }
318 
319  return true;
320  }
$context
Definition: webdav.php:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store()

ilOrgUnitPermissionDBRepository::store ( ilOrgUnitPermission  $permission)

Store permission to db Returns permission with updated fields (see update())

Implements OrgUnitPermissionRepository.

Definition at line 114 of file class.ilOrgUnitPermissionDBRepository.php.

References ilOrgUnitPermission\getId(), ilOrgUnitPermission\getParentId(), insertDB(), ilOrgUnitPermission\isProtected(), ilOrgUnitPermission\PARENT_TEMPLATE, update(), updateDB(), and ilOrgUnitPermission\withProtected().

Referenced by get(), and getDefaultForContext().

115  {
116  if ($permission->getId() === 0) {
117  $permission = $this->insertDB($permission);
118  } else {
119  if ($permission->isProtected()) {
120  throw new ilException("Protected permission " . $permission->getId() . " can not be updated");
121  }
122  if ($permission->getParentId() == ilOrgUnitPermission::PARENT_TEMPLATE) {
123  $permission = $permission->withProtected(true);
124  }
125  $this->updateDB($permission);
126  }
127 
128  $permission = $this->update($permission);
129  return $permission;
130  }
update(ilOrgUnitPermission $permission)
Update/refresh the additional fields of the permssion object (e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilOrgUnitPermissionDBRepository::update ( ilOrgUnitPermission  $permission)

Update/refresh the additional fields of the permssion object (e.g.

available operations)

This is done via the repository cause it also needs data from the operations/context repositories Ideally, this should be private use only but is still needed as public in the current version

Implements OrgUnitPermissionRepository.

Definition at line 204 of file class.ilOrgUnitPermissionDBRepository.php.

References ilOrgUnitPermission\getContextId(), ilOrgUnitPermission\getOperations(), ilOrgUnitPermission\withContext(), ilOrgUnitPermission\withOperations(), ilOrgUnitPermission\withPossibleOperations(), and ilOrgUnitPermission\withSelectedOperationIds().

Referenced by find(), getDefaultForContext(), and store().

205  {
206  $permission = $permission->withPossibleOperations(
207  $this->operationRepo->getOperationsByContextId($permission->getContextId())
208  );
209  $permission = $permission->withOperations(
210  is_array($permission->getOperations()) ? $permission->getOperations() : []
211  );
212  $selected_operation_ids = [];
213  foreach ($permission->getOperations() as $operation) {
214  $selected_operation_ids[] = $operation->getOperationId();
215  }
216  $permission = $permission->withSelectedOperationIds($selected_operation_ids);
217  $permission = $permission->withContext(
218  $this->contextRepo->getById($permission->getContextId())
219  );
220 
221  return $permission;
222  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withOperations(array $operations)
withPossibleOperations(array $possible_operations)
withSelectedOperationIds(array $selected_operation_ids)
withContext(ilOrgUnitOperationContext $context)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateDB()

ilOrgUnitPermissionDBRepository::updateDB ( ilOrgUnitPermission  $permission)
private

Definition at line 155 of file class.ilOrgUnitPermissionDBRepository.php.

References convertToJson(), ilOrgUnitPermission\getContextId(), ilOrgUnitPermission\getId(), ilOrgUnitPermission\getOperations(), ilOrgUnitPermission\getParentId(), ilOrgUnitPermission\getPositionId(), and ilOrgUnitPermission\isProtected().

Referenced by store().

155  : void
156  {
157  $where = [ 'id' => [ 'integer', $permission->getId() ] ];
158 
159  $values = [
160  'parent_id' => [ 'string', $permission->getParentId()],
161  'context_id' => [ 'string', $permission->getContextId()],
162  'position_id' => [ 'integer', $permission->getPositionId() ],
163  'protected' => [ 'integer', ($permission->isProtected()) ? 1 : 0],
164  'operations' => [ 'string', $this->convertToJson($permission->getOperations())]
165  ];
166 
167  $this->db->update(self::TABLE_NAME, $values, $where);
168  }
convertToJson(array $operations)
This will be replaced in a future update including a migration for existing db entries.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $contextRepo

ilOrgUnitOperationContextDBRepository ilOrgUnitPermissionDBRepository::$contextRepo
protected

Definition at line 25 of file class.ilOrgUnitPermissionDBRepository.php.

Referenced by __construct().

◆ $db

ilDBInterface ilOrgUnitPermissionDBRepository::$db
protected

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

Referenced by __construct().

◆ $operationRepo

ilOrgUnitOperationDBRepository ilOrgUnitPermissionDBRepository::$operationRepo
protected

Definition at line 27 of file class.ilOrgUnitPermissionDBRepository.php.

Referenced by __construct().

◆ TABLE_NAME

const ilOrgUnitPermissionDBRepository::TABLE_NAME = 'il_orgu_permissions'

Definition at line 24 of file class.ilOrgUnitPermissionDBRepository.php.


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