ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 193 of file class.ilRoleXmlImporter.php.

194 {
195 global $rbacadmin, $rbacreview;
196
197 if(!$this->getRoleFolderId())
198 {
199 return;
200 }
201
202 if($rbacreview->isRoleAssignedToObject($this->getRole()->getId(),$this->getRoleFolderId()))
203 {
204 return;
205 }
206
207 $rbacadmin->assignRoleToFolder(
208 $this->getRole()->getId(),
209 $this->getRoleFolderId(),
210 $this->getRole() instanceof ilObjRole ? 'y' : 'n'
211 );
212 }
Class ilObjRole.
getRoleFolderId()
Get role folder id.

References 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 {
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.

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

92 {
93 global $rbacadmin, $rbacreview, $lng;
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 $type = ilObject::_lookupType($this->getRoleFolderId(), true);
107 $exp = explode("_", $this->getRole()->getTitle());
108
109 if(count($exp) > 0 && $exp[0] === "il")
110 {
111 if(count($exp) > 1 && $exp[1] !== $type)
112 {
113 throw new ilRoleImporterException(sprintf($lng->txt("rbac_cant_import_role_wrong_type"),
114 $lng->txt('obj_'.$exp[1]),$lng->txt('obj_'.$type)));
115 }
116
117 $exp[3] = $this->getRoleFolderId();
118
119 $id = ilObjRole::_getIdsForTitle(implode("_", $exp));
120
121 if($id[0])
122 {
123 $GLOBALS['ilLog']->write(__METHOD__.': Overwrite role '. implode("_", $exp));
124 $this->getRole()->setId($id[0]);
125 $this->getRole()->read();
126 }
127 }
128
129 // Create or update
130 if($this->getRole()->getId())
131 {
132 $rbacadmin->deleteRolePermission($this->getRole()->getId(), $this->getRoleFolderId());
133 $this->getRole()->update();
134 }
135 else
136 {
137 $this->getRole()->create();
138 }
139
140
141 $this->assignToRoleFolder();
142
143 $protected = (string) $role['protected'];
144 if($protected)
145 {
146 $rbacadmin->setProtected(0,$this->getRole()->getId(),'y');
147 }
148
149 // Add operations
150 $ops = $rbacreview->getOperations();
151 $operations = array();
152 foreach($ops as $ope)
153 {
154 $operations[$ope['operation']] = $ope['ops_id'];
155 }
156
157 foreach($role->operations as $sxml_operations)
158 {
159 foreach($sxml_operations as $sxml_op)
160 {
161 $ops_group = (string) $sxml_op['group'];
162 $ops_id = (int) $operations[trim((string) $sxml_op)];
163 $ops = trim((string) $sxml_op);
164
165 if($ops_group and $ops_id)
166 {
167 $rbacadmin->setRolePermission(
168 $this->getRole()->getId(),
169 $ops_group,
170 array($ops_id),
171 $this->getRoleFolderId() // #10161
172 );
173 }
174 else
175 {
176 $GLOBALS['ilLog']->write(__METHOD__.': Cannot create operation for...');
177 $GLOBALS['ilLog']->write(__METHOD__.': New operation for group '. $ops_group);
178 $GLOBALS['ilLog']->write(__METHOD__.': New operation '.$ops);
179 $GLOBALS['ilLog']->write(__METHOD__.': New operation '. $ops_id);
180 }
181
182 }
183 }
184
185 return $this->getRole()->getId();
186 }
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getIdsForTitle($title, $type='', $partialmatch=false)
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $lng
Definition: privfeed.php:40

References $GLOBALS, $lng, $role, 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 215 of file class.ilRoleXmlImporter.php.

216 {
217 if($this->getRole())
218 {
219 return true;
220 }
221
222 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
223 include_once './Services/Object/classes/class.ilObjectFactory.php';
224 if($obj_id)
225 {
226 $this->role = ilObjectFactory::getInstanceByObjId($obj_id,false);
227 }
228 if(!$this->getRole() instanceof ilObjRole or !$this->getRole() instanceof ilObjRoleTemplate)
229 {
230 include_once './Services/AccessControl/classes/class.ilObjRoleTemplate.php';
231 $this->role = new ilObjRoleTemplate();
232 }
233 return true;
234 }
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)

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

237 {
238 $errors = '';
239
240 foreach(libxml_get_errors() as $err)
241 {
242 $errors .= $err->code.'<br/>';
243 }
244 return $errors;
245 }
$errors

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: