ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDidacticTemplateLocalRoleAction.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateAction.php';
5
13{
14 private $role_template_id = 0;
15
20 public function __construct($a_action_id = 0)
21 {
22 parent::__construct($a_action_id);
23 }
24
29 public function getType()
30 {
32 }
33
38 public function setRoleTemplateId($a_role_template_id)
39 {
40 $this->role_template_id = $a_role_template_id;
41 }
42
47 public function getRoleTemplateId()
48 {
50 }
51
55 public function apply()
56 {
57 global $DIC;
58
59 $rbacreview = $DIC['rbacreview'];
60 $rbacadmin = $DIC['rbacadmin'];
61
62 $source = $this->initSourceObject();
63
64 // Check if role folder already exists
65
66 // Create role
67
68 include_once './Services/AccessControl/classes/class.ilObjRole.php';
69 $role = new ilObjRole();
70 $role->setTitle(ilObject::_lookupTitle($this->getRoleTemplateId()) . '_' . $this->getRefId());
71 $role->setDescription(ilObject::_lookupDescription($this->getRoleTemplateId()));
72 $role->create();
73 $rbacadmin->assignRoleToFolder($role->getId(), $source->getRefId(), "y");
74
75 ilLoggerFactory::getLogger('otpl')->info('Using rolt: ' . $this->getRoleTemplateId() . ' with title "' . ilObject::_lookupTitle($this->getRoleTemplateId() . '". '));
76
77 // Copy template permissions
78
79 ilLoggerFactory::getLogger('otpl')->debug(
80 'Copy role template permissions ' .
81 'tpl_id: ' . $this->getRoleTemplateId() . ' ' .
82 'parent: ' . ROLE_FOLDER_ID . ' ' .
83 'role_id: ' . $role->getId() . ' ' .
84 'role_parent: ' . $source->getRefId()
85 );
86
87
88 $rbacadmin->copyRoleTemplatePermissions(
89 $this->getRoleTemplateId(),
90 ROLE_FOLDER_ID,
91 $source->getRefId(),
92 $role->getId(),
93 true
94 );
95
96 // Set permissions
97 $ops = $rbacreview->getOperationsOfRole($role->getId(), $source->getType(), $source->getRefId());
98 $rbacadmin->grantPermission($role->getId(), $ops, $source->getRefId());
99
100 return true;
101 }
102
106 public function revert()
107 {
108 // @todo: revert could delete the generated local role. But on the other hand all users
109 // assigned to this local role would be deassigned. E.g. if course or group membership
110 // is handled by didactic templates, all members would get lost.
111 }
112
116 public function save()
117 {
118 global $DIC;
119
120 $ilDB = $DIC['ilDB'];
121
122 parent::save();
123
124 $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) ' .
125 'VALUES ( ' .
126 $ilDB->quote($this->getActionId(), 'integer') . ', ' .
127 $ilDB->quote($this->getRoleTemplateId(), 'integer') . ' ' .
128 ') ';
129 $res = $ilDB->manipulate($query);
130
131 return true;
132 }
133
139 public function delete()
140 {
141 global $DIC;
142
143 $ilDB = $DIC['ilDB'];
144
145 parent::delete();
146
147 $query = 'DELETE FROM didactic_tpl_alr ' .
148 'WHERE action_id = ' . $ilDB->quote($this->getActionId(), 'integer');
149 $ilDB->manipulate($query);
150
151 return true;
152 }
153
158 public function toXml(ilXmlWriter $writer)
159 {
160 $writer->xmlStartTag('localRoleAction');
161
162
163 $il_id = 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->getRoleTemplateId()) . '_' . $this->getRoleTemplateId();
164
165 $writer->xmlStartTag(
166 'roleTemplate',
167 array(
168 'id' => $il_id
169 )
170 );
171
172 include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
173 $exp = new ilRoleXmlExport();
174 $exp->setMode(ilRoleXmlExport::MODE_DTPL);
175 $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
176 $exp->write();
177 $writer->appendXML($exp->xmlDumpMem(false));
178 $writer->xmlEndTag('roleTemplate');
179 $writer->xmlEndTag('localRoleAction');
180 }
181
187 public function read()
188 {
189 global $DIC;
190
191 $ilDB = $DIC['ilDB'];
192
193 parent::read();
194
195 $query = 'SELECT * FROM didactic_tpl_alr ' .
196 'WHERE action_id = ' . $ilDB->quote($this->getActionId(), 'integer');
197 $res = $ilDB->query($query);
198 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199 $this->setRoleTemplateId($row->role_template_id);
200 }
201 return true;
202 }
203}
An exception for terminatinating execution or to throw for unit testing.
Abstract class for template actions.
initSourceObject()
Init the source object.
getRefId()
Get ref id of target object.
represents a creation of local roles action
setRoleTemplateId($a_role_template_id)
Set role template id.
toXml(ilXmlWriter $writer)
Write xml of template action.
static getLogger($a_component_id)
Get component logger.
Class ilObjRole.
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
static _lookupType($a_id, $a_reference=false)
lookup object type
Xml export of roles and role templates.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
appendXML($a_str)
append xml string to document
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
$source
Definition: metadata.php:76
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46