ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
18 
19  const PATTERN_PARENT_TYPE = 'action';
20 
21  private $action_id = 0;
22  private $tpl_id = 0;
23  private $type = 0;
24 
25 
26  private $ref_id = 0;
27 
28 
32  public function __construct($action_id = 0)
33  {
34  $this->setActionId($action_id);
35  $this->read();
36  }
37 
42  public function getActionId()
43  {
44  return $this->action_id;
45  }
46 
51  public function setActionId($a_action_id)
52  {
53  $this->action_id = $a_action_id;
54  }
55 
61  public function setType($a_type_id)
62  {
63  $this->type = $a_type_id;
64  }
65 
70  public function setTemplateId($a_id)
71  {
72  $this->tpl_id = $a_id;
73  }
74 
79  public function getTemplateId()
80  {
81  return $this->tpl_id;
82  }
83 
89  public function setRefId($a_ref_id)
90  {
91  $this->ref_id = $a_ref_id;
92  }
93 
97  public function getRefId()
98  {
99  return $this->ref_id;
100  }
101 
108  public function save()
109  {
110  global $ilDB;
111 
112  if($this->getActionId())
113  {
114  return false;
115  }
116 
117  $this->setActionId($ilDB->nextId('didactic_tpl_a'));
118  $query = 'INSERT INTO didactic_tpl_a (id, tpl_id, type_id) '.
119  'VALUES( '.
120  $ilDB->quote($this->getActionId(),'integer').', '.
121  $ilDB->quote($this->getTemplateId(),'integer').', '.
122  $ilDB->quote($this->getType(),'integer').
123  ')';
124  $ilDB->manipulate($query);
125  return $this->getActionId();
126  }
127 
134  public function delete()
135  {
136  global $ilDB;
137 
138  $query = 'DELETE FROM didactic_tpl_a '.
139  'WHERE id = '.$ilDB->quote($this->getActionId(),'integer');
140  $ilDB->manipulate($query);
141  }
142 
147  public function read()
148  {
149  global $ilDB;
150 
151  $query = 'SELECT * FROM didactic_tpl_a '.
152  'WHERE id = '.$ilDB->quote($this->getActionId(), 'integer');
153  $res = $ilDB->query($query);
154  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
155  {
156  $this->setTemplateId($row->tpl_id);
157  }
158  return true;
159  }
160 
165  abstract public function getType();
166 
172  abstract public function apply();
173 
179  abstract public function revert();
180 
181 
185  public function __clone()
186  {
187  $this->setActionId(0);
188  }
189 
190 
194  abstract function toXml(ilXmlWriter $writer);
195 
196 
202  protected function initSourceObject()
203  {
204  include_once './Services/Object/classes/class.ilObjectFactory.php';
205  $s = ilObjectFactory::getInstanceByRefId($this->getRefId(),false);
206  return $s;
207  }
208 
213  protected function filterRoles(ilObject $source)
214  {
215  global $rbacreview;
216 
217  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
219  $this->getActionId(),
220  self::PATTERN_PARENT_TYPE
221  );
222 
223  $filtered = array();
224  foreach($rbacreview->getParentRoleIds($source->getRefId()) as $role_id => $role)
225  {
226  foreach($patterns as $pattern)
227  {
228  if($pattern->valid(ilObject::_lookupTitle($role_id)))
229  {
230  $GLOBALS['ilLog']->write(__METHOD__.' Role is valid: '. ilObject::_lookupTitle($role_id));
231  $filtered[$role_id] = $role;
232  }
233  }
234  }
235  return $filtered;
236  }
237 }
238 ?>