ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDidacticTemplateAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 public const TYPE_LOCAL_POLICY = 1;
28 public const TYPE_LOCAL_ROLE = 2;
29 public const TYPE_BLOCK_ROLE = 3;
30
31 public const FILTER_SOURCE_TITLE = 1;
32 public const FILTER_SOURCE_OBJ_ID = 2;
33 public const FILTER_PARENT_ROLES = 3;
34 public const FILTER_LOCAL_ROLES = 4;
35
36 public const PATTERN_PARENT_TYPE = 'action';
37
38 protected ilLogger $logger;
39 protected ilDBInterface $db;
42
43 private int $action_id = 0;
44 private int $tpl_id = 0;
45 private int $type = 0;
46
47 private int $ref_id = 0;
48
49 public function __construct(int $action_id = 0)
50 {
51 global $DIC;
52
53 $this->logger = $DIC->logger()->otpl();
54 $this->db = $DIC->database();
55 $this->review = $DIC->rbac()->review();
56 $this->admin = $DIC->rbac()->admin();
57
58 $this->setActionId($action_id);
59 $this->read();
60 }
61
62 public function getLogger(): ilLogger
63 {
64 return $this->logger;
65 }
66
67 public function getActionId(): int
68 {
69 return $this->action_id;
70 }
71
72 public function setActionId(int $a_action_id): void
73 {
74 $this->action_id = $a_action_id;
75 }
76
77 public function setType(int $a_type_id): void
78 {
79 $this->type = $a_type_id;
80 }
81
82 public function setTemplateId(int $a_id): void
83 {
84 $this->tpl_id = $a_id;
85 }
86
87 public function getTemplateId(): int
88 {
89 return $this->tpl_id;
90 }
91
92 public function setRefId(int $a_ref_id): void
93 {
94 $this->ref_id = $a_ref_id;
95 }
96
97 public function getRefId(): int
98 {
99 return $this->ref_id;
100 }
101
107 public function save(): int
108 {
109 if ($this->getActionId()) {
110 return 0;
111 }
112
113 $this->setActionId($this->db->nextId('didactic_tpl_a'));
114 $query = 'INSERT INTO didactic_tpl_a (id, tpl_id, type_id) ' .
115 'VALUES( ' .
116 $this->db->quote($this->getActionId(), 'integer') . ', ' .
117 $this->db->quote($this->getTemplateId(), 'integer') . ', ' .
118 $this->db->quote($this->getType(), 'integer') .
119 ')';
120 $this->db->manipulate($query);
121
122 return $this->getActionId();
123 }
124
129 public function delete(): void
130 {
131 $query = 'DELETE FROM didactic_tpl_a ' .
132 'WHERE id = ' . $this->db->quote($this->getActionId(), 'integer');
133 $this->db->manipulate($query);
134 }
135
136 public function read(): void
137 {
138 $query = 'SELECT * FROM didactic_tpl_a ' .
139 'WHERE id = ' . $this->db->quote($this->getActionId(), 'integer');
140 $res = $this->db->query($query);
141 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
142 $this->setTemplateId((int) $row->tpl_id);
143 }
144 }
145
150 abstract public function getType(): int;
151
156 abstract public function apply(): bool;
157
162 abstract public function revert(): bool;
163
164 public function __clone()
165 {
166 $this->setActionId(0);
167 }
168
169 abstract public function toXml(ilXmlWriter $writer): void;
170
171 protected function initSourceObject(): ilObject
172 {
173 $s = ilObjectFactory::getInstanceByRefId($this->getRefId(), false);
174 return $s;
175 }
176
177 protected function filterRoles(ilObject $source): array
178 {
180 $this->getActionId(),
181 self::PATTERN_PARENT_TYPE
182 );
183
184 $filtered = array();
185 foreach ($this->review->getParentRoleIds($source->getRefId()) as $role_id => $role) {
186 $role_id = (int) $role_id;
187 switch ($this->getFilterType()) {
189 $this->logger->dump($role);
190 if (
191 $role['assign'] === 'y' &&
192 (int) $role['parent'] === $source->getRefId()
193
194 ) {
195 $this->logger->debug('Excluding local role: ' . $role['title']);
196 break;
197 }
198 foreach ($patterns as $pattern) {
199 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
200 $this->logger->debug('Role is valid: ' . ilObject::_lookupTitle($role_id));
201 $filtered[$role_id] = $role;
202 }
203 }
204 break;
205
207 if (
208 $role['assign'] === 'n' ||
209 (int) $role['parent'] !== $source->getRefId()
210 ) {
211 $this->logger->debug('Excluding non local role' . $role['title']);
212 break;
213 }
214 foreach ($patterns as $pattern) {
215 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
216 $this->logger->debug('Role is valid ' . ilObject::_lookupTitle($role_id));
217 $filtered[$role_id] = $role;
218 }
219 }
220 break;
221
222 default:
224 foreach ($patterns as $pattern) {
225 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
226 $this->logger->debug('Role is valid: ' . ilObject::_lookupTitle($role_id));
227 $filtered[$role_id] = $role;
228 }
229 }
230 break;
231 }
232 }
233
234 return $filtered;
235 }
236}
Abstract class for template actions.
apply()
Apply action.
revert()
Implement everthing that is necessary to revert a didactic template return bool.
toXml(ilXmlWriter $writer)
getType()
Get type of template.
save()
Write action to db Overwrite for filling additional db fields.
static lookupPatternsByParentId(int $a_parent_id, string $a_parent_type)
Component logger with individual log levels by component id.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _lookupTitle(int $obj_id)
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26