ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
17 
18  const PATTERN_PARENT_TYPE = 'action';
19 
20 
21  private $pattern = array();
22  private $filter_type = self::FILTER_SOURCE_TITLE;
23 
28  public function __construct($action_id = 0)
29  {
30  parent::__construct($action_id);
31  }
32 
38  {
39  $this->pattern[] = $pattern;
40  }
41 
46  public function setFilterPatterns(array $patterns)
47  {
48  $this->pattern = $patterns;
49  }
50 
55  public function getFilterPattern()
56  {
57  return $this->pattern;
58  }
59 
64  public function setFilterType($a_type)
65  {
66  $this->filter_type = $a_type;
67  }
68 
73  public function getFilterType()
74  {
75  return $this->filter_type;
76  }
77 
81  public function save()
82  {
83  global $ilDB;
84 
85  parent::save();
86 
87  $query = 'INSERT INTO didactic_tpl_abr (action_id,filter_type) ' .
88  'VALUES( ' .
89  $ilDB->quote($this->getActionId(), 'integer') . ', ' .
90  $ilDB->quote($this->getFilterType(), 'integer') . ' ' .
91  ')';
92  $ilDB->manipulate($query);
93 
94  foreach ($this->getFilterPattern() as $pattern) {
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  $pattern->delete();
119  }
120  return true;
121  }
122 
123 
124 
125 
129  public function apply()
130  {
131  $source = $this->initSourceObject();
132  $roles = $this->filterRoles($source);
133 
134  // Create local policy for filtered roles
135  foreach ($roles as $role_id => $role) {
136  $this->blockRole($role_id, $source);
137  }
138  return true;
139  }
140 
146  protected function blockRole($a_role_id, $source)
147  {
148  global $rbacadmin, $rbacreview;
149 
150  // Set assign to 'y' only if it is a local role
151  $assign = $rbacreview->isAssignable($a_role_id, $source->getRefId()) ? 'y' : 'n';
152 
153  // Delete permissions
154  $rbacadmin->revokeSubtreePermissions($source->getRefId(), $a_role_id);
155 
156  // Delete template permissions
157  $rbacadmin->deleteSubtreeTemplates($source->getRefId(), $a_role_id);
158 
159  $rbacadmin->assignRoleToFolder(
160  $a_role_id,
161  $source->getRefId(),
162  $assign
163  );
164  return true;
165  }
166 
170  public function revert()
171  {
172  $source = $this->initSourceObject();
173  $roles = $this->filterRoles($source);
174 
175  // Create local policy for filtered roles
176  foreach ($roles as $role_id => $role) {
177  $this->deleteLocalPolicy($role_id, $source);
178  }
179  return true;
180  }
181 
188  protected function deleteLocalPolicy($a_role_id, $source)
189  {
190  global $rbacreview, $rbacadmin;
191 
192  // Create role folder if it does not exist
193  //$rolf = $rbacreview->getRoleFolderIdOfObject($source->getRefId());
194 
195  if ($rbacreview->getRoleFolderOfRole($a_role_id) == $source->getRefId()) {
196  ilLoggerFactory::getLogger('otpl')->debug('Ignoring local role: ' . ilObject::_lookupTitle($a_role_id));
197  return false;
198  }
199 
200  $rbacadmin->deleteLocalRole($a_role_id, $source->getRefId());
201 
202  // Change existing object
203  include_once './Services/AccessControl/classes/class.ilObjRole.php';
204  $role = new ilObjRole($a_role_id);
205  $role->changeExistingObjects(
206  $source->getRefId(),
208  array('all')
209  );
210 
211  return true;
212  }
213 
214 
219  public function getType()
220  {
221  return self::TYPE_BLOCK_ROLE;
222  }
223 
229  public function toXml(ilXmlWriter $writer)
230  {
231  $writer->xmlStartTag('blockRoleAction');
232 
233  switch ($this->getFilterType()) {
234  case self::FILTER_SOURCE_OBJ_ID:
235  $writer->xmlStartTag('roleFilter', array('source' => 'objId'));
236  break;
237 
238  default:
239  case self::FILTER_SOURCE_TITLE:
240  $writer->xmlStartTag('roleFilter', array('source' => 'title'));
241  break;
242  }
243 
244  foreach ($this->getFilterPattern() as $pattern) {
245  $pattern->toXml($writer);
246  }
247  $writer->xmlEndTag('roleFilter');
248  $writer->xmlEndTag('blockRoleAction');
249  return;
250  }
251 
255  public function __clone()
256  {
257  parent::__clone();
258 
259  // Clone patterns
260  $cloned = array();
261  foreach ($this->getFilterPattern() as $pattern) {
262  $clones[] = clone $pattern;
263  }
264  $this->setFilterPatterns($clones);
265  }
266 
272  public function read()
273  {
274  global $ilDB;
275 
276  if (!parent::read()) {
277  return false;
278  }
279 
280  $query = 'SELECT * FROM didactic_tpl_abr ' .
281  'WHERE action_id = ' . $ilDB->quote($this->getActionId());
282  $res = $ilDB->query($query);
283  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
284  $this->setFilterType($row->filter_type);
285  }
286 
287  // Read filter
288  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
289  foreach (ilDidacticTemplateFilterPatternFactory::lookupPatternsByParentId($this->getActionId(), self::PATTERN_PARENT_TYPE) as $pattern) {
290  $this->addFilterPattern($pattern);
291  }
292  }
293 }
Class ilObjRole.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
Description of ilDidacticTemplateBlockRoleAction.
static lookupPatternsByParentId($a_parent_id, $a_parent_type)
Get patterns by template id.
addFilterPattern(ilDidacticTemplateFilterPattern $pattern)
Add filter.
setFilterPatterns(array $patterns)
Set filter patterns.
XML writer class.
static _lookupTitle($a_id)
lookup object title
xmlEndTag($tag)
Writes an endtag.
deleteLocalPolicy($a_role_id, $source)
Delete local policy.
filterRoles(ilObject $source)
Filter roles.
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
initSourceObject()
Init the source object.
Abstract class for template actions.
const MODE_UNPROTECTED_DELETE_LOCAL_POLICIES
global $ilDB
static getLogger($a_component_id)
Get component logger.
$source
Definition: linkback.php:22
Represents a filter pattern for didactic template actions.