ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
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 
4 include_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  {
31  return self::TYPE_LOCAL_ROLE;
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 $rbacreview, $rbacadmin;
58 
59  $source = $this->initSourceObject();
60 
61  // Check if role folder already exists
62 
63  // Create role
64 
65  include_once './Services/AccessControl/classes/class.ilObjRole.php';
66  $role = new ilObjRole();
67  $role->setTitle(ilObject::_lookupTitle($this->getRoleTemplateId()) . '_' . $this->getRefId());
68  $role->setDescription(ilObject::_lookupDescription($this->getRoleTemplateId()));
69  $role->create();
70  $rbacadmin->assignRoleToFolder($role->getId(), $source->getRefId(), "y");
71 
72  ilLoggerFactory::getLogger('otpl')->info('Using rolt: ' . $this->getRoleTemplateId() . ' with title "' . ilObject::_lookupTitle($this->getRoleTemplateId() . '". '));
73 
74  // Copy template permissions
75 
76  ilLoggerFactory::getLogger('otpl')->debug(
77  'Copy role template permissions ' .
78  'tpl_id: ' . $this->getRoleTemplateId() . ' ' .
79  'parent: ' . ROLE_FOLDER_ID . ' ' .
80  'role_id: ' . $role->getId() . ' ' .
81  'role_parent: ' . $source->getRefId()
82  );
83 
84 
85  $rbacadmin->copyRoleTemplatePermissions(
86  $this->getRoleTemplateId(),
87  ROLE_FOLDER_ID,
88  $source->getRefId(),
89  $role->getId(),
90  true
91  );
92 
93  // Set permissions
94  $ops = $rbacreview->getOperationsOfRole($role->getId(), $source->getType(), $source->getRefId());
95  $rbacadmin->grantPermission($role->getId(), $ops, $source->getRefId());
96 
97  return true;
98  }
99 
103  public function revert()
104  {
105  // @todo: revert could delete the generated local role. But on the other hand all users
106  // assigned to this local role would be deassigned. E.g. if course or group membership
107  // is handled by didactic templates, all members would get lost.
108  }
109 
113  public function save()
114  {
115  global $ilDB;
116 
117  parent::save();
118 
119  $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) ' .
120  'VALUES ( ' .
121  $ilDB->quote($this->getActionId(), 'integer') . ', ' .
122  $ilDB->quote($this->getRoleTemplateId(), 'integer') . ' ' .
123  ') ';
124  $res = $ilDB->manipulate($query);
125 
126  return true;
127  }
128 
134  public function delete()
135  {
136  global $ilDB;
137 
138  parent::delete();
139 
140  $query = 'DELETE FROM didactic_tpl_alr ' .
141  'WHERE action_id = ' . $ilDB->quote($this->getActionId(), 'integer');
142  $ilDB->manipulate($query);
143 
144  return true;
145  }
146 
151  public function toXml(ilXmlWriter $writer)
152  {
153  $writer->xmlStartTag('localRoleAction');
154 
155 
156  $il_id = 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->getRoleTemplateId()) . '_' . $this->getRoleTemplateId();
157 
158  $writer->xmlStartTag(
159  'roleTemplate',
160  array(
161  'id' => $il_id
162  )
163  );
164 
165  include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
166  $exp = new ilRoleXmlExport();
167  $exp->setMode(ilRoleXmlExport::MODE_DTPL);
168  $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
169  $exp->write();
170  $writer->appendXML($exp->xmlDumpMem(false));
171  $writer->xmlEndTag('roleTemplate');
172  $writer->xmlEndTag('localRoleAction');
173  }
174 
180  public function read()
181  {
182  global $ilDB;
183 
184  parent::read();
185 
186  $query = 'SELECT * FROM didactic_tpl_alr ' .
187  'WHERE action_id = ' . $ilDB->quote($this->getActionId(), 'integer');
188  $res = $ilDB->query($query);
189  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
190  $this->setRoleTemplateId($row->role_template_id);
191  }
192  return true;
193  }
194 }
Class ilObjRole.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
XML writer class.
static _lookupTitle($a_id)
lookup object title
xmlEndTag($tag)
Writes an endtag.
foreach($_POST as $key=> $value) $res
toXml(ilXmlWriter $writer)
Write xml of template action.
static _lookupDescription($a_id)
lookup object description
$query
getRefId()
Get ref id of target object.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
initSourceObject()
Init the source object.
setRoleTemplateId($a_role_template_id)
Set role template id.
represents a creation of local roles action
Abstract class for template actions.
Xml export of roles and role templates.
global $ilDB
appendXML($a_str)
append xml string to document
static getLogger($a_component_id)
Get component logger.
$source
Definition: linkback.php:22