ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDidacticTemplateBlockRoleAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
28 private array $pattern = [];
30
31 public function __construct(int $action_id = 0)
32 {
34 }
35
37 {
38 $this->pattern[] = $pattern;
39 }
40
45 public function setFilterPatterns(array $patterns): void
46 {
47 $this->pattern = $patterns;
48 }
49
54 public function getFilterPattern(): array
55 {
56 return $this->pattern;
57 }
58
59 public function setFilterType(int $a_type): void
60 {
61 $this->filter_type = $a_type;
62 }
63
64 public function getFilterType(): int
65 {
66 return $this->filter_type;
67 }
68
69 public function save(): int
70 {
71 parent::save();
72 $query = 'INSERT INTO didactic_tpl_abr (action_id,filter_type) ' .
73 'VALUES( ' .
74 $this->db->quote($this->getActionId(), \ilDBConstants::T_INTEGER) . ', ' .
75 $this->db->quote($this->getFilterType(), \ilDBConstants::T_INTEGER) . ' ' .
76 ')';
77 $this->db->manipulate($query);
78
79 foreach ($this->getFilterPattern() as $pattern) {
80 /* @var ilDidacticTemplateFilterPattern $pattern */
81 $pattern->setParentId($this->getActionId());
82 $pattern->setParentType(self::PATTERN_PARENT_TYPE);
83 $pattern->save();
84 }
85
86 return $this->getActionId();
87 }
88
89 public function delete(): void
90 {
91 parent::delete();
92 $query = 'DELETE FROM didactic_tpl_abr ' .
93 'WHERE action_id = ' . $this->db->quote($this->getActionId(), 'integer');
94 $this->db->manipulate($query);
95
96 foreach ($this->getFilterPattern() as $pattern) {
97 $pattern->delete();
98 }
99 }
100
101 public function apply(): bool
102 {
103 $source = $this->initSourceObject();
104 $roles = $this->filterRoles($source);
105
106 // Create local policy for filtered roles
107 foreach ($roles as $role_id => $role) {
108 $this->blockRole($role_id, $source);
109 }
110
111 return true;
112 }
113
114 protected function blockRole(int $a_role_id, ilObject $source): bool
115 {
116 // Set assign to 'y' only if it is a local role
117 $assign = $this->review->isAssignable($a_role_id, $source->getRefId()) ? 'y' : 'n';
118
119 // Delete permissions
120 $this->admin->revokeSubtreePermissions($source->getRefId(), $a_role_id);
121
122 // Delete template permissions
123 $this->admin->deleteSubtreeTemplates($source->getRefId(), $a_role_id);
124
125 $this->admin->assignRoleToFolder(
126 $a_role_id,
127 $source->getRefId(),
128 $assign
129 );
130
131 return true;
132 }
133
134 public function revert(): bool
135 {
136 $source = $this->initSourceObject();
137 $roles = $this->filterRoles($source);
138
139 // Create local policy for filtered roles
140 foreach ($roles as $role_id => $role) {
141 $this->deleteLocalPolicy($role_id, $source);
142 }
143
144 return true;
145 }
146
147 protected function deleteLocalPolicy(int $a_role_id, ilObject $source): bool
148 {
149 // Create role folder if it does not exist
150 //$rolf = $rbacreview->getRoleFolderIdOfObject($source->getRefId());
151
152 if ($this->review->getRoleFolderOfRole($a_role_id) === $source->getRefId()) {
153 $this->logger->debug('Ignoring local role: ' . ilObject::_lookupTitle($a_role_id));
154 return false;
155 }
156
157 $this->admin->deleteLocalRole($a_role_id, $source->getRefId());
158
159 // Change existing object
160 $role = new ilObjRole($a_role_id);
161 $role->changeExistingObjects(
162 $source->getRefId(),
164 ['all']
165 );
166 return true;
167 }
168
169 public function getType(): int
170 {
172 }
173
174 public function toXml(ilXmlWriter $writer): void
175 {
176 $writer->xmlStartTag('blockRoleAction');
177
178 switch ($this->getFilterType()) {
180 $writer->xmlStartTag('roleFilter', ['source' => 'objId']);
181 break;
182
184 $writer->xmlStartTag('roleFilter', ['source' => 'parentRoles']);
185 break;
186
188 default:
189 $writer->xmlStartTag('roleFilter', ['source' => 'title']);
190 break;
191 }
192
193 foreach ($this->getFilterPattern() as $pattern) {
194 $pattern->toXml($writer);
195 }
196 $writer->xmlEndTag('roleFilter');
197 $writer->xmlEndTag('blockRoleAction');
198 }
199
200 public function __clone()
201 {
202 parent::__clone();
203
204 $clones = [];
205 foreach ($this->getFilterPattern() as $pattern) {
206 $clones[] = clone $pattern;
207 }
208 $this->setFilterPatterns($clones);
209 }
210
211 public function read(): void
212 {
213 parent::read();
214 $query = 'SELECT * FROM didactic_tpl_abr ' .
215 'WHERE action_id = ' . $this->db->quote($this->getActionId(), ilDBConstants::T_INTEGER);
216 $res = $this->db->query($query);
217 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
218 $this->setFilterType((int) $row->filter_type);
219 }
220
221 // Read filter
223 $this->getActionId(),
224 self::PATTERN_PARENT_TYPE
225 ) as $pattern) {
226 $this->addFilterPattern($pattern);
227 }
228 }
229}
Abstract class for template actions.
Description of ilDidacticTemplateBlockRoleAction.
save()
Write action to db Overwrite for filling additional db fields.
addFilterPattern(ilDidacticTemplateFilterPattern $pattern)
setFilterPatterns(array $patterns)
Set filter patterns.
revert()
Implement everthing that is necessary to revert a didactic template return bool.
static lookupPatternsByParentId(int $a_parent_id, string $a_parent_type)
Represents a filter pattern for didactic template actions.
Class ilObjRole.
const MODE_UNPROTECTED_DELETE_LOCAL_POLICIES
Class ilObject Basic functions for all objects.
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc