ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilDidacticTemplateLocalPolicyAction Class Reference

Description of class. More...

+ Inheritance diagram for ilDidacticTemplateLocalPolicyAction:
+ Collaboration diagram for ilDidacticTemplateLocalPolicyAction:

Public Member Functions

 __construct ($action_id=0)
 Constructor. More...
 
 addFilterPattern (ilDidacticTemplateFilterPattern $pattern)
 Add filter. More...
 
 setFilterPatterns (Array $patterns)
 Set filter patterns. More...
 
 getFilterPattern ()
 Get filter pattern. More...
 
 setFilterType ($a_type)
 Set filter type. More...
 
 getFilterType ()
 Get filter type. More...
 
 setRoleTemplateType ($a_tpl_type)
 Set Role template type. More...
 
 getRoleTemplateType ()
 Get role template type. More...
 
 setRoleTemplateId ($a_id)
 Set role template id. More...
 
 getRoleTemplateId ()
 Get role template id. More...
 
 save ()
 Save action. More...
 
 delete ()
 delete action filter @global ilDB $ilDB More...
 
 apply ()
 Apply action. More...
 
 revert ()
 Revert action. More...
 
 getType ()
 Get action type. More...
 
 toXml (ilXmlWriter $writer)
 Export to xml. More...
 
 __clone ()
 clone method More...
 
 read ()
 @global ilDB $ilDB More...
 
- Public Member Functions inherited from ilDidacticTemplateAction
 __construct ($action_id=0)
 Constructor. More...
 
 getActionId ()
 Get action id. More...
 
 setActionId ($a_action_id)
 Set action id. More...
 
 setType ($a_type_id)
 Set type id. More...
 
 setTemplateId ($a_id)
 Set template id. More...
 
 getTemplateId ()
 Get template id. More...
 
 setRefId ($a_ref_id)
 Set ref id of target object. More...
 
 getRefId ()
 Get ref id of target object. More...
 
 save ()
 write action to db overwrite for filling additional db fields More...
 
 delete ()
 Delete didactic template action overwrite for filling additional db fields. More...
 
 read ()
 @global ilDB $ilDB More...
 
 getType ()
 Get type of template. More...
 
 apply ()
 Apply action. More...
 
 revert ()
 Implement everthing that is necessary to revert a didactic template. More...
 
 __clone ()
 Clone method. More...
 
 toXml (ilXmlWriter $writer)
 Write xml for export. More...
 

Data Fields

const TPL_ACTION_OVERWRITE = 1
 
const TPL_ACTION_INTERSECT = 2
 
const TPL_ACTION_ADD = 3
 
const TPL_ACTION_SUBTRACT = 4
 
const TPL_ACTION_UNION = 5
 
- Data Fields inherited from ilDidacticTemplateAction
const TYPE_LOCAL_POLICY = 1
 
const TYPE_LOCAL_ROLE = 2
 
const TYPE_BLOCK_ROLE = 3
 
const FILTER_SOURCE_TITLE = 1
 
const FILTER_SOURCE_OBJ_ID = 2
 
const PATTERN_PARENT_TYPE = 'action'
 

Protected Member Functions

 createLocalPolicy (ilObject $source, $role)
 Create local policy. More...
 
 revertLocalPolicy (ilObject $source, $role)
 
- Protected Member Functions inherited from ilDidacticTemplateAction
 initSourceObject ()
 Init the source object. More...
 
 filterRoles (ilObject $source)
 Filter roles. More...
 

Private Attributes

 $pattern = array()
 
 $filter_type = self::FILTER_SOURCE_TITLE
 
 $role_template_type = self::TPL_ACTION_OVERWRITE
 
 $role_template_id = 0
 

Detailed Description

Description of class.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 12 of file class.ilDidacticTemplateLocalPolicyAction.php.

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateLocalPolicyAction::__construct (   $action_id = 0)

Constructor.

Parameters
int$action_id

Reimplemented from ilDidacticTemplateAction.

Definition at line 31 of file class.ilDidacticTemplateLocalPolicyAction.php.

32 {
33 parent::__construct($action_id);
34 }

References ilDidacticTemplateAction\$action_id.

Member Function Documentation

◆ __clone()

ilDidacticTemplateLocalPolicyAction::__clone ( )

clone method

Reimplemented from ilDidacticTemplateAction.

Definition at line 320 of file class.ilDidacticTemplateLocalPolicyAction.php.

321 {
322 parent::__clone();
323
324 // Clone patterns
325 $cloned = array();
326 foreach($this->getFilterPattern() as $pattern)
327 {
328 $clones[] = clone $pattern;
329 }
330 $this->setFilterPatterns($clones);
331 }

References $pattern, getFilterPattern(), and setFilterPatterns().

+ Here is the call graph for this function:

◆ addFilterPattern()

ilDidacticTemplateLocalPolicyAction::addFilterPattern ( ilDidacticTemplateFilterPattern  $pattern)

Add filter.

Parameters
ilDidacticTemplateFilterPatter$pattern

Definition at line 40 of file class.ilDidacticTemplateLocalPolicyAction.php.

41 {
42 $this->pattern[] = $pattern;
43 }

References $pattern.

Referenced by read().

+ Here is the caller graph for this function:

◆ apply()

ilDidacticTemplateLocalPolicyAction::apply ( )

Apply action.

Reimplemented from ilDidacticTemplateAction.

Definition at line 171 of file class.ilDidacticTemplateLocalPolicyAction.php.

172 {
173 global $rbacreview;
174
175 $source = $this->initSourceObject();
176 // Create a role folder for the new local policies
177
178 $roles = $this->filterRoles($source);
179
180 // Create local policy for filtered roles
181 foreach($roles as $role_id => $role)
182 {
183 // No local policies for protected roles of higher context
184 if($role['protected'] and $role['parent'] != $source->getRefId())
185 {
186 continue;
187 }
188 $this->createLocalPolicy($source,$role);
189 }
190 return true;
191 }
initSourceObject()
Init the source object.
filterRoles(ilObject $source)
Filter roles.
createLocalPolicy(ilObject $source, $role)
Create local policy.

References createLocalPolicy(), ilDidacticTemplateAction\filterRoles(), and ilDidacticTemplateAction\initSourceObject().

+ Here is the call graph for this function:

◆ createLocalPolicy()

ilDidacticTemplateLocalPolicyAction::createLocalPolicy ( ilObject  $source,
  $role 
)
protected

Create local policy.

Parameters
ilObject$source
array$role
Returns
bool

Definition at line 367 of file class.ilDidacticTemplateLocalPolicyAction.php.

368 {
369 global $rbacreview, $rbacadmin;
370
371 // Add local policy
372 if(!$rbacreview->isRoleAssignedToObject($role['obj_id'],$source->getRefId()))
373 {
374 $rbacadmin->assignRoleToFolder($role['obj_id'],$source->getRefId(),'n');
375 }
376
377 switch($this->getRoleTemplateType())
378 {
380
381 ilLoggerFactory::getLogger('otpl')->info('Using ilRbacAdmin::copyRolePermissionUnion()');
382 $rbacadmin->copyRolePermissionUnion(
383 $role['obj_id'],
384 $role['parent'],
385 $this->getRoleTemplateId(),
386 ROLE_FOLDER_ID,
387 $role['obj_id'],
388 $source->getRefId()
389 );
390 break;
391
393
394 ilLoggerFactory::getLogger('otpl')->info('Using ilRbacAdmin::copyRoleTemplatePermission()');
395 $rbacadmin->copyRoleTemplatePermissions(
396 $this->getRoleTemplateId(),
397 ROLE_FOLDER_ID,
398 $source->getRefId(),
399 $role['obj_id'],
400 true
401 );
402 break;
403
405
406 ilLoggerFactory::getLogger('otpl')->info('Using ilRbacAdmin::copyRolePermissionIntersection()');
407 $rbacadmin->copyRolePermissionIntersection(
408 $role['obj_id'],
409 $role['parent'],
410 $this->getRoleTemplateId(),
411 ROLE_FOLDER_ID,
412 $source->getRefId(),
413 $role['obj_id']
414 );
415 break;
416
417 }
418
419 // Change existing object
420 include_once './Services/AccessControl/classes/class.ilObjRole.php';
421 $role_obj = new ilObjRole($role['obj_id']);
422 $role_obj->changeExistingObjects(
423 $source->getRefId(),
425 array('all')
426 );
427
428 return true;
429 }
static getLogger($a_component_id)
Get component logger.
Class ilObjRole.
const MODE_PROTECTED_DELETE_LOCAL_POLICIES
const MODE_UNPROTECTED_DELETE_LOCAL_POLICIES
getRefId()
get reference id @access public

References ilLoggerFactory\getLogger(), ilObject\getRefId(), getRoleTemplateId(), getRoleTemplateType(), ilObjRole\MODE_PROTECTED_DELETE_LOCAL_POLICIES, ilObjRole\MODE_UNPROTECTED_DELETE_LOCAL_POLICIES, TPL_ACTION_INTERSECT, TPL_ACTION_OVERWRITE, and TPL_ACTION_UNION.

Referenced by apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilDidacticTemplateLocalPolicyAction::delete ( )

delete action filter @global ilDB $ilDB

Returns
bool

Reimplemented from ilDidacticTemplateAction.

Definition at line 148 of file class.ilDidacticTemplateLocalPolicyAction.php.

149 {
150 global $ilDB;
151
152 parent::delete();
153
154 $query = 'DELETE FROM didactic_tpl_alp '.
155 'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
156 $ilDB->manipulate($query);
157
158 foreach($this->getFilterPattern() as $pattern)
159 {
160 $pattern->delete();
161 }
162 return true;
163 }
global $ilDB

References $ilDB, $pattern, $query, ilDidacticTemplateAction\getActionId(), and getFilterPattern().

+ Here is the call graph for this function:

◆ getFilterPattern()

ilDidacticTemplateLocalPolicyAction::getFilterPattern ( )

Get filter pattern.

Returns
array

Definition at line 58 of file class.ilDidacticTemplateLocalPolicyAction.php.

59 {
60 return $this->pattern;
61 }

References $pattern.

Referenced by __clone(), delete(), save(), and toXml().

+ Here is the caller graph for this function:

◆ getFilterType()

ilDidacticTemplateLocalPolicyAction::getFilterType ( )

Get filter type.

Returns
int

Definition at line 76 of file class.ilDidacticTemplateLocalPolicyAction.php.

References $filter_type.

Referenced by save(), and toXml().

+ Here is the caller graph for this function:

◆ getRoleTemplateId()

ilDidacticTemplateLocalPolicyAction::getRoleTemplateId ( )

Get role template id.

Returns
int

Definition at line 111 of file class.ilDidacticTemplateLocalPolicyAction.php.

References $role_template_id.

Referenced by createLocalPolicy(), save(), and toXml().

+ Here is the caller graph for this function:

◆ getRoleTemplateType()

ilDidacticTemplateLocalPolicyAction::getRoleTemplateType ( )

Get role template type.

Definition at line 93 of file class.ilDidacticTemplateLocalPolicyAction.php.

References $role_template_type.

Referenced by createLocalPolicy(), save(), and toXml().

+ Here is the caller graph for this function:

◆ getType()

ilDidacticTemplateLocalPolicyAction::getType ( )

Get action type.

Returns
int

Reimplemented from ilDidacticTemplateAction.

Definition at line 239 of file class.ilDidacticTemplateLocalPolicyAction.php.

References ilDidacticTemplateAction\TYPE_LOCAL_POLICY.

◆ read()

ilDidacticTemplateLocalPolicyAction::read ( )

@global ilDB $ilDB

Reimplemented from ilDidacticTemplateAction.

Definition at line 333 of file class.ilDidacticTemplateLocalPolicyAction.php.

334 {
335 global $ilDB;
336
337 if(!parent::read())
338 {
339 return false;
340 }
341
342 $query = 'SELECT * FROM didactic_tpl_alp '.
343 'WHERE action_id = '.$ilDB->quote($this->getActionId());
344 $res = $ilDB->query($query);
345 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
346 {
347 $this->setFilterType($row->filter_type);
348 $this->setRoleTemplateType($row->template_type);
349 $this->setRoleTemplateId($row->template_id);
350 }
351
352 // Read filter
353 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateFilterPatternFactory.php';
355 {
356 $this->addFilterPattern($pattern);
357 }
358 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static lookupPatternsByParentId($a_parent_id, $a_parent_type)
Get patterns by template id.
addFilterPattern(ilDidacticTemplateFilterPattern $pattern)
Add filter.

References $ilDB, $pattern, $query, $res, $row, addFilterPattern(), DB_FETCHMODE_OBJECT, ilDidacticTemplateAction\getActionId(), ilDidacticTemplateFilterPatternFactory\lookupPatternsByParentId(), setFilterType(), setRoleTemplateId(), and setRoleTemplateType().

+ Here is the call graph for this function:

◆ revert()

ilDidacticTemplateLocalPolicyAction::revert ( )

Revert action.

@global ilRbacReview

Reimplemented from ilDidacticTemplateAction.

Definition at line 198 of file class.ilDidacticTemplateLocalPolicyAction.php.

199 {
200 global $rbacreview,$rbacadmin,$tree;
201
202 $source = $this->initSourceObject();
203 $roles = $this->filterRoles($source);
204
205 // Delete local policy for filtered roles
206 foreach($roles as $role_id => $role)
207 {
208 // Do not delete local roles of auto genrated roles
209 if(!$rbacreview->isGlobalRole($role['obj_id']) and
210 $rbacreview->isAssignable($role['obj_id'],$source->getRefId()) and
211 $rbacreview->isSystemGeneratedRole($role['obj_id']))
212 {
213 $this->revertLocalPolicy($source, $role);
214 }
215 else
216 {
217 // delete local role and change exiting objects
218 $rbacadmin->deleteLocalRole($role_id,$source->getRefId());
219 // Change existing object
220 include_once './Services/AccessControl/classes/class.ilObjRole.php';
221 $role_obj = new ilObjRole($role_id);
222 $role_obj->changeExistingObjects(
223 $source->getRefId(),
224 $role['protected'] ?
227 array('all')
228 );
229 }
230
231 }
232 return true;
233 }

References ilDidacticTemplateAction\filterRoles(), ilDidacticTemplateAction\initSourceObject(), ilObjRole\MODE_PROTECTED_DELETE_LOCAL_POLICIES, ilObjRole\MODE_UNPROTECTED_DELETE_LOCAL_POLICIES, and revertLocalPolicy().

+ Here is the call graph for this function:

◆ revertLocalPolicy()

ilDidacticTemplateLocalPolicyAction::revertLocalPolicy ( ilObject  $source,
  $role 
)
protected

Definition at line 431 of file class.ilDidacticTemplateLocalPolicyAction.php.

432 {
433 global $rbacadmin, $rbacreview, $ilDB;
434
435 ilLoggerFactory::getLogger('otpl')->info('Reverting policy for role '. $role['title']);
436 // Local policies can only be reverted for auto generated roles. Otherwise the
437 // original role settings are unknown
438 if(substr($role['title'],0,3) != 'il_')
439 {
440 ilLoggerFactory::getLogger('otpl')->warning('Cannot revert local policy for role '. $role['title']);
441 return false;
442 }
443
444
445 // No local policies
446 if(!$rbacreview->getLocalPolicies($source->getRefId()))
447 {
448 return false;
449 }
450
451 $exploded_title = explode('_',$role['title']);
452 $rolt_title = $exploded_title[0].'_'.$exploded_title[1].'_'.$exploded_title[2];
453
454 // Lookup role template
455 $query = 'SELECT obj_id FROM object_data '.
456 'WHERE title = '.$ilDB->quote($rolt_title,'text').' '.
457 'AND type = '.$ilDB->quote('rolt','text');
458 $res = $ilDB->query($query);
459 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
460 {
461 $rolt_id = $row->obj_id;
462 }
463
464 // No template found
465 if(!$rolt_id)
466 {
467 return false;
468 }
469
470 $rbacadmin->copyRoleTemplatePermissions(
471 $rolt_id,
472 ROLE_FOLDER_ID,
473 $source->getRefId(),
474 $role['obj_id'],
475 true
476 );
477
478 // Change existing object
479 include_once './Services/AccessControl/classes/class.ilObjRole.php';
480 $role_obj = new ilObjRole($role['obj_id']);
481 $role_obj->changeExistingObjects(
482 $source->getRefId(),
484 array('all')
485 );
486 }

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, ilLoggerFactory\getLogger(), ilObject\getRefId(), ilObjRole\MODE_PROTECTED_DELETE_LOCAL_POLICIES, and ilObjRole\MODE_UNPROTECTED_DELETE_LOCAL_POLICIES.

Referenced by revert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilDidacticTemplateLocalPolicyAction::save ( )

Save action.

Reimplemented from ilDidacticTemplateAction.

Definition at line 119 of file class.ilDidacticTemplateLocalPolicyAction.php.

120 {
121 global $ilDB;
122
123 parent::save();
124
125 $query = 'INSERT INTO didactic_tpl_alp (action_id,filter_type,template_type,template_id) '.
126 'VALUES( '.
127 $ilDB->quote($this->getActionId(),'integer').', '.
128 $ilDB->quote($this->getFilterType(),'integer').', '.
129 $ilDB->quote($this->getRoleTemplateType(),'integer').', '.
130 $ilDB->quote($this->getRoleTemplateId(),'integer').' '.
131 ')';
132 $ilDB->manipulate($query);
133
134 foreach($this->getFilterPattern() as $pattern)
135 {
136 /* @var ilDidacticTemplateFilterPattern $pattern */
137 $pattern->setParentId($this->getActionId());
138 $pattern->setParentType(self::PATTERN_PARENT_TYPE);
139 $pattern->save();
140 }
141 }

References $ilDB, $pattern, $query, ilDidacticTemplateAction\getActionId(), getFilterPattern(), getFilterType(), getRoleTemplateId(), and getRoleTemplateType().

+ Here is the call graph for this function:

◆ setFilterPatterns()

ilDidacticTemplateLocalPolicyAction::setFilterPatterns ( Array  $patterns)

Set filter patterns.

Parameters
array$patterns

Definition at line 49 of file class.ilDidacticTemplateLocalPolicyAction.php.

50 {
51 $this->pattern = $patterns;
52 }

Referenced by __clone().

+ Here is the caller graph for this function:

◆ setFilterType()

ilDidacticTemplateLocalPolicyAction::setFilterType (   $a_type)

Set filter type.

Parameters
int$a_type

Definition at line 67 of file class.ilDidacticTemplateLocalPolicyAction.php.

68 {
69 $this->filter_type = $a_type;
70 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setRoleTemplateId()

ilDidacticTemplateLocalPolicyAction::setRoleTemplateId (   $a_id)

Set role template id.

Parameters
int$a_id

Definition at line 102 of file class.ilDidacticTemplateLocalPolicyAction.php.

103 {
104 $this->role_template_id = $a_id;
105 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setRoleTemplateType()

ilDidacticTemplateLocalPolicyAction::setRoleTemplateType (   $a_tpl_type)

Set Role template type.

Parameters
int$a_tpl_type

Definition at line 85 of file class.ilDidacticTemplateLocalPolicyAction.php.

86 {
87 $this->role_template_type = $a_tpl_type;
88 }

Referenced by read().

+ Here is the caller graph for this function:

◆ toXml()

ilDidacticTemplateLocalPolicyAction::toXml ( ilXmlWriter  $writer)

Export to xml.

Parameters
ilXmlWriter$writer
Returns
void

Reimplemented from ilDidacticTemplateAction.

Definition at line 249 of file class.ilDidacticTemplateLocalPolicyAction.php.

250 {
251 $writer->xmlStartTag('localPolicyAction');
252
253 switch($this->getFilterType())
254 {
256 $writer->xmlStartTag('roleFilter',array('source' => 'title'));
257 break;
258
260 $writer->xmlStartTag('roleFilter',array('source' => 'objId'));
261 break;
262
263 }
264
265 foreach($this->getFilterPattern() as $pattern)
266 {
267 $pattern->toXml($writer);
268 }
269 $writer->xmlEndTag('roleFilter');
270
271 $il_role_id = 'il_'.IL_INST_ID.'_'.ilObject::_lookupType($this->getRoleTemplateId()).'_'.$this->getRoleTemplateId();
272
273 switch($this->getRoleTemplateType())
274 {
276 $writer->xmlStartTag(
277 'localPolicyTemplate',
278 array(
279 'type' => 'overwrite',
280 'id' => $il_role_id
281 )
282 );
283 break;
284
286 $writer->xmlStartTag(
287 'localPolicyTemplate',
288 array(
289 'type' => 'intersect',
290 'id' => $il_role_id
291 )
292 );
293 break;
294
296 $writer->xmlStartTag(
297 'localPolicyTemplate',
298 array(
299 'type' => 'union',
300 'id' => $il_role_id
301 )
302 );
303 break;
304 }
305
306 include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
307 $exp = new ilRoleXmlExport();
308 $exp->setMode(ilRoleXmlExport::MODE_DTPL);
309 $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
310 $exp->write();
311 $writer->appendXML($exp->xmlDumpMem(FALSE));
312 $writer->xmlEndTag('localPolicyTemplate');
313 $writer->xmlEndTag('localPolicyAction');
314 return void;
315 }
static _lookupType($a_id, $a_reference=false)
lookup object type
Xml export of roles and role templates.
xmlEndTag($tag)
Writes an endtag.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
appendXML($a_str)
append xml string to document

References $pattern, ilObject\_lookupType(), ilXmlWriter\appendXML(), ilDidacticTemplateAction\FILTER_SOURCE_OBJ_ID, ilDidacticTemplateAction\FILTER_SOURCE_TITLE, getFilterPattern(), getFilterType(), getRoleTemplateId(), getRoleTemplateType(), ilRoleXmlExport\MODE_DTPL, TPL_ACTION_INTERSECT, TPL_ACTION_OVERWRITE, TPL_ACTION_UNION, ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

+ Here is the call graph for this function:

Field Documentation

◆ $filter_type

ilDidacticTemplateLocalPolicyAction::$filter_type = self::FILTER_SOURCE_TITLE
private

Definition at line 22 of file class.ilDidacticTemplateLocalPolicyAction.php.

Referenced by getFilterType().

◆ $pattern

ilDidacticTemplateLocalPolicyAction::$pattern = array()
private

◆ $role_template_id

ilDidacticTemplateLocalPolicyAction::$role_template_id = 0
private

Definition at line 24 of file class.ilDidacticTemplateLocalPolicyAction.php.

Referenced by getRoleTemplateId().

◆ $role_template_type

ilDidacticTemplateLocalPolicyAction::$role_template_type = self::TPL_ACTION_OVERWRITE
private

Definition at line 23 of file class.ilDidacticTemplateLocalPolicyAction.php.

Referenced by getRoleTemplateType().

◆ TPL_ACTION_ADD

const ilDidacticTemplateLocalPolicyAction::TPL_ACTION_ADD = 3

◆ TPL_ACTION_INTERSECT

const ilDidacticTemplateLocalPolicyAction::TPL_ACTION_INTERSECT = 2

◆ TPL_ACTION_OVERWRITE

const ilDidacticTemplateLocalPolicyAction::TPL_ACTION_OVERWRITE = 1

◆ TPL_ACTION_SUBTRACT

const ilDidacticTemplateLocalPolicyAction::TPL_ACTION_SUBTRACT = 4

◆ TPL_ACTION_UNION

const ilDidacticTemplateLocalPolicyAction::TPL_ACTION_UNION = 5

The documentation for this class was generated from the following file: