ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
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  {
32  return self::TYPE_LOCAL_ROLE;
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()). '_' . $this->getRefId());
69  $role->setDescription(ilObject::_lookupDescription($this->getRoleTemplateId()));
70  $role->create();
71  $rbacadmin->assignRoleToFolder($role->getId(),$source->getRefId(),"y");
72 
73  ilLoggerFactory::getLogger('otpl')->info('Using rolt: '.$this->getRoleTemplateId().' with title "'.ilObject::_lookupTitle($this->getRoleTemplateId().'". '));
74 
75  // Copy template permissions
76 
77  ilLoggerFactory::getLogger('otpl')->debug(
78  'Copy role template permissions '.
79  'tpl_id: '.$this->getRoleTemplateId().' '.
80  'parent: '.ROLE_FOLDER_ID.' '.
81  'role_id: '.$role->getId().' '.
82  'role_parent: '.$source->getRefId()
83  );
84 
85 
86  $rbacadmin->copyRoleTemplatePermissions(
87  $this->getRoleTemplateId(),
88  ROLE_FOLDER_ID,
89  $source->getRefId(),
90  $role->getId(),
91  true
92  );
93 
94  // Set permissions
95  $ops = $rbacreview->getOperationsOfRole($role->getId(),$source->getType(),$source->getRefId());
96  $rbacadmin->grantPermission($role->getId(),$ops,$source->getRefId());
97 
98  return true;
99  }
100 
104  public function revert()
105  {
106  // @todo: revert could delete the generated local role. But on the other hand all users
107  // assigned to this local role would be deassigned. E.g. if course or group membership
108  // is handled by didactic templates, all members would get lost.
109  }
110 
114  public function save()
115  {
116  global $ilDB;
117 
118  parent::save();
119 
120  $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) '.
121  'VALUES ( '.
122  $ilDB->quote($this->getActionId(),'integer').', '.
123  $ilDB->quote($this->getRoleTemplateId(),'integer').' '.
124  ') ';
125  $res = $ilDB->manipulate($query);
126 
127  return true;
128  }
129 
135  public function delete()
136  {
137  global $ilDB;
138 
139  parent::delete();
140 
141  $query = 'DELETE FROM didactic_tpl_alr '.
142  'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
143  $ilDB->manipulate($query);
144 
145  return true;
146  }
147 
152  public function toXml(ilXmlWriter $writer)
153  {
154  $writer->xmlStartTag('localRoleAction');
155 
156 
157  $il_id = 'il_'.IL_INST_ID.'_'.ilObject::_lookupType($this->getRoleTemplateId()).'_'.$this->getRoleTemplateId();
158 
159  $writer->xmlStartTag(
160  'roleTemplate',
161  array(
162  'id' => $il_id
163  )
164  );
165 
166  include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
167  $exp = new ilRoleXmlExport();
168  $exp->setMode(ilRoleXmlExport::MODE_DTPL);
169  $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
170  $exp->write();
171  $writer->appendXML($exp->xmlDumpMem(FALSE));
172  $writer->xmlEndTag('roleTemplate');
173  $writer->xmlEndTag('localRoleAction');
174  }
175 
181  public function read()
182  {
183  global $ilDB;
184 
185  parent::read();
186 
187  $query = 'SELECT * FROM didactic_tpl_alr '.
188  'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
189  $res = $ilDB->query($query);
190  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
191  {
192  $this->setRoleTemplateId($row->role_template_id);
193  }
194  return true;
195  }
196 
197 }
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.
toXml(ilXmlWriter $writer)
Write xml of template action.
static _lookupDescription($a_id)
lookup object description
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.