19 declare(strict_types=1);
55 $this->pattern = $patterns;
69 $this->filter_type = $a_type;
79 $this->role_template_type = $a_tpl_type;
89 $this->role_template_id = $a_id;
99 if (!parent::save()) {
103 $query =
'INSERT INTO didactic_tpl_alp (action_id,filter_type,template_type,template_id) ' .
105 $this->db->quote($this->
getActionId(),
'integer') .
', ' .
110 $this->db->manipulate($query);
115 $pattern->setParentType(self::PATTERN_PARENT_TYPE);
122 public function delete():
void 125 $query =
'DELETE FROM didactic_tpl_alp ' .
126 'WHERE action_id = ' . $this->db->quote($this->
getActionId(),
'integer');
127 $this->db->manipulate($query);
141 foreach ($roles as $role_id => $role) {
142 $this->
getLogger()->debug(
'Apply to role: ' . $role[
'title']);
143 $this->
getLogger()->debug(
'Role parent: ' . $role[
'parent']);
144 $this->
getLogger()->debug(
'Source ref_id: ' . $source->getRefId());
148 (
int) $role[
'parent'] !== $source->getRefId() &&
149 $this->review->isProtected($role[
'parent'], $role_id)
151 $this->
getLogger()->debug(
'Ignoring protected role.');
166 foreach ($roles as $role_id => $role) {
168 if (!$this->review->isGlobalRole($role[
'obj_id']) &&
169 $this->review->isAssignable($role[
'obj_id'], $source->getRefId()) &&
170 $this->review->isSystemGeneratedRole($role[
'obj_id'])) {
171 $this->
getLogger()->debug(
'Reverting local policy of auto generated role: ' . $role[
'title']);
174 $this->
getLogger()->debug(
'Reverting local policy and deleting local role: ' . $role[
'title']);
177 $this->admin->deleteLocalRole($role_id, $source->getRefId());
182 $protected = $this->review->isProtected($role[
'parent'], $role[
'rol_id']);
184 $role_obj->changeExistingObjects(
199 return self::TYPE_LOCAL_POLICY;
207 case self::FILTER_SOURCE_OBJ_ID:
208 $writer->
xmlStartTag(
'roleFilter', [
'source' =>
'objId']);
211 case self::FILTER_PARENT_ROLES:
212 $writer->
xmlStartTag(
'roleFilter', [
'source' =>
'parentRoles']);
215 case self::FILTER_LOCAL_ROLES:
216 $writer->
xmlStartTag(
'roleFilter', [
'source' =>
'localRoles']);
219 case self::FILTER_SOURCE_TITLE:
221 $writer->
xmlStartTag(
'roleFilter', [
'source' =>
'title']);
226 $pattern->toXml($writer);
233 case self::TPL_ACTION_OVERWRITE:
235 'localPolicyTemplate',
237 'type' =>
'overwrite',
243 case self::TPL_ACTION_INTERSECT:
245 'localPolicyTemplate',
247 'type' =>
'intersect',
253 case self::TPL_ACTION_UNION:
255 'localPolicyTemplate',
268 $writer->
appendXML($exp->xmlDumpMem(
false));
269 $writer->
xmlEndTag(
'localPolicyTemplate');
287 $query =
'SELECT * FROM didactic_tpl_alp ' .
289 $res = $this->db->query($query);
298 self::PATTERN_PARENT_TYPE
308 foreach ($this->review->getParentRoleIds($source->
getRefId()) as $role_id => $tmp_role) {
309 if ((
int) $role_id === (
int) $role[
'obj_id']) {
310 $role_data = $tmp_role;
315 if (!$this->review->isRoleAssignedToObject((
int) $role[
'obj_id'], $source->
getRefId())) {
316 $this->admin->assignRoleToFolder(
317 (
int) $role[
'obj_id'],
325 (
int) $role[
'parent'] !== $source->
getRefId() &&
326 $this->review->isProtected($source->
getRefId(), (
int) $role[
'obj_id'])
328 $this->
getLogger()->info(
'Ignoring protected role: ' . $role[
'title']);
333 case self::TPL_ACTION_UNION:
335 $this->
logger->info(
'Using ilRbacAdmin::copyRolePermissionUnion()');
336 $this->admin->copyRolePermissionUnion(
337 (
int) $role_data[
'obj_id'],
338 (
int) $role_data[
'parent'],
341 (
int) $role_data[
'obj_id'],
346 case self::TPL_ACTION_OVERWRITE:
348 $this->
logger->info(
'Using ilRbacAdmin::copyRoleTemplatePermission()');
349 $this->admin->copyRoleTemplatePermissions(
353 (
int) $role_data[
'obj_id'],
358 case self::TPL_ACTION_INTERSECT:
361 $this->admin->copyRolePermissionIntersection(
362 (
int) $role_data[
'obj_id'],
363 (
int) $role_data[
'parent'],
367 (
int) $role_data[
'obj_id']
372 $role_obj =
new ilObjRole((
int) $role_data[
'obj_id']);
373 $role_obj->changeExistingObjects(
384 $this->
logger->info(
'Reverting policy for role ' . $role[
'title']);
387 if (strpos($role[
'title'],
'il_') !== 0) {
388 $this->
logger->warning(
'Cannot revert local policy for role ' . $role[
'title']);
393 if (!$this->review->getLocalPolicies($source->
getRefId())) {
397 $exploded_title = explode(
'_', $role[
'title']);
398 $rolt_title = $exploded_title[0] .
'_' . $exploded_title[1] .
'_' . $exploded_title[2];
401 $query =
'SELECT obj_id FROM object_data ' .
402 'WHERE title = ' . $this->db->quote($rolt_title,
'text') .
' ' .
403 'AND type = ' . $this->db->quote(
'rolt',
'text');
404 $res = $this->db->query($query);
407 $rolt_id = (
int) $row->obj_id;
415 $this->admin->copyRoleTemplatePermissions(
419 (
int) $role[
'obj_id'],
424 $role_obj =
new ilObjRole((
int) $role[
'obj_id']);
425 $role_obj->changeExistingObjects(
const MODE_PROTECTED_DELETE_LOCAL_POLICIES
const TPL_ACTION_INTERSECT
const TPL_ACTION_SUBTRACT
appendXML(string $a_str)
append xml string to document
toXml(ilXmlWriter $writer)
const TPL_ACTION_OVERWRITE
getFilterPattern()
Get filter pattern.
xmlEndTag(string $tag)
Writes an endtag.
addFilterPattern(ilDidacticTemplateFilterPattern $pattern)
filterRoles(ilObject $source)
__construct(int $action_id=0)
setFilterType(int $a_type)
createLocalPolicy(ilObject $source, array $role)
revertLocalPolicy(ilObject $source, array $role)
Abstract class for template actions.
static lookupPatternsByParentId(int $a_parent_id, string $a_parent_type)
const MODE_UNPROTECTED_DELETE_LOCAL_POLICIES
__construct(Container $dic, ilPlugin $plugin)
Xml export of roles and role templates.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
setFilterPatterns(array $patterns)
Set filter patterns.
static _lookupType(int $id, bool $reference=false)
Represents a filter pattern for didactic template actions.
setRoleTemplateId(int $a_id)
setRoleTemplateType(int $a_tpl_type)