ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 
94  if($this->getMode() != self::MODE_DTPL)
95  {
96  $this->xmlStartTag('roles');
97  }
98 
99  foreach($this->getRoles() as $role_id => $role_folder_ids)
100  {
101  foreach((array) $role_folder_ids as $rolf)
102  {
103  $this->writeRole($role_id, $rolf);
104  }
105  }
106 
107  if($this->getMode() != self::MODE_DTPL)
108  {
109  $this->xmlEndTag('roles');
110  }
111  }
112 
118  private function writeRole($a_role_id, $a_rolf)
119  {
120  global $rbacreview;
121 
122  $attributes = array(
123  'type' => ilObject::_lookupType($a_role_id),
124  'id' => 'il_'.IL_INST_ID.'_'.ilObject::_lookupType($a_role_id).'_'.$a_role_id,
125  'protected' => ($GLOBALS['rbacreview']->isProtected($a_rolf,$a_role_id) ? 1 : 0)
126  );
127 
128  $this->xmlStartTag('role',$attributes);
129 
130  $this->xmlElement('title',array(),ilObject::_lookupTitle($a_role_id));
131  $this->xmlElement('description', array(), ilObject::_lookupDescription($a_role_id));
132 
133  $this->xmlStartTag('operations');
134  foreach($rbacreview->getAllOperationsOfRole($a_role_id, $a_rolf) as $obj_group => $operations)
135  {
136  foreach($operations as $ops_id)
137  {
138  $this->xmlElement('operation', array('group' => $obj_group), trim($this->operations[$ops_id]));
139  }
140  }
141  $this->xmlEndTag('operations');
142  $this->xmlEndTag('role');
143  return true;
144  }
145 
149  private function initRbacOperations()
150  {
151  global $rbacreview;
152 
153  foreach($rbacreview->getOperations() as $operation)
154  {
155  $this->operations[$operation['ops_id']] = $operation['operation'];
156  }
157  return true;
158  }
159 
160 
161 }
162 ?>
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.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
writeHeader()
Write xml header.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
static _lookupTitle($a_id)
lookup object title
xmlEndTag($tag)
Writes an endtag.
writeRole($a_role_id, $a_rolf)
Write xml presentation of one role.
$GLOBALS['ct_recipient']
static _lookupDescription($a_id)
lookup object description
xmlHeader()
Writes xml header public.
static _lookupType($a_id, $a_reference=false)
lookup object type
initRbacOperations()
Cache rbac operations.
addRole($a_role_id, $a_rolf_id)
Add one role.
Xml export of roles and role templates.