ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilRoleXmlExport.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 public const MODE_DTPL = 1;
28
29 private array $roles = [];
30 private array $operations = [];
31 private int $mode = 0;
32
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $this->rbacreview = $DIC->rbac()->review();
40
42 $this->initRbacOperations();
43 }
44
49 public function setRoles(array $a_roles): void
50 {
51 $this->roles = $a_roles;
52 }
53
54 public function getRoles(): array
55 {
56 return $this->roles;
57 }
58
59 public function addRole(int $a_role_id, int $a_rolf_id): void
60 {
61 $this->roles[$a_role_id][] = $a_rolf_id;
62 }
63
64 public function setMode(int $a_mode): void
65 {
66 $this->mode = $a_mode;
67 }
68
69 public function getMode(): int
70 {
71 return $this->mode;
72 }
73
77 public function writeHeader(): void
78 {
79 $this->xmlSetDtdDef("<!DOCTYPE Roles PUBLIC \"-//ILIAS//DTD ILIAS Roles//EN\" \"" . ILIAS_HTTP_PATH . "/components/ILIAS/Export/xml/ilias_role_definition_4_2.dtd\">");
80 $this->xmlSetGenCmt("Role Definition");
81 $this->xmlHeader();
82 }
83
87 public function write(): void
88 {
89 if ($this->getMode() != self::MODE_DTPL) {
90 $this->xmlStartTag('roles');
91 }
92
93 foreach ($this->getRoles() as $role_id => $role_folder_ids) {
94 foreach ((array) $role_folder_ids as $rolf) {
95 $this->writeRole($role_id, $rolf);
96 }
97 }
98
99 if ($this->getMode() != self::MODE_DTPL) {
100 $this->xmlEndTag('roles');
101 }
102 }
103
107 private function writeRole(int $a_role_id, int $a_rolf): void
108 {
109 $attributes = [
110 'type' => ilObject::_lookupType($a_role_id),
111 'id' => 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($a_role_id) . '_' . $a_role_id,
112 'protected' => ($GLOBALS['DIC']['rbacreview']->isProtected($a_rolf, $a_role_id) ? 1 : 0)
113 ];
114
115 $this->xmlStartTag('role', $attributes);
116
117 $this->xmlElement('title', [], ilObject::_lookupTitle($a_role_id));
118 $this->xmlElement('description', [], ilObject::_lookupDescription($a_role_id));
119
120 $this->xmlStartTag('operations');
121 foreach ($this->rbacreview->getAllOperationsOfRole($a_role_id, $a_rolf) as $obj_group => $operations) {
122 foreach ($operations as $ops_id) {
123 if (isset($this->operations[$ops_id])) {
124 $this->xmlElement('operation', ['group' => $obj_group], trim($this->operations[$ops_id]));
125 }
126 }
127 }
128 $this->xmlEndTag('operations');
129 $this->xmlEndTag('role');
130 }
131
135 private function initRbacOperations(): void
136 {
137 foreach ($this->rbacreview->getOperations() as $operation) {
138 $this->operations[$operation['ops_id']] = $operation['operation'];
139 }
140 }
141}
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
class ilRbacReview Contains Review functions of core Rbac.
Xml export of roles and role templates.
initRbacOperations()
Cache rbac operations.
writeRole(int $a_role_id, int $a_rolf)
Write xml presentation of one role.
addRole(int $a_role_id, int $a_rolf_id)
setRoles(array $a_roles)
Set roles Format is: array(role_id => array(role_folder_id))
write()
Write xml presentation of chosen roles.
writeHeader()
Write xml header.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const IL_INST_ID
Definition: constants.php:40
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54