4 include_once
'./Services/AccessControl/exceptions/class.ilRoleImporterException.php';
36 $this->logger = $DIC->logger()->otpl();
37 $this->role_folder = $a_role_folder_id;
38 $this->refinery = $DIC[
'refinery'];
82 public function import()
84 libxml_use_internal_errors(
true);
86 $root = simplexml_load_string($this->
getXml());
88 if (!$root instanceof SimpleXMLElement) {
91 foreach ($root->role as $roleElement) {
107 $rbacadmin = $DIC[
'rbacadmin'];
108 $rbacreview = $DIC[
'rbacreview'];
111 $import_id = (string) $role[
'id'];
112 $this->logger->info(
'Importing role with import_id: ' . $import_id);
118 $trafo = $this->refinery->in()->series([
119 $this->refinery->kindlyTo()->string(),
120 $this->refinery->string()->stripTags()
123 $this->
getRole()->setTitle($trafo->transform($role->title ??
''));
124 $this->
getRole()->setDescription($trafo->transform($role->description ??
''));
126 $this->logger->info(
'Current role import id: ' . $this->
getRole()->getImportId());
129 $exp = explode(
"_", $this->
getRole()->getTitle());
131 if (count($exp) > 0 && $exp[0] ===
"il") {
132 if (count($exp) > 1 && $exp[1] !==
$type) {
134 $lng->txt(
"rbac_cant_import_role_wrong_type"),
135 $lng->txt(
'obj_' . $exp[1]),
145 $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ .
': Overwrite role ' . implode(
"_", $exp));
146 $this->
getRole()->setId($id[0]);
152 if ($this->
getRole()->getId()) {
160 $this->assignToRoleFolder();
162 $protected = (string) $role[
'protected'];
164 $rbacadmin->setProtected(0, $this->
getRole()->getId(),
'y');
168 $ops = $rbacreview->getOperations();
169 $operations = array();
170 foreach ($ops as $ope) {
171 $operations[$ope[
'operation']] = $ope[
'ops_id'];
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)) {
180 $ops_group = (string) $sxml_op[
'group'];
181 $ops_id = (int) $operations[$operation];
182 $ops = trim((
string) $sxml_op);
184 if ($ops_group and $ops_id) {
185 $rbacadmin->setRolePermission(
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);
200 return $this->
getRole()->getId();
212 $rbacadmin = $DIC[
'rbacadmin'];
213 $rbacreview = $DIC[
'rbacreview'];
219 if ($rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->
getRoleFolderId())) {
223 $rbacadmin->assignRoleToFolder(
237 $this->logger->debug(
'Searching already imported role by import_id: ' . $import_id);
242 $this->logger->debug(
'Found already imported obj_id: ' . $obj_id);
252 $this->logger->debug(
'Creating new role template');
253 $this->role =
new ilObjRoleTemplate();
255 $this->role->setImportId((
string) $import_id);
263 foreach (libxml_get_errors() as $err) {
264 $errors .= $err->code .
'<br/>';
importSimpleXml(SimpleXMLElement $role)
Import using simplexml.
setRole(ilObject $role)
Set role or role template.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType($a_id, $a_reference=false)
lookup object type
getRoleFolderId()
Get role folder id.
static _getIdsForTitle($title, $type='', $partialmatch=false)
__construct($a_role_folder_id=0)
Constructor.
static _lookupObjIdByImportId($a_import_id)
assigntoRoleFolder()
Assign role to folder type $rbacadmin.