ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilRoleXmlImporter Class Reference

Description of class. More...

+ Collaboration diagram for ilRoleXmlImporter:

Public Member Functions

 __construct ($a_role_folder_id=0)
 Constructor. More...
 
 setXml ($a_xml)
 
 getXml ()
 
 getRoleFolderId ()
 Get role folder id. More...
 
 getRole ()
 Get role. More...
 
 setRole (ilObject $role)
 Set role or role template. More...
 
 import ()
 import role | role templatae More...
 
 importSimpleXml (SimpleXMLElement $role)
 Import using simplexml. More...
 

Protected Member Functions

 assigntoRoleFolder ()
 Assign role to folder @global type $rbacadmin. More...
 
 initRole ($import_id)
 
 parseXmlErrors ()
 

Protected Attributes

 $role_folder = 0
 
 $role = null
 
 $xml = ''
 

Detailed Description

Description of class.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilRoleXmlImporter::__construct (   $a_role_folder_id = 0)

Constructor.

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

23 {
24 $this->role_folder = $a_role_folder_id;
25 }

Member Function Documentation

◆ assigntoRoleFolder()

ilRoleXmlImporter::assigntoRoleFolder ( )
protected

Assign role to folder @global type $rbacadmin.

Returns
type

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

184 {
185 global $DIC;
186
187 $rbacadmin = $DIC['rbacadmin'];
188 $rbacreview = $DIC['rbacreview'];
189
190 if (!$this->getRoleFolderId()) {
191 return;
192 }
193
194 if ($rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->getRoleFolderId())) {
195 return;
196 }
197
198 $rbacadmin->assignRoleToFolder(
199 $this->getRole()->getId(),
200 $this->getRoleFolderId(),
201 $this->getRole() instanceof ilObjRole ? 'y' : 'n'
202 );
203 }
Class ilObjRole.
getRoleFolderId()
Get role folder id.
global $DIC
Definition: saml.php:7

References $DIC, getRole(), and getRoleFolderId().

+ Here is the call graph for this function:

◆ getRole()

ilRoleXmlImporter::getRole ( )

Get role.

Returns
ilObjRole

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

References $role.

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

+ Here is the caller graph for this function:

◆ getRoleFolderId()

ilRoleXmlImporter::getRoleFolderId ( )

Get role folder id.

Returns
int

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

References $role_folder.

Referenced by assigntoRoleFolder(), and importSimpleXml().

+ Here is the caller graph for this function:

◆ getXml()

ilRoleXmlImporter::getXml ( )

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

References $xml.

Referenced by import().

+ Here is the caller graph for this function:

◆ import()

ilRoleXmlImporter::import ( )

import role | role templatae

Exceptions
ilRoleXmlImporterException

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

69 {
70 libxml_use_internal_errors(true);
71
72 $root = simplexml_load_string($this->getXml());
73
74 if (!$root instanceof SimpleXMLElement) {
75 throw new ilRoleImporterException($this->parseXmlErrors());
76 }
77 foreach ($root->role as $roleElement) {
78 $this->importSimpleXml($roleElement);
79 // only one role is parsed
80 break;
81 }
82 }
importSimpleXml(SimpleXMLElement $role)
Import using simplexml.
$root
Definition: sabredav.php:45

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

+ Here is the call graph for this function:

◆ importSimpleXml()

ilRoleXmlImporter::importSimpleXml ( SimpleXMLElement  $role)

Import using simplexml.

Parameters
SimpleXMLElement$role

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

90 {
91 global $DIC;
92
93 $rbacadmin = $DIC['rbacadmin'];
94 $rbacreview = $DIC['rbacreview'];
95 $lng = $DIC['lng'];
96
97 $import_id = (string) $role['id'];
98 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ' Importing role with import id ' . $import_id);
99
100 if (!$this->initRole($import_id)) {
101 return 0;
102 }
103
104 $this->getRole()->setTitle(trim((string) $role->title));
105 $this->getRole()->setDescription(trim((string) $role->description));
106
108 $exp = explode("_", $this->getRole()->getTitle());
109
110 if (count($exp) > 0 && $exp[0] === "il") {
111 if (count($exp) > 1 && $exp[1] !== $type) {
112 throw new ilRoleImporterException(sprintf(
113 $lng->txt("rbac_cant_import_role_wrong_type"),
114 $lng->txt('obj_' . $exp[1]),
115 $lng->txt('obj_' . $type)
116 ));
117 }
118
119 $exp[3] = $this->getRoleFolderId();
120
121 $id = ilObjRole::_getIdsForTitle(implode("_", $exp));
122
123 if ($id[0]) {
124 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Overwrite role ' . implode("_", $exp));
125 $this->getRole()->setId($id[0]);
126 $this->getRole()->read();
127 }
128 }
129
130 // Create or update
131 if ($this->getRole()->getId()) {
132 $rbacadmin->deleteRolePermission($this->getRole()->getId(), $this->getRoleFolderId());
133 $this->getRole()->update();
134 } else {
135 $this->getRole()->create();
136 }
137
138
139 $this->assignToRoleFolder();
140
141 $protected = (string) $role['protected'];
142 if ($protected) {
143 $rbacadmin->setProtected(0, $this->getRole()->getId(), 'y');
144 }
145
146 // Add operations
147 $ops = $rbacreview->getOperations();
148 $operations = array();
149 foreach ($ops as $ope) {
150 $operations[$ope['operation']] = $ope['ops_id'];
151 }
152
153 foreach ($role->operations as $sxml_operations) {
154 foreach ($sxml_operations as $sxml_op) {
155 $ops_group = (string) $sxml_op['group'];
156 $ops_id = (int) $operations[trim((string) $sxml_op)];
157 $ops = trim((string) $sxml_op);
158
159 if ($ops_group and $ops_id) {
160 $rbacadmin->setRolePermission(
161 $this->getRole()->getId(),
162 $ops_group,
163 array($ops_id),
164 $this->getRoleFolderId() // #10161
165 );
166 } else {
167 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Cannot create operation for...');
168 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New operation for group ' . $ops_group);
169 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New operation ' . $ops);
170 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New operation ' . $ops_id);
171 }
172 }
173 }
174
175 return $this->getRole()->getId();
176 }
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getIdsForTitle($title, $type='', $partialmatch=false)
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$type
$lng

References $DIC, $GLOBALS, $id, $lng, $role, $type, ilObject\_getIdsForTitle(), ilObject\_lookupType(), getRole(), getRoleFolderId(), and initRole().

Referenced by import().

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

◆ initRole()

ilRoleXmlImporter::initRole (   $import_id)
protected

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

207 {
208 if ($this->getRole()) {
209 return true;
210 }
211
212 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
213 include_once './Services/Object/classes/class.ilObjectFactory.php';
214 if ($obj_id) {
215 $this->role = ilObjectFactory::getInstanceByObjId($obj_id, false);
216 }
217 if (!$this->getRole() instanceof ilObjRole or !$this->getRole() instanceof ilObjRoleTemplate) {
218 include_once './Services/AccessControl/classes/class.ilObjRoleTemplate.php';
219 $this->role = new ilObjRoleTemplate();
220 }
221 return true;
222 }
Class ilObjRoleTemplate.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjIdByImportId($a_import_id)

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

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 224 of file class.ilRoleXmlImporter.php.

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

References $errors.

Referenced by import().

+ Here is the caller graph for this function:

◆ setRole()

ilRoleXmlImporter::setRole ( ilObject  $role)

Set role or role template.

Parameters
ilObject$role

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

60 {
61 $this->role = $role;
62 }

References $role.

◆ setXml()

ilRoleXmlImporter::setXml (   $a_xml)

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

28 {
29 $this->xml = $a_xml;
30 }

Field Documentation

◆ $role

ilRoleXmlImporter::$role = null
protected

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

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

◆ $role_folder

ilRoleXmlImporter::$role_folder = 0
protected

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

Referenced by getRoleFolderId().

◆ $xml

ilRoleXmlImporter::$xml = ''
protected

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

Referenced by getXml().


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