ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDidacticTemplateLocalRoleAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 private int $role_template_id = 0;
28
29 public function __construct(int $a_action_id = 0)
30 {
31 parent::__construct($a_action_id);
32 }
33
34 public function getType(): int
35 {
37 }
38
39 public function setRoleTemplateId(int $a_role_template_id): void
40 {
41 $this->role_template_id = $a_role_template_id;
42 }
43
44 public function getRoleTemplateId(): int
45 {
47 }
48
49 public function apply(): bool
50 {
51 $source = $this->initSourceObject();
52
53 $role = new ilObjRole();
54 $role->setTitle(ilObject::_lookupTitle($this->getRoleTemplateId()) . '_' . $this->getRefId());
55 $role->setDescription(ilObject::_lookupDescription($this->getRoleTemplateId()));
56 $role->create();
57 $this->admin->assignRoleToFolder($role->getId(), $source->getRefId(), "y");
58 $this->logger->info(
59 'Using rolt: ' .
60 $this->getRoleTemplateId() .
61 ' with title "' .
63 '". '
64 );
65
66 // Copy template permissions
67
68 $this->logger->debug(
69 'Copy role template permissions ' .
70 'tpl_id: ' . $this->getRoleTemplateId() . ' ' .
71 'parent: ' . ROLE_FOLDER_ID . ' ' .
72 'role_id: ' . $role->getId() . ' ' .
73 'role_parent: ' . $source->getRefId()
74 );
75
76 $this->admin->copyRoleTemplatePermissions(
77 $this->getRoleTemplateId(),
79 $source->getRefId(),
80 $role->getId(),
81 true
82 );
83 // Set permissions
84 $ops = $this->review->getOperationsOfRole($role->getId(), $source->getType(), $source->getRefId());
85 $this->admin->grantPermission($role->getId(), $ops, $source->getRefId());
86
87 return true;
88 }
89
90 public function revert(): bool
91 {
92 // @todo: revert could delete the generated local role. But on the other hand all users
93 // assigned to this local role would be deassigned. E.g. if course or group membership
94 // is handled by didactic templates, all members would get lost.
95 return false;
96 }
97
98 public function save(): int
99 {
100 if (!parent::save()) {
101 return 0;
102 }
103
104 $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) ' .
105 'VALUES ( ' .
106 $this->db->quote($this->getActionId(), 'integer') . ', ' .
107 $this->db->quote($this->getRoleTemplateId(), 'integer') . ' ' .
108 ') ';
109 $res = $this->db->manipulate($query);
110
111 return $this->getActionId();
112 }
113
114 public function delete(): void
115 {
116 parent::delete();
117
118 $query = 'DELETE FROM didactic_tpl_alr ' .
119 'WHERE action_id = ' . $this->db->quote($this->getActionId(), 'integer');
120 $this->db->manipulate($query);
121 }
122
123 public function toXml(ilXmlWriter $writer): void
124 {
125 $writer->xmlStartTag('localRoleAction');
126
127 $il_id = 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->getRoleTemplateId()) . '_' . $this->getRoleTemplateId();
128
129 $writer->xmlStartTag(
130 'roleTemplate',
131 [
132 'id' => $il_id
133 ]
134 );
135
136 $exp = new ilRoleXmlExport();
137 $exp->setMode(ilRoleXmlExport::MODE_DTPL);
138 $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
139 $exp->write();
140 $writer->appendXML($exp->xmlDumpMem(false));
141 $writer->xmlEndTag('roleTemplate');
142 $writer->xmlEndTag('localRoleAction');
143 }
144
145 public function read(): void
146 {
147 parent::read();
148 $query = 'SELECT * FROM didactic_tpl_alr ' .
149 'WHERE action_id = ' . $this->db->quote($this->getActionId(), 'integer');
150 $res = $this->db->query($query);
151 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
152 $this->setRoleTemplateId((int) $row->role_template_id);
153 }
154 }
155}
Abstract class for template actions.
represents a creation of local roles action
save()
Write action to db Overwrite for filling additional db fields.
revert()
Implement everthing that is necessary to revert a didactic template return bool.
Class ilObjRole.
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
Xml export of roles and role templates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
appendXML(string $a_str)
append xml string to document
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const IL_INST_ID
Definition: constants.php:40
const ROLE_FOLDER_ID
Definition: constants.php:34
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc