4 include_once
'./Services/AccessControl/exceptions/class.ilRoleImporterException.php';
31 $this->logger = $DIC->logger()->otpl();
32 $this->role_folder = $a_role_folder_id;
76 public function import()
78 libxml_use_internal_errors(
true);
80 $root = simplexml_load_string($this->
getXml());
82 if (!$root instanceof SimpleXMLElement) {
85 foreach ($root->role as $roleElement) {
101 $rbacadmin = $DIC[
'rbacadmin'];
102 $rbacreview = $DIC[
'rbacreview'];
105 $import_id = (string) $role[
'id'];
106 $this->logger->info(
'Importing role with import_id: ' . $import_id);
112 $this->
getRole()->setTitle(trim((
string) $role->title));
113 $this->
getRole()->setDescription(trim((
string) $role->description));
115 $this->logger->info(
'Current role import id: ' . $this->
getRole()->getImportId());
118 $exp = explode(
"_", $this->
getRole()->getTitle());
120 if (count($exp) > 0 && $exp[0] ===
"il") {
121 if (count($exp) > 1 && $exp[1] !==
$type) {
123 $lng->txt(
"rbac_cant_import_role_wrong_type"),
124 $lng->txt(
'obj_' . $exp[1]),
134 $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ .
': Overwrite role ' . implode(
"_", $exp));
135 $this->
getRole()->setId($id[0]);
141 if ($this->
getRole()->getId()) {
149 $this->assignToRoleFolder();
151 $protected = (string) $role[
'protected'];
153 $rbacadmin->setProtected(0, $this->
getRole()->getId(),
'y');
157 $ops = $rbacreview->getOperations();
158 $operations = array();
159 foreach ($ops as $ope) {
160 $operations[$ope[
'operation']] = $ope[
'ops_id'];
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);
169 if ($ops_group and $ops_id) {
170 $rbacadmin->setRolePermission(
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);
185 return $this->
getRole()->getId();
197 $rbacadmin = $DIC[
'rbacadmin'];
198 $rbacreview = $DIC[
'rbacreview'];
204 if ($rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->
getRoleFolderId())) {
208 $rbacadmin->assignRoleToFolder(
222 $this->logger->debug(
'Searching already imported role by import_id: ' . $import_id);
227 $this->logger->debug(
'Found already imported obj_id: ' . $obj_id);
237 $this->logger->debug(
'Creating new role template');
238 $this->role =
new ilObjRoleTemplate();
240 $this->role->setImportId((
string) $import_id);
248 foreach (libxml_get_errors() as $err) {
249 $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.