ILIAS  release_7 Revision v7.30-3-g800a261c036
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
 
 $refinery
 

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

References $DIC.

33  {
34  global $DIC;
35 
36  $this->logger = $DIC->logger()->otpl();
37  $this->role_folder = $a_role_folder_id;
38  $this->refinery = $DIC['refinery'];
39  }
global $DIC
Definition: goto.php:24

Member Function Documentation

◆ assigntoRoleFolder()

ilRoleXmlImporter::assigntoRoleFolder ( )
protected

Assign role to folder type $rbacadmin.

Returns
type

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

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

209  {
210  global $DIC;
211 
212  $rbacadmin = $DIC['rbacadmin'];
213  $rbacreview = $DIC['rbacreview'];
214 
215  if (!$this->getRoleFolderId()) {
216  return;
217  }
218 
219  if ($rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->getRoleFolderId())) {
220  return;
221  }
222 
223  $rbacadmin->assignRoleToFolder(
224  $this->getRole()->getId(),
225  $this->getRoleFolderId(),
226  $this->getRole() instanceof ilObjRole ? 'y' : 'n'
227  );
228  }
Class ilObjRole.
global $DIC
Definition: goto.php:24
getRoleFolderId()
Get role folder id.
+ Here is the call graph for this function:

◆ getRole()

ilRoleXmlImporter::getRole ( )

Get role.

Returns
ilObjRole

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

References $role.

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

65  {
66  return $this->role;
67  }
+ Here is the caller graph for this function:

◆ getRoleFolderId()

ilRoleXmlImporter::getRoleFolderId ( )

Get role folder id.

Returns
int

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

References $role_folder.

Referenced by assigntoRoleFolder(), and importSimpleXml().

56  {
57  return $this->role_folder;
58  }
+ Here is the caller graph for this function:

◆ getXml()

ilRoleXmlImporter::getXml ( )

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

References $xml.

Referenced by import().

47  {
48  return $this->xml;
49  }
+ Here is the caller graph for this function:

◆ import()

ilRoleXmlImporter::import ( )

import role | role templatae

Exceptions
ilRoleXmlImporterException

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

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

83  {
84  libxml_use_internal_errors(true);
85 
86  $root = simplexml_load_string($this->getXml());
87 
88  if (!$root instanceof SimpleXMLElement) {
89  throw new ilRoleImporterException($this->parseXmlErrors());
90  }
91  foreach ($root->role as $roleElement) {
92  $this->importSimpleXml($roleElement);
93  // only one role is parsed
94  break;
95  }
96  }
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 103 of file class.ilRoleXmlImporter.php.

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

Referenced by import().

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

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

Referenced by importSimpleXml().

232  {
233  if ($this->getRole()) {
234  return true;
235  }
236 
237  $this->logger->debug('Searching already imported role by import_id: ' . $import_id);
238  $obj_id = 0;
239  if ($import_id) {
241  }
242  $this->logger->debug('Found already imported obj_id: ' . $obj_id);
243 
244 
245  if ($obj_id) {
246  $this->role = ilObjectFactory::getInstanceByObjId($obj_id, false);
247  }
248  if (
249  (!$this->getRole() instanceof ilObjRole) &&
250  (!$this->getRole() instanceof ilObjRoleTemplate)
251  ) {
252  $this->logger->debug('Creating new role template');
253  $this->role = new ilObjRoleTemplate();
254  }
255  $this->role->setImportId((string) $import_id);
256  return true;
257  }
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 259 of file class.ilRoleXmlImporter.php.

References $errors.

Referenced by import().

260  {
261  $errors = '';
262 
263  foreach (libxml_get_errors() as $err) {
264  $errors .= $err->code . '<br/>';
265  }
266  return $errors;
267  }
$errors
Definition: imgupload.php:49
+ Here is the caller graph for this function:

◆ setRole()

ilRoleXmlImporter::setRole ( ilObject  $role)

Set role or role template.

Parameters
ilObject$role

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

References $role.

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

◆ setXml()

ilRoleXmlImporter::setXml (   $a_xml)

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

42  {
43  $this->xml = $a_xml;
44  }

Field Documentation

◆ $logger

ilRoleXmlImporter::$logger = null
private

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

◆ $refinery

ilRoleXmlImporter::$refinery
private

Definition at line 27 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: