ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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...
 
 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 21 of file class.ilOrgUnitPermissionDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

References $contextRepo, $db, and $operationRepo.

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 325 of file class.ilOrgUnitPermissionDBRepository.php.

326 {
327 $ids = json_decode($operations);
328 $ret = [];
329 foreach ($ids as $operation_id) {
330 $ret[] = $this->operationRepo->getById((int) $operation_id);
331 }
332 return $ret;
333 }

Referenced by find(), and getDefaultForContext().

+ 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 339 of file class.ilOrgUnitPermissionDBRepository.php.

340 {
341 $ids = [];
342 foreach ($operations as $operation) {
343 $ids[] = $operation->getOperationId();
344 }
345 return json_encode($ids);
346 }

Referenced by insertDB(), and updateDB().

+ 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 169 of file class.ilOrgUnitPermissionDBRepository.php.

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

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

+ 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 73 of file class.ilOrgUnitPermissionDBRepository.php.

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

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

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

+ 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 35 of file class.ilOrgUnitPermissionDBRepository.php.

36 {
37 if ($position_id === 0) {
38 throw new ilException('$position_id cannot be 0');
39 }
40 if ($parent_id <= 0) {
41 throw new ilException('$parent_id cannot be <=0');
42 }
43
44 $context = $this->contextRepo->getByRefId($parent_id);
45 if (!$context) {
46 throw new ilException('Context for ref_id ' . $parent_id . ' not found');
47 }
48
49 if (!$this->isContextEnabled($context->getContext())) {
51 "Position-related permissions not active in {$context->getContext()}",
52 $context->getContext()
53 );
54 }
55
56 $permission = $this->find($parent_id, $position_id);
57 if ($permission) {
58 return $permission;
59 }
60
61 $template = $this->getDefaultForContext($context->getContext(), $position_id);
62 $permission = (new ilOrgUnitPermission())
63 ->withParentId($parent_id)
64 ->withContextId($context->getId())
65 ->withPositionId($position_id)
66 ->withOperations($template->getOperations())
67 ->withProtected(false);
68 $permission = $this->store($permission);
69
70 return $permission;
71 }
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...
store(ilOrgUnitPermission $permission)
Store permission to db Returns permission with updated fields (see update())

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

+ 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 249 of file class.ilOrgUnitPermissionDBRepository.php.

250 {
251 if ($position_id === 0) {
252 throw new ilException('$position_id cannot be 0');
253 }
254
255 $context = $this->contextRepo->find($context_name);
256 if (!$context) {
257 throw new ilException('Context ' . $context_name . ' not found');
258 }
259
260 $template = false;
261 $query = 'SELECT id, parent_id, context_id, position_id, protected, operations FROM' . PHP_EOL
262 . self::TABLE_NAME
263 . ' WHERE ' . self::TABLE_NAME . '.parent_id = ' . $this->db->quote(ilOrgUnitPermission::PARENT_TEMPLATE, 'integer') . PHP_EOL
264 . ' AND ' . self::TABLE_NAME . '.position_id = ' . $this->db->quote($position_id, 'integer') . PHP_EOL
265 . ' AND ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($context->getId(), 'integer') . PHP_EOL;
266 $res = $this->db->query($query);
267 if ($res->numRows() > 0) {
268 $rec = $this->db->fetchAssoc($res);
269 $template = (new ilOrgUnitPermission((int) $rec['id']))
270 ->withParentId((int) $rec["parent_id"])
271 ->withContextId((int) $rec['context_id'])
272 ->withPositionId((int) $rec['position_id'])
273 ->withProtected((bool) $rec['protected'])
274 ->withOperations($this->convertToArray((string) $rec["operations"]));
275 $template = $this->update($template);
276 }
277
278 if (!$template) {
279 $template = (new ilOrgUnitPermission())
281 ->withContextId($context->getId())
282 ->withPositionId($position_id)
283 ->withProtected(true);
284 $template = $this->store($template);
285 }
286
287 $template = $template->withProtected(!$editable);
288 $template = $this->update($template);
289
290 return $template;
291 }

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

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

+ 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 293 of file class.ilOrgUnitPermissionDBRepository.php.

293 : array
294 {
295 $active_contexts = [];
296 foreach (ilOrgUnitGlobalSettings::getInstance()->getPositionSettings() as $ilOrgUnitObjectPositionSetting) {
297 if ($ilOrgUnitObjectPositionSetting->isActive()) {
298 $active_contexts[] = $ilOrgUnitObjectPositionSetting->getType();
299 }
300 }
301
302 $permissions = [];
303 foreach ($active_contexts as $context) {
304 $permissions[] = $this->getDefaultForContext($context, $position_id, $editable);
305 }
306
307 return $permissions;
308 }

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

+ 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 223 of file class.ilOrgUnitPermissionDBRepository.php.

224 {
225 if ($position_id === 0) {
226 throw new ilException('$position_id cannot be 0');
227 }
228
229 $context = $this->contextRepo->getByRefId($parent_id);
230 if (!$context) {
231 throw new ilException('Context for ref_id ' . $parent_id . ' not found');
232 }
233
234 if (!$this->isContextEnabled($context->getContext())) {
236 "Position-related permissions not active in {$context->getContext()}",
237 $context->getContext()
238 );
239 }
240
241 $permission = $this->find($parent_id, $position_id);
242 if ($permission) {
243 return $permission;
244 }
245
246 return $this->getDefaultForContext($context->getContext(), $position_id);
247 }

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

+ Here is the call graph for this function:

◆ insertDB()

ilOrgUnitPermissionDBRepository::insertDB ( ilOrgUnitPermission  $permission)
private

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

132 {
133 $id = $this->db->nextId(self::TABLE_NAME);
134
135 $values = [
136 'id' => [ 'integer', $id ],
137 'parent_id' => [ 'string', $permission->getParentId()],
138 'context_id' => [ 'string', $permission->getContextId()],
139 'position_id' => [ 'integer', $permission->getPositionId() ],
140 'protected' => [ 'integer', ($permission->isProtected()) ? 1 : 0],
141 'operations' => [ 'string', $this->convertToJson($permission->getOperations())]
142 ];
143
144 $this->db->insert(self::TABLE_NAME, $values);
145
146 return (new ilOrgUnitPermission($id))
147 ->withParentId($permission->getParentId())
148 ->withContextId($permission->getContextId())
149 ->withPositionId($permission->getPositionId())
150 ->withProtected($permission->isProtected())
151 ->withOperations($permission->getOperations());
152 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
convertToJson(array $operations)
This will be replaced in a future update including a migration for existing db entries.

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

Referenced by store().

+ 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 310 of file class.ilOrgUnitPermissionDBRepository.php.

310 : bool
311 {
312 $ilOrgUnitGlobalSettings = ilOrgUnitGlobalSettings::getInstance();
313 $ilOrgUnitObjectPositionSetting = $ilOrgUnitGlobalSettings->getObjectPositionSettingsByType($context);
314 if (!$ilOrgUnitObjectPositionSetting->isActive()) {
315 return false;
316 }
317
318 return true;
319 }

References $context, and ilOrgUnitGlobalSettings\getInstance().

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

+ 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 113 of file class.ilOrgUnitPermissionDBRepository.php.

114 {
115 if ($permission->getId() === 0) {
116 $permission = $this->insertDB($permission);
117 } else {
118 if ($permission->isProtected()) {
119 throw new ilException("Protected permission " . $permission->getId() . " can not be updated");
120 }
122 $permission = $permission->withProtected(true);
123 }
124 $this->updateDB($permission);
125 }
126
127 $permission = $this->update($permission);
128 return $permission;
129 }

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

Referenced by get(), and getDefaultForContext().

+ 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 203 of file class.ilOrgUnitPermissionDBRepository.php.

204 {
205 $permission = $permission->withPossibleOperations(
206 $this->operationRepo->getOperationsByContextId($permission->getContextId())
207 );
208 $permission = $permission->withOperations(
209 is_array($permission->getOperations()) ? $permission->getOperations() : []
210 );
211 $selected_operation_ids = [];
212 foreach ($permission->getOperations() as $operation) {
213 $selected_operation_ids[] = $operation->getOperationId();
214 }
215 $permission = $permission->withSelectedOperationIds($selected_operation_ids);
216 $permission = $permission->withContext(
217 $this->contextRepo->getById($permission->getContextId())
218 );
219
220 return $permission;
221 }
withOperations(array $operations)
withPossibleOperations(array $possible_operations)
withSelectedOperationIds(array $selected_operation_ids)
withContext(ilOrgUnitOperationContext $context)

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

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

+ 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 154 of file class.ilOrgUnitPermissionDBRepository.php.

154 : void
155 {
156 $where = [ 'id' => [ 'integer', $permission->getId() ] ];
157
158 $values = [
159 'parent_id' => [ 'string', $permission->getParentId()],
160 'context_id' => [ 'string', $permission->getContextId()],
161 'position_id' => [ 'integer', $permission->getPositionId() ],
162 'protected' => [ 'integer', ($permission->isProtected()) ? 1 : 0],
163 'operations' => [ 'string', $this->convertToJson($permission->getOperations())]
164 ];
165
166 $this->db->update(self::TABLE_NAME, $values, $where);
167 }

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

Referenced by store().

+ 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 24 of file class.ilOrgUnitPermissionDBRepository.php.

Referenced by __construct().

◆ $db

ilDBInterface ilOrgUnitPermissionDBRepository::$db
protected

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

Referenced by __construct().

◆ $operationRepo

ilOrgUnitOperationDBRepository ilOrgUnitPermissionDBRepository::$operationRepo
protected

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

Referenced by __construct().

◆ TABLE_NAME

const ilOrgUnitPermissionDBRepository::TABLE_NAME = 'il_orgu_permissions'

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


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