ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4include_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 {
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 $DIC;
116
117 $rbacreview = $DIC['rbacreview'];
118
119 $attributes = array(
120 'type' => ilObject::_lookupType($a_role_id),
121 'id' => 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($a_role_id) . '_' . $a_role_id,
122 'protected' => ($GLOBALS['DIC']['rbacreview']->isProtected($a_rolf, $a_role_id) ? 1 : 0)
123 );
124
125 $this->xmlStartTag('role', $attributes);
126
127 $this->xmlElement('title', array(), ilObject::_lookupTitle($a_role_id));
128 $this->xmlElement('description', array(), ilObject::_lookupDescription($a_role_id));
129
130 $this->xmlStartTag('operations');
131 foreach ($rbacreview->getAllOperationsOfRole($a_role_id, $a_rolf) as $obj_group => $operations) {
132 foreach ($operations as $ops_id) {
133 $this->xmlElement('operation', array('group' => $obj_group), trim($this->operations[$ops_id]));
134 }
135 }
136 $this->xmlEndTag('operations');
137 $this->xmlEndTag('role');
138 return true;
139 }
140
144 private function initRbacOperations()
145 {
146 global $DIC;
147
148 $rbacreview = $DIC['rbacreview'];
149
150 foreach ($rbacreview->getOperations() as $operation) {
151 $this->operations[$operation['ops_id']] = $operation['operation'];
152 }
153 return true;
154 }
155}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
static _lookupType($a_id, $a_reference=false)
lookup object type
Xml export of roles and role templates.
initRbacOperations()
Cache rbac operations.
addRole($a_role_id, $a_rolf_id)
Add one role.
setRoles($a_roles)
Set roles Format is: array(role_id => array(role_folder_id))
write()
Write xml presentation of chosen roles.
writeRole($a_role_id, $a_rolf)
Write xml presentation of one role.
writeHeader()
Write xml header.
__construct()
Constructor.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlHeader()
Writes xml header @access public.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
$attributes
Definition: metadata.php:231
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc