ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 = ''
 

Private Attributes

 $logger = null
 

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

References $DIC.

28  {
29  global $DIC;
30 
31  $this->logger = $DIC->logger()->otpl();
32  $this->role_folder = $a_role_folder_id;
33  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ assigntoRoleFolder()

ilRoleXmlImporter::assigntoRoleFolder ( )
protected

Assign role to folder type $rbacadmin.

Returns
type

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

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

194  {
195  global $DIC;
196 
197  $rbacadmin = $DIC['rbacadmin'];
198  $rbacreview = $DIC['rbacreview'];
199 
200  if (!$this->getRoleFolderId()) {
201  return;
202  }
203 
204  if ($rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->getRoleFolderId())) {
205  return;
206  }
207 
208  $rbacadmin->assignRoleToFolder(
209  $this->getRole()->getId(),
210  $this->getRoleFolderId(),
211  $this->getRole() instanceof ilObjRole ? 'y' : 'n'
212  );
213  }
Class ilObjRole.
getRoleFolderId()
Get role folder id.
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

◆ getRole()

ilRoleXmlImporter::getRole ( )

Get role.

Returns
ilObjRole

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

References $role.

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

59  {
60  return $this->role;
61  }
+ Here is the caller graph for this function:

◆ getRoleFolderId()

ilRoleXmlImporter::getRoleFolderId ( )

Get role folder id.

Returns
int

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

References $role_folder.

Referenced by assigntoRoleFolder(), and importSimpleXml().

50  {
51  return $this->role_folder;
52  }
+ Here is the caller graph for this function:

◆ getXml()

ilRoleXmlImporter::getXml ( )

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

References $xml.

Referenced by import().

41  {
42  return $this->xml;
43  }
+ Here is the caller graph for this function:

◆ import()

ilRoleXmlImporter::import ( )

import role | role templatae

Exceptions
ilRoleXmlImporterException

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

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

77  {
78  libxml_use_internal_errors(true);
79 
80  $root = simplexml_load_string($this->getXml());
81 
82  if (!$root instanceof SimpleXMLElement) {
83  throw new ilRoleImporterException($this->parseXmlErrors());
84  }
85  foreach ($root->role as $roleElement) {
86  $this->importSimpleXml($roleElement);
87  // only one role is parsed
88  break;
89  }
90  }
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 97 of file class.ilRoleXmlImporter.php.

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

Referenced by import().

98  {
99  global $DIC;
100 
101  $rbacadmin = $DIC['rbacadmin'];
102  $rbacreview = $DIC['rbacreview'];
103  $lng = $DIC['lng'];
104 
105  $import_id = (string) $role['id'];
106  $this->logger->info('Importing role with import_id: ' . $import_id);
107 
108  if (!$this->initRole($import_id)) {
109  return 0;
110  }
111 
112  $this->getRole()->setTitle(trim((string) $role->title));
113  $this->getRole()->setDescription(trim((string) $role->description));
114 
115  $this->logger->info('Current role import id: ' . $this->getRole()->getImportId());
116 
117  $type = ilObject::_lookupType($this->getRoleFolderId(), true);
118  $exp = explode("_", $this->getRole()->getTitle());
119 
120  if (count($exp) > 0 && $exp[0] === "il") {
121  if (count($exp) > 1 && $exp[1] !== $type) {
122  throw new ilRoleImporterException(sprintf(
123  $lng->txt("rbac_cant_import_role_wrong_type"),
124  $lng->txt('obj_' . $exp[1]),
125  $lng->txt('obj_' . $type)
126  ));
127  }
128 
129  $exp[3] = $this->getRoleFolderId();
130 
131  $id = ilObjRole::_getIdsForTitle(implode("_", $exp));
132 
133  if ($id[0]) {
134  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Overwrite role ' . implode("_", $exp));
135  $this->getRole()->setId($id[0]);
136  $this->getRole()->read();
137  }
138  }
139 
140  // Create or update
141  if ($this->getRole()->getId()) {
142  $rbacadmin->deleteRolePermission($this->getRole()->getId(), $this->getRoleFolderId());
143  $this->getRole()->update();
144  } else {
145  $this->getRole()->create();
146  }
147 
148 
149  $this->assignToRoleFolder();
150 
151  $protected = (string) $role['protected'];
152  if ($protected) {
153  $rbacadmin->setProtected(0, $this->getRole()->getId(), 'y');
154  }
155 
156  // Add operations
157  $ops = $rbacreview->getOperations();
158  $operations = array();
159  foreach ($ops as $ope) {
160  $operations[$ope['operation']] = $ope['ops_id'];
161  }
162 
163  foreach ($role->operations as $sxml_operations) {
164  foreach ($sxml_operations as $sxml_op) {
165  $ops_group = (string) $sxml_op['group'];
166  $ops_id = (int) $operations[trim((string) $sxml_op)];
167  $ops = trim((string) $sxml_op);
168 
169  if ($ops_group and $ops_id) {
170  $rbacadmin->setRolePermission(
171  $this->getRole()->getId(),
172  $ops_group,
173  array($ops_id),
174  $this->getRoleFolderId() // #10161
175  );
176  } else {
177  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Cannot create operation for...');
178  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New operation for group ' . $ops_group);
179  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New operation ' . $ops);
180  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New operation ' . $ops_id);
181  }
182  }
183  }
184 
185  return $this->getRole()->getId();
186  }
$type
$lng
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _lookupType($a_id, $a_reference=false)
lookup object type
getRoleFolderId()
Get role folder id.
$DIC
Definition: xapitoken.php:46
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 216 of file class.ilRoleXmlImporter.php.

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

Referenced by importSimpleXml().

217  {
218  if ($this->getRole()) {
219  return true;
220  }
221 
222  $this->logger->debug('Searching already imported role by import_id: ' . $import_id);
223  $obj_id = 0;
224  if ($import_id) {
225  $obj_id = ilObject::_lookupObjIdByImportId($import_id);
226  }
227  $this->logger->debug('Found already imported obj_id: ' . $obj_id);
228 
229 
230  if ($obj_id) {
231  $this->role = ilObjectFactory::getInstanceByObjId($obj_id, false);
232  }
233  if (
234  (!$this->getRole() instanceof ilObjRole) &&
235  (!$this->getRole() instanceof ilObjRoleTemplate)
236  ) {
237  $this->logger->debug('Creating new role template');
238  $this->role = new ilObjRoleTemplate();
239  }
240  $this->role->setImportId((string) $import_id);
241  return true;
242  }
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 244 of file class.ilRoleXmlImporter.php.

References $errors.

Referenced by import().

245  {
246  $errors = '';
247 
248  foreach (libxml_get_errors() as $err) {
249  $errors .= $err->code . '<br/>';
250  }
251  return $errors;
252  }
$errors
+ Here is the caller graph for this function:

◆ setRole()

ilRoleXmlImporter::setRole ( ilObject  $role)

Set role or role template.

Parameters
ilObject$role

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

References $role.

68  {
69  $this->role = $role;
70  }

◆ setXml()

ilRoleXmlImporter::setXml (   $a_xml)

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

36  {
37  $this->xml = $a_xml;
38  }

Field Documentation

◆ $logger

ilRoleXmlImporter::$logger = null
private

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

◆ $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: