ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
84 
85  $ilDB = $DIC['ilDB'];
86 
87  parent::save();
88 
89  $query = 'INSERT INTO didactic_tpl_abr (action_id,filter_type) ' .
90  'VALUES( ' .
91  $ilDB->quote($this->getActionId(), 'integer') . ', ' .
92  $ilDB->quote($this->getFilterType(), 'integer') . ' ' .
93  ')';
94  $ilDB->manipulate($query);
95 
96  foreach ($this->getFilterPattern() as $pattern) {
97  /* @var ilDidacticTemplateFilterPattern $pattern */
98  $pattern->setParentId($this->getActionId());
99  $pattern->setParentType(self::PATTERN_PARENT_TYPE);
100  $pattern->save();
101  }
102  }
103 
109  public function delete()
110  {
111  global $DIC;
112 
113  $ilDB = $DIC['ilDB'];
114 
115  parent::delete();
116 
117  $query = 'DELETE FROM didactic_tpl_abr ' .
118  'WHERE action_id = ' . $ilDB->quote($this->getActionId(), 'integer');
119  $ilDB->manipulate($query);
120 
121  foreach ($this->getFilterPattern() as $pattern) {
122  $pattern->delete();
123  }
124  return true;
125  }
126 
127 
128 
129 
133  public function apply()
134  {
135  $source = $this->initSourceObject();
136  $roles = $this->filterRoles($source);
137 
138  // Create local policy for filtered roles
139  foreach ($roles as $role_id => $role) {
140  $this->blockRole($role_id, $source);
141  }
142  return true;
143  }
144 
150  protected function blockRole($a_role_id, $source)
151  {
152  global $DIC;
153 
154  $rbacadmin = $DIC['rbacadmin'];
155  $rbacreview = $DIC['rbacreview'];
156 
157  // Set assign to 'y' only if it is a local role
158  $assign = $rbacreview->isAssignable($a_role_id, $source->getRefId()) ? 'y' : 'n';
159 
160  // Delete permissions
161  $rbacadmin->revokeSubtreePermissions($source->getRefId(), $a_role_id);
162 
163  // Delete template permissions
164  $rbacadmin->deleteSubtreeTemplates($source->getRefId(), $a_role_id);
165 
166  $rbacadmin->assignRoleToFolder(
167  $a_role_id,
168  $source->getRefId(),
169  $assign
170  );
171  return true;
172  }
173 
177  public function revert()
178  {
179  $source = $this->initSourceObject();
180  $roles = $this->filterRoles($source);
181 
182  // Create local policy for filtered roles
183  foreach ($roles as $role_id => $role) {
184  $this->deleteLocalPolicy($role_id, $source);
185  }
186  return true;
187  }
188 
195  protected function deleteLocalPolicy($a_role_id, $source)
196  {
197  global $DIC;
198 
199  $rbacreview = $DIC['rbacreview'];
200  $rbacadmin = $DIC['rbacadmin'];
201 
202  // Create role folder if it does not exist
203  //$rolf = $rbacreview->getRoleFolderIdOfObject($source->getRefId());
204 
205  if ($rbacreview->getRoleFolderOfRole($a_role_id) == $source->getRefId()) {
206  ilLoggerFactory::getLogger('otpl')->debug('Ignoring local role: ' . ilObject::_lookupTitle($a_role_id));
207  return false;
208  }
209 
210  $rbacadmin->deleteLocalRole($a_role_id, $source->getRefId());
211 
212  // Change existing object
213  include_once './Services/AccessControl/classes/class.ilObjRole.php';
214  $role = new ilObjRole($a_role_id);
215  $role->changeExistingObjects(
216  $source->getRefId(),
218  array('all')
219  );
220 
221  return true;
222  }
223 
224 
229  public function getType()
230  {
231  return self::TYPE_BLOCK_ROLE;
232  }
233 
239  public function toXml(ilXmlWriter $writer)
240  {
241  $writer->xmlStartTag('blockRoleAction');
242 
243  switch ($this->getFilterType()) {
244  case self::FILTER_SOURCE_OBJ_ID:
245  $writer->xmlStartTag('roleFilter', ['source' => 'objId']);
246  break;
247 
248  case self::FILTER_SOURCE_TITLE:
249  $writer->xmlStartTag('roleFilter', ['source' => 'title']);
250  break;
251 
252  case self::FILTER_PARENT_ROLES:
253  $writer->xmlStartTag('roleFilter', ['source' => 'parentRoles']);
254  break;
255 
256  default:
257  $writer->xmlStartTag('roleFilter', ['source' => 'title']);
258  break;
259 
260  }
261 
262  foreach ($this->getFilterPattern() as $pattern) {
263  $pattern->toXml($writer);
264  }
265  $writer->xmlEndTag('roleFilter');
266  $writer->xmlEndTag('blockRoleAction');
267  return;
268  }
269 
273  public function __clone()
274  {
275  parent::__clone();
276 
277  // Clone patterns
278  $cloned = array();
279  foreach ($this->getFilterPattern() as $pattern) {
280  $clones[] = clone $pattern;
281  }
282  $this->setFilterPatterns($clones);
283  }
284 
290  public function read()
291  {
292  global $DIC;
293 
294  $ilDB = $DIC['ilDB'];
295 
296  if (!parent::read()) {
297  return false;
298  }
299 
300  $query = 'SELECT * FROM didactic_tpl_abr ' .
301  'WHERE action_id = ' . $ilDB->quote($this->getActionId());
302  $res = $ilDB->query($query);
303  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
304  $this->setFilterType($row->filter_type);
305  }
306 
307  // Read filter
308  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
309  foreach (ilDidacticTemplateFilterPatternFactory::lookupPatternsByParentId($this->getActionId(), self::PATTERN_PARENT_TYPE) as $pattern) {
310  $this->addFilterPattern($pattern);
311  }
312  }
313 }
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.
global $DIC
Definition: saml.php:7
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
initSourceObject()
Init the source object.
$row
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.