ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
15 private $role_template_id = 0;
16
21 public function __construct($a_action_id = 0)
22 {
23 parent::__construct($a_action_id);
24 }
25
30 public function getType()
31 {
33 }
34
39 public function setRoleTemplateId($a_role_template_id)
40 {
41 $this->role_template_id = $a_role_template_id;
42 }
43
48 public function getRoleTemplateId()
49 {
51 }
52
56 public function apply()
57 {
58 global $rbacreview, $rbacadmin;
59
60 $source = $this->initSourceObject();
61
62 // Check if role folder already exists
63
64 // Create role
65
66 include_once './Services/AccessControl/classes/class.ilObjRole.php';
67 $role = new ilObjRole();
68 $role->setTitle(ilObject::_lookupTitle($this->getRoleTemplateId()));
69 $role->setDescription(ilObject::_lookupDescription($this->getRoleTemplateId()));
70 $role->create();
71 $rbacadmin->assignRoleToFolder($role->getId(),$source->getRefId(),"y");
72
73 $GLOBALS['ilLog']->write(__METHOD__.': Using rolt: '.$this->getRoleTemplateId().' with title "'.ilObject::_lookupTitle($this->getRoleTemplateId().'". '));
74
75 // Copy template permissions
76 $rbacadmin->copyRoleTemplatePermissions(
77 $this->getRoleTemplateId(),
78 ROLE_FOLDER_ID,
79 $source->getRefId(),
80 $role->getId(),
81 true
82 );
83
84 // Set permissions
85 $ops = $rbacreview->getOperationsOfRole($role->getId(),$source->getType(),$source->getRefId());
86 $rbacadmin->grantPermission($role->getId(),$ops,$source->getRefId());
87
88 return true;
89 }
90
94 public function revert()
95 {
96 // @todo: revert could delete the generated local role. But on the other hand all users
97 // assigned to this local role would be deassigned. E.g. if course or group membership
98 // is handled by didactic templates, all members would get lost.
99 }
100
104 public function save()
105 {
106 global $ilDB;
107
108 parent::save();
109
110 $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) '.
111 'VALUES ( '.
112 $ilDB->quote($this->getActionId(),'integer').', '.
113 $ilDB->quote($this->getRoleTemplateId(),'integer').' '.
114 ') ';
115 $res = $ilDB->manipulate($query);
116
117 return true;
118 }
119
125 public function delete()
126 {
127 global $ilDB;
128
129 parent::delete();
130
131 $query = 'DELETE FROM didactic_tpl_alr '.
132 'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
133 $ilDB->manipulate($query);
134
135 return true;
136 }
137
142 public function toXml(ilXmlWriter $writer)
143 {
144 $writer->xmlStartTag('localRoleAction');
145
146
147
148 $il_id = 'il_'.IL_INST_ID.'_'.ilObject::_lookupType($this->getRoleTemplateId()).'_'.$this->getRoleTemplateId();
149
150 $writer->xmlStartTag(
151 'roleTemplate',
152 array(
153 'id' => $il_id
154 )
155 );
156
157 include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
158 $exp = new ilRoleXmlExport();
159 $exp->setMode(ilRoleXmlExport::MODE_DTPL);
160 $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
161 $exp->write();
162 $writer->appendXML($exp->xmlDumpMem(FALSE));
163 $writer->xmlEndTag('roleTemplate');
164 $writer->xmlEndTag('localRoleAction');
165 }
166
172 public function read()
173 {
174 global $ilDB;
175
176 parent::read();
177
178 $query = 'SELECT * FROM didactic_tpl_alr '.
179 'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
180 $res = $ilDB->query($query);
181 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
182 {
183 $this->setRoleTemplateId($row->role_template_id);
184 }
185 return true;
186 }
187
188}
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
Abstract class for template actions.
initSourceObject()
Init the source 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.
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.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
appendXML($a_str)
append xml string to document
$GLOBALS['ct_recipient']
global $ilDB