ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRoleXmlImporter Class Reference

Description of class. More...

+ Collaboration diagram for ilRoleXmlImporter:

Public Member Functions

 __construct (int $a_role_folder_id=0)
 
 setXml (string $a_xml)
 
 getXml ()
 
 getRoleFolderId ()
 
 getRole ()
 
 setRole (ilObject $role)
 
 import ()
 import role | role templatae More...
 
 importSimpleXml (SimpleXMLElement $role)
 

Protected Member Functions

 assignToRoleFolder ()
 
 initRole (string $import_id)
 
 parseXmlErrors ()
 

Protected Attributes

int $role_folder = 0
 
ilObject $role = null
 
string $xml = ''
 

Private Attributes

ilLogger $logger
 
ilRbacAdmin $rbacadmin
 
ilRbacReview $rbacreview
 
ilLanguage $language
 
Refinery $refinery
 

Detailed Description

Description of class.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 28 of file class.ilRoleXmlImporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilRoleXmlImporter::__construct ( int  $a_role_folder_id = 0)

Definition at line 41 of file class.ilRoleXmlImporter.php.

42 {
43 global $DIC;
44
45 $this->logger = $DIC->logger()->ac();
46 $this->rbacreview = $DIC->rbac()->review();
47 $this->rbacadmin = $DIC->rbac()->admin();
48 $this->language = $DIC->language();
49 $this->refinery = $DIC['refinery'];
50
51 $this->role_folder = $a_role_folder_id;
52 }
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Member Function Documentation

◆ assignToRoleFolder()

ilRoleXmlImporter::assignToRoleFolder ( )
protected

Definition at line 182 of file class.ilRoleXmlImporter.php.

182 : void
183 {
184 if (!$this->getRoleFolderId()) {
185 return;
186 }
187
188 if ($this->rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->getRoleFolderId())) {
189 return;
190 }
191
192 $this->rbacadmin->assignRoleToFolder(
193 $this->getRole()->getId(),
194 $this->getRoleFolderId(),
195 $this->getRole() instanceof ilObjRole ? 'y' : 'n'
196 );
197 }
Class ilObjRole.

References ILIAS\Survey\Mode\getId(), getRole(), and getRoleFolderId().

Referenced by importSimpleXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRole()

ilRoleXmlImporter::getRole ( )

Definition at line 69 of file class.ilRoleXmlImporter.php.

69 : ?ilObject
70 {
71 return $this->role;
72 }
Class ilObject Basic functions for all objects.

References $role.

Referenced by assignToRoleFolder(), importSimpleXml(), and initRole().

+ Here is the caller graph for this function:

◆ getRoleFolderId()

ilRoleXmlImporter::getRoleFolderId ( )

Definition at line 64 of file class.ilRoleXmlImporter.php.

64 : int
65 {
66 return $this->role_folder;
67 }

References $role_folder.

Referenced by assignToRoleFolder(), and importSimpleXml().

+ Here is the caller graph for this function:

◆ getXml()

ilRoleXmlImporter::getXml ( )

Definition at line 59 of file class.ilRoleXmlImporter.php.

59 : string
60 {
61 return $this->xml;
62 }

References $xml.

Referenced by import().

+ Here is the caller graph for this function:

◆ import()

ilRoleXmlImporter::import ( )

import role | role templatae

Exceptions
ilRoleImporterException

Definition at line 83 of file class.ilRoleXmlImporter.php.

83 : void
84 {
85 $use_internal_errors = libxml_use_internal_errors(true);
86 $root = simplexml_load_string($this->getXml());
87 libxml_use_internal_errors($use_internal_errors);
88
89 if (!$root instanceof SimpleXMLElement) {
90 throw new ilRoleImporterException($this->parseXmlErrors());
91 }
92 foreach ($root->role as $roleElement) {
93 $this->importSimpleXml($roleElement);
94 // only one role is parsed
95 break;
96 }
97 }
importSimpleXml(SimpleXMLElement $role)

References getXml(), importSimpleXml(), and parseXmlErrors().

+ Here is the call graph for this function:

◆ importSimpleXml()

ilRoleXmlImporter::importSimpleXml ( SimpleXMLElement  $role)

Definition at line 99 of file class.ilRoleXmlImporter.php.

99 : int
100 {
101 $import_id = (string) $role['id'];
102 $this->logger->info('Importing role with import_id: ' . $import_id);
103 $this->initRole($import_id);
104
105 $trafo = $this->refinery->in()->series([
106 $this->refinery->kindlyTo()->string(),
107 $this->refinery->string()->stripTags()
108 ]);
109
110 $this->getRole()->setTitle($trafo->transform($role->title ?? ''));
111 $this->getRole()->setDescription($trafo->transform($role->description ?? ''));
112
113 $this->logger->info('Current role import id: ' . $this->getRole()->getImportId());
114
115 $type = ilObject::_lookupType($this->getRoleFolderId(), true);
116 $exp = explode("_", $this->getRole()->getTitle());
117
118 if (count($exp) > 0 && $exp[0] === "il") {
119 if (count($exp) > 1 && $exp[1] !== $type) {
120 throw new ilRoleImporterException(sprintf(
121 $this->language->txt("rbac_cant_import_role_wrong_type"),
122 $this->language->txt('obj_' . $exp[1]),
123 $this->language->txt('obj_' . $type)
124 ));
125 }
126
127 $exp[3] = $this->getRoleFolderId();
128
129 $id = ilObjRole::_getIdsForTitle(implode("_", $exp));
130
131 if ($id[0]) {
132 $this->getRole()->setId($id[0]);
133 $this->getRole()->read();
134 }
135 }
136
137 // Create or update
138 if ($this->getRole()->getId()) {
139 $this->rbacadmin->deleteRolePermission($this->getRole()->getId(), $this->getRoleFolderId());
140 $this->getRole()->update();
141 } else {
142 $this->getRole()->create();
143 }
144
145 $this->assignToRoleFolder();
146
147 $protected = (string) $role['protected'];
148 if ($protected) {
149 $this->rbacadmin->setProtected(0, $this->getRole()->getId(), 'y');
150 }
151
152 // Add operations
153 $ops = $this->rbacreview->getOperations();
154 $operations = [];
155 foreach ($ops as $ope) {
156 $operations[$ope['operation']] = $ope['ops_id'];
157 }
158
159 foreach ($role->operations as $sxml_operations) {
160 foreach ($sxml_operations as $sxml_op) {
161 $operation = trim((string) $sxml_op);
162 if (!array_key_exists($operation, $operations)) {
163 continue;
164 }
165 $ops_group = (string) $sxml_op['group'];
166 $ops_id = (int) $operations[$operation];
167 $ops = $operation;
168
169 if ($ops_group && $ops_id) {
170 $this->rbacadmin->setRolePermission(
171 $this->getRole()->getId(),
172 $ops_group,
173 [$ops_id],
174 $this->getRoleFolderId() // #10161
175 );
176 }
177 }
178 }
179 return $this->getRole()->getId();
180 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $id, bool $reference=false)
static _getIdsForTitle(string $title, string $type='', bool $partial_match=false)
initRole(string $import_id)

References $id, $role, ilObject\_getIdsForTitle(), ilObject\_lookupType(), assignToRoleFolder(), ILIAS\Survey\Mode\getId(), getRole(), getRoleFolderId(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), initRole(), ILIAS\Repository\int(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), and ILIAS\Repository\refinery().

Referenced by import().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initRole()

ilRoleXmlImporter::initRole ( string  $import_id)
protected

Definition at line 199 of file class.ilRoleXmlImporter.php.

199 : void
200 {
201 if ($this->getRole()) {
202 return;
203 }
204
205 $this->logger->debug('Searching already imported role by import_id: ' . $import_id);
206 $obj_id = 0;
207 if ($import_id) {
208 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
209 }
210 $this->logger->debug('Found already imported obj_id: ' . $obj_id);
211
212 if ($obj_id) {
213 $this->role = ilObjectFactory::getInstanceByObjId($obj_id, false);
214 }
215 if (
216 (!$this->getRole() instanceof ilObjRole) &&
217 (!$this->getRole() instanceof ilObjRoleTemplate)
218 ) {
219 $this->logger->debug('Creating new role template');
220 $this->role = new ilObjRoleTemplate();
221 }
222 $this->role->setImportId($import_id);
223 }
Class ilObjRoleTemplate.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.

References ilObject\_lookupObjIdByImportId(), ilObjectFactory\getInstanceByObjId(), getRole(), and ILIAS\Repository\logger().

Referenced by importSimpleXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseXmlErrors()

ilRoleXmlImporter::parseXmlErrors ( )
protected

Definition at line 225 of file class.ilRoleXmlImporter.php.

225 : string
226 {
227 $errors = '';
228
229 foreach (libxml_get_errors() as $err) {
230 $errors .= $err->code . '<br/>';
231 }
232 return $errors;
233 }

Referenced by import().

+ Here is the caller graph for this function:

◆ setRole()

ilRoleXmlImporter::setRole ( ilObject  $role)

Definition at line 74 of file class.ilRoleXmlImporter.php.

74 : void
75 {
76 $this->role = $role;
77 }

References $role.

◆ setXml()

ilRoleXmlImporter::setXml ( string  $a_xml)

Definition at line 54 of file class.ilRoleXmlImporter.php.

54 : void
55 {
56 $this->xml = $a_xml;
57 }

Field Documentation

◆ $language

ilLanguage ilRoleXmlImporter::$language
private

Definition at line 38 of file class.ilRoleXmlImporter.php.

◆ $logger

ilLogger ilRoleXmlImporter::$logger
private

Definition at line 35 of file class.ilRoleXmlImporter.php.

◆ $rbacadmin

ilRbacAdmin ilRoleXmlImporter::$rbacadmin
private

Definition at line 36 of file class.ilRoleXmlImporter.php.

◆ $rbacreview

ilRbacReview ilRoleXmlImporter::$rbacreview
private

Definition at line 37 of file class.ilRoleXmlImporter.php.

◆ $refinery

Refinery ilRoleXmlImporter::$refinery
private

Definition at line 39 of file class.ilRoleXmlImporter.php.

◆ $role

ilObject ilRoleXmlImporter::$role = null
protected

Definition at line 31 of file class.ilRoleXmlImporter.php.

Referenced by getRole(), importSimpleXml(), and setRole().

◆ $role_folder

int ilRoleXmlImporter::$role_folder = 0
protected

Definition at line 30 of file class.ilRoleXmlImporter.php.

Referenced by getRoleFolderId().

◆ $xml

string ilRoleXmlImporter::$xml = ''
protected

Definition at line 33 of file class.ilRoleXmlImporter.php.

Referenced by getXml().


The documentation for this class was generated from the following file: