ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRoleXmlExport.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/Xml/classes/class.ilXmlWriter.php';
5 
13 {
14  const MODE_DTPL = 1;
15 
16 
17  private $roles = array();
18  private $operations = array();
19 
20  private $mode = 0;
21 
22 
26  public function __construct()
27  {
28  parent::__construct();
29 
30  $this->initRbacOperations();
31  }
32 
33 
41  public function setRoles($a_roles)
42  {
43  $this->roles = (array) $a_roles;
44  }
45 
50  public function getRoles()
51  {
52  return (array) $this->roles;
53  }
54 
60  public function addRole($a_role_id, $a_rolf_id)
61  {
62  $this->roles[$a_role_id][] = $a_rolf_id;
63  }
64 
65  public function setMode($a_mode)
66  {
67  $this->mode = $a_mode;
68  }
69 
70  public function getMode()
71  {
72  return $this->mode;
73  }
74 
75 
79  public function writeHeader()
80  {
81  $this->xmlSetDtdDef("<!DOCTYPE Roles PUBLIC \"-//ILIAS//DTD ILIAS Roles//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_role_definition_4_2.dtd\">");
82  $this->xmlSetGenCmt("Role Definition");
83  $this->xmlHeader();
84  return true;
85  }
86 
91  public function write()
92  {
93  if ($this->getMode() != self::MODE_DTPL) {
94  $this->xmlStartTag('roles');
95  }
96 
97  foreach ($this->getRoles() as $role_id => $role_folder_ids) {
98  foreach ((array) $role_folder_ids as $rolf) {
99  $this->writeRole($role_id, $rolf);
100  }
101  }
102 
103  if ($this->getMode() != self::MODE_DTPL) {
104  $this->xmlEndTag('roles');
105  }
106  }
107 
113  private function writeRole($a_role_id, $a_rolf)
114  {
115  global $rbacreview;
116 
117  $attributes = array(
118  'type' => ilObject::_lookupType($a_role_id),
119  'id' => 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($a_role_id) . '_' . $a_role_id,
120  'protected' => ($GLOBALS['rbacreview']->isProtected($a_rolf, $a_role_id) ? 1 : 0)
121  );
122 
123  $this->xmlStartTag('role', $attributes);
124 
125  $this->xmlElement('title', array(), ilObject::_lookupTitle($a_role_id));
126  $this->xmlElement('description', array(), ilObject::_lookupDescription($a_role_id));
127 
128  $this->xmlStartTag('operations');
129  foreach ($rbacreview->getAllOperationsOfRole($a_role_id, $a_rolf) as $obj_group => $operations) {
130  foreach ($operations as $ops_id) {
131  $this->xmlElement('operation', array('group' => $obj_group), trim($this->operations[$ops_id]));
132  }
133  }
134  $this->xmlEndTag('operations');
135  $this->xmlEndTag('role');
136  return true;
137  }
138 
142  private function initRbacOperations()
143  {
144  global $rbacreview;
145 
146  foreach ($rbacreview->getOperations() as $operation) {
147  $this->operations[$operation['ops_id']] = $operation['operation'];
148  }
149  return true;
150  }
151 }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetGenCmt($genCmt)
Sets generated comment.
__construct()
Constructor.
write()
Write xml presentation of chosen roles.
setRoles($a_roles)
Set roles Format is: array(role_id => array(role_folder_id))
xmlSetDtdDef($dtdDef)
Sets dtd definition.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
writeHeader()
Write xml header.
XML writer class.
$attributes
static _lookupTitle($a_id)
lookup object title
xmlEndTag($tag)
Writes an endtag.
writeRole($a_role_id, $a_rolf)
Write xml presentation of one role.
static _lookupDescription($a_id)
lookup object description
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
initRbacOperations()
Cache rbac operations.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
addRole($a_role_id, $a_rolf_id)
Add one role.
Xml export of roles and role templates.