19 declare(strict_types=1);
33 protected string $xml =
'';
45 $this->
logger = $DIC->logger()->ac();
46 $this->rbacreview = $DIC->rbac()->review();
47 $this->rbacadmin = $DIC->rbac()->admin();
51 $this->role_folder = $a_role_folder_id;
54 public function setXml(
string $a_xml): void
83 public function import():
void 85 $use_internal_errors = libxml_use_internal_errors(
true);
86 $root = simplexml_load_string($this->
getXml());
87 libxml_use_internal_errors($use_internal_errors);
92 foreach ($root->role as $roleElement) {
101 $import_id = (string) $role[
'id'];
102 $this->
logger->info(
'Importing role with import_id: ' . $import_id);
105 $trafo = $this->
refinery->in()->series([
106 $this->
refinery->kindlyTo()->string(),
107 $this->
refinery->string()->stripTags()
110 $this->
getRole()->setTitle($trafo->transform($role->title ??
''));
111 $this->
getRole()->setDescription($trafo->transform($role->description ??
''));
113 $this->
logger->info(
'Current role import id: ' . $this->
getRole()->getImportId());
118 if (count($exp) > 0 && $exp[0] ===
"il") {
119 if (count($exp) > 1 && $exp[1] !== $type) {
121 $this->
language->txt(
"rbac_cant_import_role_wrong_type"),
122 $this->
language->txt(
'obj_' . $exp[1]),
123 $this->
language->txt(
'obj_' . $type)
147 $protected = (string) $role[
'protected'];
149 $this->rbacadmin->setProtected(0, $this->
getRole()->
getId(),
'y');
153 $ops = $this->rbacreview->getOperations();
155 foreach ($ops as $ope) {
156 $operations[$ope[
'operation']] = $ope[
'ops_id'];
159 foreach ($role->operations as $sxml_operations) {
160 foreach ($sxml_operations as $sxml_op) {
161 $operation = trim((
string) $sxml_op);
162 if (!array_key_exists($operation, $operations)) {
165 $ops_group = (string) $sxml_op[
'group'];
166 $ops_id = (
int) $operations[$operation];
169 if ($ops_group && $ops_id) {
170 $this->rbacadmin->setRolePermission(
179 return $this->
getRole()->getId();
188 if ($this->rbacreview->isRoleAssignedToObject($this->getRole()->getId(), $this->
getRoleFolderId())) {
192 $this->rbacadmin->assignRoleToFolder(
199 protected function initRole(
string $import_id): void
205 $this->
logger->debug(
'Searching already imported role by import_id: ' . $import_id);
210 $this->
logger->debug(
'Found already imported obj_id: ' . $obj_id);
219 $this->
logger->debug(
'Creating new role template');
220 $this->role =
new ilObjRoleTemplate();
222 $this->role->setImportId($import_id);
229 foreach (libxml_get_errors() as $err) {
230 $errors .= $err->code .
'<br/>';
importSimpleXml(SimpleXMLElement $role)
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
__construct(int $a_role_folder_id=0)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _getIdsForTitle(string $title, string $type='', bool $partial_match=false)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
initRole(string $import_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
language()
description: > Example for rendring a language glyph.
Class ilRbacAdmin Core functions for role based access control.
static _lookupType(int $id, bool $reference=false)