ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 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 type $rbacadmin.

Returns
type

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

References getRole(), and getRoleFolderId().

180  {
181  global $rbacadmin, $rbacreview;
182 
183  if (!$this->getRoleFolderId()) {
184  return;
185  }
186 
187  if ($rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->getRoleFolderId())) {
188  return;
189  }
190 
191  $rbacadmin->assignRoleToFolder(
192  $this->getRole()->getId(),
193  $this->getRoleFolderId(),
194  $this->getRole() instanceof ilObjRole ? 'y' : 'n'
195  );
196  }
Class ilObjRole.
getRoleFolderId()
Get role folder id.
+ 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().

51  {
52  return $this->role;
53  }
+ 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().

42  {
43  return $this->role_folder;
44  }
+ 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().

33  {
34  return $this->xml;
35  }
+ 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.

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

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.
+ 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.

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

Referenced by import().

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

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

Referenced by importSimpleXml().

200  {
201  if ($this->getRole()) {
202  return true;
203  }
204 
205  $obj_id = ilObject::_lookupObjIdByImportId($import_id);
206  include_once './Services/Object/classes/class.ilObjectFactory.php';
207  if ($obj_id) {
208  $this->role = ilObjectFactory::getInstanceByObjId($obj_id, false);
209  }
210  if (!$this->getRole() instanceof ilObjRole or !$this->getRole() instanceof ilObjRoleTemplate) {
211  include_once './Services/AccessControl/classes/class.ilObjRoleTemplate.php';
212  $this->role = new ilObjRoleTemplate();
213  }
214  return true;
215  }
Class ilObjRole.
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseXmlErrors()

ilRoleXmlImporter::parseXmlErrors ( )
protected

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

References $errors.

Referenced by import().

218  {
219  $errors = '';
220 
221  foreach (libxml_get_errors() as $err) {
222  $errors .= $err->code . '<br/>';
223  }
224  return $errors;
225  }
$errors
Definition: index.php:6
+ 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.

References $role.

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

◆ 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(), 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: