ILIAS  release_4-4 Revision
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 170 of file class.ilRoleXmlImporter.php.

References getRole(), and getRoleFolderId().

171  {
172  global $rbacadmin;
173 
174  if(!$this->getRoleFolderId())
175  {
176  return;
177  }
178 
179  $rbacadmin->assignRoleToFolder(
180  $this->getRole()->getId(),
181  $this->getRoleFolderId(),
182  $this->getRole() instanceof ilObjRole ? 'y' : 'n'
183  );
184  }
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  {
76  throw new ilRoleImporterException($this->parseXmlErrors());
77  }
78  foreach($root->role as $roleElement)
79  {
80  $this->importSimpleXml($roleElement);
81  // only one role is parsed
82  break;
83  }
84  }
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 91 of file class.ilRoleXmlImporter.php.

References $GLOBALS, getRole(), getRoleFolderId(), and initRole().

Referenced by import().

92  {
93  global $rbacadmin, $rbacreview;
94 
95  $import_id = (string) $role['id'];
96  $GLOBALS['ilLog']->write(__METHOD__.' Importing role with import id '. $import_id);
97 
98  if(!$this->initRole($import_id))
99  {
100  return 0;
101  }
102 
103  $this->getRole()->setTitle(trim((string) $role->title));
104  $this->getRole()->setDescription(trim((string) $role->description));
105 
106 
107  // Create or update
108  if($this->getRole()->getId())
109  {
110  $this->getRole()->update();
111  }
112  else
113  {
114  $this->getRole()->create();
115  }
116 
117 
118  $this->assignToRoleFolder();
119 
120  $protected = (string) $role['protected'];
121  if($protected)
122  {
123  $rbacadmin->setProtected(0,$this->getRole()->getId(),'y');
124  }
125 
126  // Add operations
127  $ops = $rbacreview->getOperations();
128  $operations = array();
129  foreach($ops as $ope)
130  {
131  $operations[$ope['operation']] = $ope['ops_id'];
132  }
133 
134  foreach($role->operations as $sxml_operations)
135  {
136  foreach($sxml_operations as $sxml_op)
137  {
138  $ops_group = (string) $sxml_op['group'];
139  $ops_id = (int) $operations[trim((string) $sxml_op)];
140  $ops = trim((string) $sxml_op);
141 
142  if($ops_group and $ops_id)
143  {
144  $rbacadmin->setRolePermission(
145  $this->getRole()->getId(),
146  $ops_group,
147  array($ops_id),
148  $this->getRoleFolderId() // #10161
149  );
150  }
151  else
152  {
153  $GLOBALS['ilLog']->write(__METHOD__.': Cannot create operation for...');
154  $GLOBALS['ilLog']->write(__METHOD__.': New operation for group '. $ops_group);
155  $GLOBALS['ilLog']->write(__METHOD__.': New operation '.$ops);
156  $GLOBALS['ilLog']->write(__METHOD__.': New operation '. $ops_id);
157  }
158 
159  }
160  }
161 
162  return $this->getRole()->getId();
163  }
$GLOBALS['ct_recipient']
getRoleFolderId()
Get role folder id.
+ 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 187 of file class.ilRoleXmlImporter.php.

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

Referenced by importSimpleXml().

188  {
189  if($this->getRole())
190  {
191  return true;
192  }
193 
194  $obj_id = ilObject::_lookupObjIdByImportId($import_id);
195  include_once './Services/Object/classes/class.ilObjectFactory.php';
196  if($obj_id)
197  {
198  $this->role = ilObjectFactory::getInstanceByObjId($obj_id,false);
199  }
200  if(!$this->getRole() instanceof ilObjRole or !$this->getRole() instanceof ilObjRoleTemplate)
201  {
202  include_once './Services/AccessControl/classes/class.ilObjRoleTemplate.php';
203  $this->role = new ilObjRoleTemplate();
204  }
205  return true;
206  }
Class ilObjRole.
Class ilObjRoleTemplate.
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 208 of file class.ilRoleXmlImporter.php.

References $errors.

Referenced by import().

209  {
210  $errors = '';
211 
212  foreach(libxml_get_errors() as $err)
213  {
214  $errors .= $err->code.'<br/>';
215  }
216  return $errors;
217  }
$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 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: