ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
19
20 const PATTERN_PARENT_TYPE = 'action';
21
25 private $logger = null;
26
27 private $action_id = 0;
28 private $tpl_id = 0;
29 private $type = 0;
30
31
32 private $ref_id = 0;
33
34
38 public function __construct($action_id = 0)
39 {
40 $this->logger = $GLOBALS['DIC']->logger()->otpl();
41
42 $this->setActionId($action_id);
43 $this->read();
44 }
45
50 public function getLogger()
51 {
52 return $this->logger;
53 }
54
59 public function getActionId()
60 {
61 return $this->action_id;
62 }
63
68 public function setActionId($a_action_id)
69 {
70 $this->action_id = $a_action_id;
71 }
72
78 public function setType($a_type_id)
79 {
80 $this->type = $a_type_id;
81 }
82
87 public function setTemplateId($a_id)
88 {
89 $this->tpl_id = $a_id;
90 }
91
96 public function getTemplateId()
97 {
98 return $this->tpl_id;
99 }
100
106 public function setRefId($a_ref_id)
107 {
108 $this->ref_id = $a_ref_id;
109 }
110
114 public function getRefId()
115 {
116 return $this->ref_id;
117 }
118
125 public function save()
126 {
127 global $ilDB;
128
129 if ($this->getActionId()) {
130 return false;
131 }
132
133 $this->setActionId($ilDB->nextId('didactic_tpl_a'));
134 $query = 'INSERT INTO didactic_tpl_a (id, tpl_id, type_id) ' .
135 'VALUES( ' .
136 $ilDB->quote($this->getActionId(), 'integer') . ', ' .
137 $ilDB->quote($this->getTemplateId(), 'integer') . ', ' .
138 $ilDB->quote($this->getType(), 'integer') .
139 ')';
140 $ilDB->manipulate($query);
141 return $this->getActionId();
142 }
143
150 public function delete()
151 {
152 global $ilDB;
153
154 $query = 'DELETE FROM didactic_tpl_a ' .
155 'WHERE id = ' . $ilDB->quote($this->getActionId(), 'integer');
156 $ilDB->manipulate($query);
157 }
158
163 public function read()
164 {
165 global $ilDB;
166
167 $query = 'SELECT * FROM didactic_tpl_a ' .
168 'WHERE id = ' . $ilDB->quote($this->getActionId(), 'integer');
169 $res = $ilDB->query($query);
170 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
171 $this->setTemplateId($row->tpl_id);
172 }
173 return true;
174 }
175
180 abstract public function getType();
181
187 abstract public function apply();
188
194 abstract public function revert();
195
196
200 public function __clone()
201 {
202 $this->setActionId(0);
203 }
204
205
209 abstract public function toXml(ilXmlWriter $writer);
210
211
217 protected function initSourceObject()
218 {
219 include_once './Services/Object/classes/class.ilObjectFactory.php';
221 return $s;
222 }
223
228 protected function filterRoles(ilObject $source)
229 {
230 global $rbacreview;
231
232 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
234 $this->getActionId(),
235 self::PATTERN_PARENT_TYPE
236 );
237
238 $filtered = array();
239 foreach ($rbacreview->getParentRoleIds($source->getRefId()) as $role_id => $role) {
240 switch ($this->getFilterType()) {
242
243 ilLoggerFactory::getLogger('dtpl')->dump($role);
244 if (
245 ($role['parent'] == $source->getRefId()) &&
246 ($role['assign'] == 'y')
247 ) {
248 ilLoggerFactory::getLogger('dtpl')->debug('Excluding local role: ' . $role['title']);
249 break;
250 }
251 foreach ($patterns as $pattern) {
252 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
253 ilLoggerFactory::getLogger('otpl')->debug('Role is valid: ' . ilObject::_lookupTitle($role_id));
254 $filtered[$role_id] = $role;
255 }
256 }
257 break;
258
259 default:
261 foreach ($patterns as $pattern) {
262 if ($pattern->valid(ilObject::_lookupTitle($role_id))) {
263 ilLoggerFactory::getLogger('otpl')->debug('Role is valid: ' . ilObject::_lookupTitle($role_id));
264 $filtered[$role_id] = $role;
265 }
266 }
267 break;
268 }
269 }
270 return $filtered;
271 }
272}
$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.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$query
$s
Definition: pwgen.php:45
foreach($_POST as $key=> $value) $res
global $ilDB