ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDidacticTemplateAction.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
13 const TYPE_LOCAL_ROLE = 2;
14 const TYPE_BLOCK_ROLE = 3;
15
20
21 const PATTERN_PARENT_TYPE = 'action';
22
26 private $logger = null;
27
28 private $action_id = 0;
29 private $tpl_id = 0;
30 private $type = 0;
31
32
33 private $ref_id = 0;
34
35
39 public function __construct($action_id = 0)
40 {
41 global $DIC;
42
43 $this->logger = $DIC->logger()->otpl();
44
45 $this->setActionId($action_id);
46 $this->read();
47 }
48
53 public function getLogger()
54 {
55 return $this->logger;
56 }
57
62 public function getActionId()
63 {
64 return $this->action_id;
65 }
66
71 public function setActionId($a_action_id)
72 {
73 $this->action_id = $a_action_id;
74 }
75
81 public function setType($a_type_id)
82 {
83 $this->type = $a_type_id;
84 }
85
90 public function setTemplateId($a_id)
91 {
92 $this->tpl_id = $a_id;
93 }
94
99 public function getTemplateId()
100 {
101 return $this->tpl_id;
102 }
103
109 public function setRefId($a_ref_id)
110 {
111 $this->ref_id = $a_ref_id;
112 }
113
117 public function getRefId()
118 {
119 return $this->ref_id;
120 }
121
128 public function save()
129 {
130 global $DIC;
131
132 $ilDB = $DIC['ilDB'];
133
134 if ($this->getActionId()) {
135 return false;
136 }
137
138 $this->setActionId($ilDB->nextId('didactic_tpl_a'));
139 $query = 'INSERT INTO didactic_tpl_a (id, tpl_id, type_id) ' .
140 'VALUES( ' .
141 $ilDB->quote($this->getActionId(), 'integer') . ', ' .
142 $ilDB->quote($this->getTemplateId(), 'integer') . ', ' .
143 $ilDB->quote($this->getType(), 'integer') .
144 ')';
145 $ilDB->manipulate($query);
146 return $this->getActionId();
147 }
148
155 public function delete()
156 {
157 global $DIC;
158
159 $ilDB = $DIC['ilDB'];
160
161 $query = 'DELETE FROM didactic_tpl_a ' .
162 'WHERE id = ' . $ilDB->quote($this->getActionId(), 'integer');
163 $ilDB->manipulate($query);
164 }
165
170 public function read()
171 {
172 global $DIC;
173
174 $ilDB = $DIC['ilDB'];
175
176 $query = 'SELECT * FROM didactic_tpl_a ' .
177 'WHERE id = ' . $ilDB->quote($this->getActionId(), 'integer');
178 $res = $ilDB->query($query);
179 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
180 $this->setTemplateId($row->tpl_id);
181 }
182 return true;
183 }
184
189 abstract public function getType();
190
196 abstract public function apply();
197
203 abstract public function revert();
204
205
209 public function __clone()
210 {
211 $this->setActionId(0);
212 }
213
214
218 abstract public function toXml(ilXmlWriter $writer);
219
220
226 protected function initSourceObject()
227 {
228 include_once './Services/Object/classes/class.ilObjectFactory.php';
230 return $s;
231 }
232
237 protected function filterRoles(ilObject $source)
238 {
239 global $DIC;
240
241 $rbacreview = $DIC['rbacreview'];
242
243 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
245 $this->getActionId(),
246 self::PATTERN_PARENT_TYPE
247 );
248
249 $filtered = array();
250 foreach ($rbacreview->getParentRoleIds($source->getRefId()) as $role_id => $role) {
251 switch ($this->getFilterType()) {
253
254 ilLoggerFactory::getLogger('dtpl')->dump($role);
255 if (
256 ($role['parent'] == $source->getRefId()) &&
257 ($role['assign'] == 'y')
258 ) {
259 ilLoggerFactory::getLogger('dtpl')->debug('Excluding local role: ' . $role['title']);
260 break;
261 }
262 foreach ($patterns as $pattern) {
263 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
264 ilLoggerFactory::getLogger('otpl')->debug('Role is valid: ' . ilObject::_lookupTitle($role_id));
265 $filtered[$role_id] = $role;
266 }
267 }
268 break;
269
271
272 if (
273 $role['parent'] != $source->getRefId() ||
274 $role['assign'] == 'n'
275 ) {
276 $this->logger->debug('Excluding non local role' . $role['title']);
277 break;
278 }
279 foreach ($patterns as $pattern) {
280 if ($pattern->valid(\ilObject::_lookupTitle($role_id))) {
281 $this->logger->debug('Role is valid ' . \ilObject::_lookupTitle($role_id));
282 $filtered[$role_id] = $role;
283 }
284 }
285 break;
286
287 default:
289 foreach ($patterns as $pattern) {
290 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
291 ilLoggerFactory::getLogger('otpl')->debug('Role is valid: ' . ilObject::_lookupTitle($role_id));
292 $filtered[$role_id] = $role;
293 }
294 }
295 break;
296 }
297 }
298 return $filtered;
299 }
300}
$source
Definition: linkback.php:22
An exception for terminatinating execution or to throw for unit testing.
Abstract class for template actions.
setRefId($a_ref_id)
Set ref id of target object.
__construct($action_id=0)
Constructor.
apply()
Apply action.
revert()
Implement everthing that is necessary to revert a didactic template.
toXml(ilXmlWriter $writer)
Write xml for export.
getType()
Get type of template.
initSourceObject()
Init the source object.
filterRoles(ilObject $source)
Filter roles.
setActionId($a_action_id)
Set action id.
getRefId()
Get ref id of target object.
save()
write action to db overwrite for filling additional db fields
static lookupPatternsByParentId($a_parent_id, $a_parent_type)
Get patterns by template id.
static getLogger($a_component_id)
Get component logger.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _lookupTitle($a_id)
lookup object title
XML writer class.
$row
$query
$s
Definition: pwgen.php:45
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB