ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
12  const TYPE_LOCAL_POLICY = 1;
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  {
131  return false;
132  }
133 
134  $this->setActionId($ilDB->nextId('didactic_tpl_a'));
135  $query = 'INSERT INTO didactic_tpl_a (id, tpl_id, type_id) '.
136  'VALUES( '.
137  $ilDB->quote($this->getActionId(),'integer').', '.
138  $ilDB->quote($this->getTemplateId(),'integer').', '.
139  $ilDB->quote($this->getType(),'integer').
140  ')';
141  $ilDB->manipulate($query);
142  return $this->getActionId();
143  }
144 
151  public function delete()
152  {
153  global $ilDB;
154 
155  $query = 'DELETE FROM didactic_tpl_a '.
156  'WHERE id = '.$ilDB->quote($this->getActionId(),'integer');
157  $ilDB->manipulate($query);
158  }
159 
164  public function read()
165  {
166  global $ilDB;
167 
168  $query = 'SELECT * FROM didactic_tpl_a '.
169  'WHERE id = '.$ilDB->quote($this->getActionId(), 'integer');
170  $res = $ilDB->query($query);
171  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
172  {
173  $this->setTemplateId($row->tpl_id);
174  }
175  return true;
176  }
177 
182  abstract public function getType();
183 
189  abstract public function apply();
190 
196  abstract public function revert();
197 
198 
202  public function __clone()
203  {
204  $this->setActionId(0);
205  }
206 
207 
211  abstract function toXml(ilXmlWriter $writer);
212 
213 
219  protected function initSourceObject()
220  {
221  include_once './Services/Object/classes/class.ilObjectFactory.php';
222  $s = ilObjectFactory::getInstanceByRefId($this->getRefId(),false);
223  return $s;
224  }
225 
230  protected function filterRoles(ilObject $source)
231  {
232  global $rbacreview;
233 
234  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
236  $this->getActionId(),
237  self::PATTERN_PARENT_TYPE
238  );
239 
240  $filtered = array();
241  foreach($rbacreview->getParentRoleIds($source->getRefId()) as $role_id => $role)
242  {
243  switch($this->getFilterType())
244  {
245  case self::FILTER_PARENT_ROLES:
246 
247  ilLoggerFactory::getLogger('dtpl')->dump($role);
248  if(
249  ($role['parent'] == $source->getRefId()) &&
250  ($role['assign'] == 'y')
251  )
252  {
253  ilLoggerFactory::getLogger('dtpl')->debug('Excluding local role: ' . $role['title']);
254  break;
255  }
256  foreach($patterns as $pattern)
257  {
258  if($pattern->valid(ilObject::_lookupTitle($role_id)))
259  {
260  ilLoggerFactory::getLogger('otpl')->debug('Role is valid: '. ilObject::_lookupTitle($role_id));
261  $filtered[$role_id] = $role;
262  }
263  }
264  break;
265 
266  default:
267  case self::FILTER_SOURCE_TITLE:
268  foreach($patterns as $pattern)
269  {
270  if($pattern->valid(ilObject::_lookupTitle($role_id)))
271  {
272  ilLoggerFactory::getLogger('otpl')->debug('Role is valid: '. ilObject::_lookupTitle($role_id));
273  $filtered[$role_id] = $role;
274  }
275  }
276  break;
277  }
278 
279 
280  }
281  return $filtered;
282  }
283 }
284 ?>
static lookupPatternsByParentId($a_parent_id, $a_parent_type)
Get patterns by template id.
save()
write action to db overwrite for filling additional db fields
Class ilObject Basic functions for all objects.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
XML writer class.
static _lookupTitle($a_id)
lookup object title
__construct($action_id=0)
Constructor.
filterRoles(ilObject $source)
Filter roles.
getType()
Get type of template.
getRefId()
Get ref id of target object.
setRefId($a_ref_id)
Set ref id of target object.
Create styles array
The data for the language used.
initSourceObject()
Init the source object.
apply()
Apply action.
Abstract class for template actions.
global $ilDB
getRefId()
get reference id public
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static getLogger($a_component_id)
Get component logger.
setActionId($a_action_id)
Set action id.
toXml(ilXmlWriter $writer)
Write xml for export.
revert()
Implement everthing that is necessary to revert a didactic template.