ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRoleXmlExport.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
26 {
27  public const MODE_DTPL = 1;
28 
29  private array $roles = array();
30  private array $operations = array();
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 . "/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 = array(
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', array(), ilObject::_lookupTitle($a_role_id));
118  $this->xmlElement('description', array(), 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', array('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 }
$attributes
Definition: metadata.php:248
const IL_INST_ID
Definition: constants.php:40
write()
Write xml presentation of chosen roles.
writeHeader()
Write xml header.
setRoles(array $a_roles)
Set roles Format is: array(role_id => array(role_folder_id))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: feed.php:28
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
addRole(int $a_role_id, int $a_rolf_id)
static _lookupTitle(int $obj_id)
writeRole(int $a_role_id, int $a_rolf)
Write xml presentation of one role.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
xmlHeader()
Writes xml header.
static _lookupDescription(int $obj_id)
initRbacOperations()
Cache rbac operations.
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
static _lookupType(int $id, bool $reference=false)