20 declare(strict_types=1);
38 if ($position_id === 0) {
41 if ($parent_id <= 0) {
45 $context = $this->contextRepo->getByRefId($parent_id);
47 throw new ilException(
'Context for ref_id ' . $parent_id .
' not found');
52 "Position-related permissions not active in {$context->getContext()}",
57 $permission = $this->
find($parent_id, $position_id);
64 ->withParentId($parent_id)
66 ->withPositionId($position_id)
67 ->withOperations($template->getOperations())
68 ->withProtected(
false);
69 $permission = $this->
store($permission);
76 if ($position_id === 0) {
79 if ($parent_id <= 0) {
83 $context = $this->contextRepo->getByRefId($parent_id);
92 $query =
'SELECT id, parent_id, context_id, position_id, protected, operations FROM' . PHP_EOL
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) {
102 $rec = $this->db->fetchAssoc(
$res);
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"]));
110 $ret = $this->
update($ret);
116 if ($permission->
getId() === 0) {
117 $permission = $this->
insertDB($permission);
120 throw new ilException(
"Protected permission " . $permission->
getId() .
" can not be updated");
128 $permission = $this->
update($permission);
134 $id = $this->db->nextId(self::TABLE_NAME);
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],
145 $this->db->insert(self::TABLE_NAME, $values);
157 $where = [
'id' => [
'integer', $permission->
getId() ] ];
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],
167 $this->db->update(self::TABLE_NAME, $values, $where);
170 public function delete(
int $parent_id,
int $position_id):
bool 172 if ($position_id === 0) {
175 if ($parent_id <= 0) {
179 $context = $this->contextRepo->getByRefId($parent_id);
181 throw new ilException(
'Context for ref_id ' . $parent_id .
' not found');
186 "Position-related permissions not active in {$context->getContext()}",
191 $permission = $this->
find($parent_id, $position_id);
193 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
194 .
' WHERE id = ' . $this->db->quote($permission->getId(),
'integer');
195 $this->db->manipulate($query);
207 $this->operationRepo->getOperationsByContextId($permission->
getContextId())
212 $selected_operation_ids = [];
214 $selected_operation_ids[] = $operation->getOperationId();
218 $this->contextRepo->getById($permission->
getContextId())
226 if ($position_id === 0) {
230 $context = $this->contextRepo->getByRefId($parent_id);
232 throw new ilException(
'Context for ref_id ' . $parent_id .
' not found');
237 "Position-related permissions not active in {$context->getContext()}",
242 $permission = $this->
find($parent_id, $position_id);
252 if ($position_id === 0) {
256 $context = $this->contextRepo->find($context_name);
258 throw new ilException(
'Context ' . $context_name .
' not found');
262 $query =
'SELECT id, parent_id, context_id, position_id, protected, operations FROM' . 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);
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);
283 ->withPositionId($position_id)
284 ->withProtected(
true);
285 $template = $this->
store($template);
288 $template = $template->withProtected(!$editable);
289 $template = $this->
update($template);
296 $active_contexts = [];
298 if ($ilOrgUnitObjectPositionSetting->isActive()) {
299 $active_contexts[] = $ilOrgUnitObjectPositionSetting->getType();
304 foreach ($active_contexts as
$context) {
314 $ilOrgUnitObjectPositionSetting = $ilOrgUnitGlobalSettings->getObjectPositionSettingsByType($context);
315 if (!$ilOrgUnitObjectPositionSetting->isActive()) {
328 $ids = json_decode($operations);
330 foreach ($ids as $operation_id) {
331 $ret[] = $this->operationRepo->getById((
int) $operation_id);
343 foreach ($operations as $operation) {
344 $ids[] = $operation->getOperationId();
346 return json_encode($ids);
isContextEnabled(string $context)
insertDB(ilOrgUnitPermission $permission)
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())
ilOrgUnitOperationDBRepository $operationRepo
getLocalorDefault(int $parent_id, int $position_id)
Get an existing local permission.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateDB(ilOrgUnitPermission $permission)
withOperations(array $operations)
withPossibleOperations(array $possible_operations)
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.
withProtected(bool $protected)
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.
__construct(ilDBInterface $db, ilOrgUnitOperationDBRepository $operationRepo, ilOrgUnitOperationContextDBRepository $contextRepo)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
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...
ilOrgUnitOperationContextDBRepository $contextRepo
withSelectedOperationIds(array $selected_operation_ids)
getDefaultsForActiveContexts(int $position_id, bool $editable=false)
Get an array of default settings for all active contexts If the settings don't exist yet...
withContext(ilOrgUnitOperationContext $context)