ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDidacticTemplateBlockRoleAction.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateAction.php';
5 
13 {
16 
17  const PATTERN_PARENT_TYPE = 'action';
18 
19 
20  private $pattern = array();
22 
27  public function __construct($action_id = 0)
28  {
30  }
31 
37  {
38  $this->pattern[] = $pattern;
39  }
40 
45  public function setFilterPatterns(Array $patterns)
46  {
47  $this->pattern = $patterns;
48  }
49 
54  public function getFilterPattern()
55  {
56  return $this->pattern;
57  }
58 
63  public function setFilterType($a_type)
64  {
65  $this->filter_type = $a_type;
66  }
67 
72  public function getFilterType()
73  {
74  return $this->filter_type;
75  }
76 
80  public function save()
81  {
82  global $ilDB;
83 
84  parent::save();
85 
86  $query = 'INSERT INTO didactic_tpl_abr (action_id,filter_type) '.
87  'VALUES( '.
88  $ilDB->quote($this->getActionId(),'integer').', '.
89  $ilDB->quote($this->getFilterType(),'integer').' '.
90  ')';
91  $ilDB->manipulate($query);
92 
93  foreach($this->getFilterPattern() as $pattern)
94  {
95  /* @var ilDidacticTemplateFilterPattern $pattern */
96  $pattern->setParentId($this->getActionId());
97  $pattern->setParentType(self::PATTERN_PARENT_TYPE);
98  $pattern->save();
99  }
100  }
101 
107  public function delete()
108  {
109  global $ilDB;
110 
111  parent::delete();
112 
113  $query = 'DELETE FROM didactic_tpl_abr '.
114  'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
115  $ilDB->manipulate($query);
116 
117  foreach($this->getFilterPattern() as $pattern)
118  {
119  $pattern->delete();
120  }
121  return true;
122  }
123 
124 
125 
126 
130  public function apply()
131  {
132  $source = $this->initSourceObject();
133  $roles = $this->filterRoles($source);
134 
135  // Create local policy for filtered roles
136  foreach($roles as $role_id => $role)
137  {
138  $this->blockRole($role_id, $source);
139  }
140  return true;
141  }
142 
148  protected function blockRole($a_role_id, $source)
149  {
150  global $rbacadmin, $rbacreview;
151 
152  // Set assign to 'y' only if it is a local role
153  $assign = $rbacreview->isAssignable($a_role_id, $source->getRefId()) ? 'y' : 'n';
154 
155  // Delete permissions
156  $rbacadmin->revokeSubtreePermissions($source->getRefId(), $a_role_id);
157 
158  // Delete template permissions
159  $rbacadmin->deleteSubtreeTemplates($source->getRefId(), $a_role_id);
160 
161  $rbacadmin->assignRoleToFolder(
162  $a_role_id,
163  $source->getRefId(),
164  $assign
165  );
166  return true;
167  }
168 
172  public function revert()
173  {
174  $source = $this->initSourceObject();
175  $roles = $this->filterRoles($source);
176 
177  // Create local policy for filtered roles
178  foreach($roles as $role_id => $role)
179  {
180  $this->deleteLocalPolicy($role_id, $source);
181  }
182  return true;
183  }
184 
191  protected function deleteLocalPolicy($a_role_id, $source)
192  {
193  global $rbacreview, $rbacadmin;
194 
195  // Create role folder if it does not exist
196  //$rolf = $rbacreview->getRoleFolderIdOfObject($source->getRefId());
197 
198  if($rbacreview->getRoleFolderOfRole($a_role_id) == $source->getRefId())
199  {
200  $GLOBALS['ilLog']->write(__METHOD__.': Ignoring local role: '.ilObject::_lookupTitle($a_role_id));
201  return false;
202  }
203 
204  $rbacadmin->deleteLocalRole($a_role_id, $source->getRefId());
205 
206  // Change existing object
207  include_once './Services/AccessControl/classes/class.ilObjRole.php';
208  $role = new ilObjRole($a_role_id);
209  $role->changeExistingObjects(
210  $source->getRefId(),
212  array('all')
213  );
214 
215  return true;
216  }
217 
218 
223  public function getType()
224  {
225  return self::TYPE_BLOCK_ROLE;
226  }
227 
233  public function toXml(ilXmlWriter $writer)
234  {
235  $writer->xmlStartTag('blockRoleAction');
236 
237  switch($this->getFilterType())
238  {
239  case self::FILTER_SOURCE_OBJ_ID:
240  $writer->xmlStartTag('roleFilter',array('source' => 'objId'));
241  break;
242 
243  default:
244  case self::FILTER_SOURCE_TITLE:
245  $writer->xmlStartTag('roleFilter',array('source' => 'title'));
246  break;
247  }
248 
249  foreach($this->getFilterPattern() as $pattern)
250  {
251  $pattern->toXml($writer);
252  }
253  $writer->xmlEndTag('roleFilter');
254  $writer->xmlEndTag('blockRoleAction');
255  return;
256  }
257 
261  public function __clone()
262  {
263  parent::__clone();
264 
265  // Clone patterns
266  $cloned = array();
267  foreach($this->getFilterPattern() as $pattern)
268  {
269  $clones[] = clone $pattern;
270  }
271  $this->setFilterPatterns($clones);
272  }
273 
279  public function read()
280  {
281  global $ilDB;
282 
283  if(!parent::read())
284  {
285  return false;
286  }
287 
288  $query = 'SELECT * FROM didactic_tpl_abr '.
289  'WHERE action_id = '.$ilDB->quote($this->getActionId());
290  $res = $ilDB->query($query);
291  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
292  {
293  $this->setFilterType($row->filter_type);
294  }
295 
296  // Read filter
297  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
298  foreach(ilDidacticTemplateFilterPatternFactory::lookupPatternsByParentId($this->getActionId(),self::PATTERN_PARENT_TYPE) as $pattern)
299  {
300  $this->addFilterPattern($pattern);
301  }
302  }
303 }
304 ?>