ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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 
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  $rolf_id = $rbacreview->getRoleFolderIdOfObject($source->getRefId());
64  if(!$rolf_id)
65  {
66  $source->createRoleFolder();
67  }
68  $rolf_id = $rbacreview->getRoleFolderIdOfObject($source->getRefId());
69 
70  $GLOBALS['ilLog']->write(__METHOD__.': Current role folder id is: '.$rolf_id);
71 
72  // Create role
73  $rolf = ilObjectFactory::getInstanceByRefId($rolf_id,false);
74  $role = $rolf->createRole(
77  );
78 
79  $GLOBALS['ilLog']->write(__METHOD__.': Using rolt: '.$this->getRoleTemplateId().' with title "'.ilObject::_lookupTitle($this->getRoleTemplateId().'". '));
80 
81  // Copy template permissions
82  $rbacadmin->copyRoleTemplatePermissions(
83  $this->getRoleTemplateId(),
84  ROLE_FOLDER_ID,
85  $rolf->getRefId(),
86  $role->getId(),
87  true
88  );
89 
90  // Set permissions
91  $ops = $rbacreview->getOperationsOfRole($role->getId(),$source->getType(),$rolf->getRefId());
92  $rbacadmin->grantPermission($role->getId(),$ops,$source->getRefId());
93 
94  return true;
95  }
96 
100  public function revert()
101  {
102  // @todo: revert could delete the generated local role. But on the other hand all users
103  // assigned to this local role would be deassigned. E.g. if course or group membership
104  // is handled by didactic templates, all members would get lost.
105  }
106 
110  public function save()
111  {
112  global $ilDB;
113 
114  parent::save();
115 
116  $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) '.
117  'VALUES ( '.
118  $ilDB->quote($this->getActionId(),'integer').', '.
119  $ilDB->quote($this->getRoleTemplateId(),'integer').' '.
120  ') ';
121  $res = $ilDB->manipulate($query);
122 
123  return true;
124  }
125 
131  public function delete()
132  {
133  global $ilDB;
134 
135  parent::delete();
136 
137  $query = 'DELETE FROM didactic_tpl_alr '.
138  'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
139  $ilDB->manipulate($query);
140 
141  return true;
142  }
143 
148  public function toXml(ilXmlWriter $writer)
149  {
150  $writer->xmlStartTag('localRoleAction');
151 
152 
153 
154  $il_id = 'il_'.IL_INST_ID.'_'.ilObject::_lookupType($this->getRoleTemplateId()).'_'.$this->getRoleTemplateId();
155 
156  $writer->xmlStartTag(
157  'roleTemplate',
158  array(
159  'id' => $il_id
160  )
161  );
162 
163  include_once './Services/AccessControl/classes/class.ilRoleXmlExport.php';
164  $exp = new ilRoleXmlExport();
165  $exp->setMode(ilRoleXmlExport::MODE_DTPL);
166  $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
167  $exp->write();
168  $writer->appendXML($exp->xmlDumpMem(FALSE));
169  $writer->xmlEndTag('roleTemplate');
170  $writer->xmlEndTag('localRoleAction');
171  }
172 
178  public function read()
179  {
180  global $ilDB;
181 
182  parent::read();
183 
184  $query = 'SELECT * FROM didactic_tpl_alr '.
185  'WHERE action_id = '.$ilDB->quote($this->getActionId(),'integer');
186  $res = $ilDB->query($query);
187  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
188  {
189  $this->setRoleTemplateId($row->role_template_id);
190  }
191  return true;
192  }
193 
194 }