ILIAS  release_8 Revision v8.24
class.ilRbacLogTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 protected array $operations = [];
30 protected array $filter = [];
31 protected array $action_map = [];
32 private int $ref_id;
33
34 public function __construct(object $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
35 {
36 global $DIC;
37
38 $this->setId("rbaclog");
39 $this->ref_id = $a_ref_id;
40
41 parent::__construct($a_parent_obj, $a_parent_cmd);
42 $this->setTitle($this->lng->txt("rbac_log"));
43 $this->setLimit(5);
44
45 $this->addColumn($this->lng->txt("date"), "", "15%");
46 $this->addColumn($this->lng->txt("name"), "", "10%");
47 $this->addColumn($this->lng->txt("login"), "", "10%");
48 $this->addColumn($this->lng->txt("action"), "", "15%");
49 $this->addColumn($this->lng->txt("rbac_changes"), "", "50%");
50
51 $this->setExternalSegmentation(true);
52 $this->setEnableHeader(true);
53 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
54 $this->setRowTemplate("tpl.rbac_log_row.html", "Services/AccessControl");
55 $this->setFilterCommand("applyLogFilter");
56 $this->setResetCommand("resetLogFilter");
57
58 $this->action_map = array(ilRbacLog::EDIT_PERMISSIONS => $this->lng->txt("rbac_log_edit_permissions"),
59 ilRbacLog::MOVE_OBJECT => $this->lng->txt("rbac_log_move_object"),
60 ilRbacLog::LINK_OBJECT => $this->lng->txt("rbac_log_link_object"),
61 ilRbacLog::COPY_OBJECT => $this->lng->txt("rbac_log_copy_object"),
62 ilRbacLog::CREATE_OBJECT => $this->lng->txt("rbac_log_create_object"),
63 ilRbacLog::EDIT_TEMPLATE => $this->lng->txt("rbac_log_edit_template"),
64 ilRbacLog::EDIT_TEMPLATE_EXISTING => $this->lng->txt("rbac_log_edit_template_existing"),
65 ilRbacLog::CHANGE_OWNER => $this->lng->txt("rbac_log_change_owner")
66 );
67
68 $this->initFilter();
69 $this->getItems($this->ref_id, $this->filter);
70 }
71
72 public function initFilter(): void
73 {
75 $item->setOptions(array("" => $this->lng->txt("all")) + $this->action_map);
76 $this->filter["action"] = $item->getValue();
77
79 $this->filter["date"] = $item->getDate();
80 }
81
82 protected function getItems(int $a_ref_id, array $a_current_filter = null): void
83 {
84 global $DIC;
85
86 $rbacreview = $DIC['rbacreview'];
87
89
90 foreach ($rbacreview->getOperations() as $op) {
91 $this->operations[$op["ops_id"]] = $op["operation"];
92 }
93
94 // special case: role folder should display root folder entries
95 if ($a_ref_id == ROLE_FOLDER_ID) {
96 $a_ref_id = ROOT_FOLDER_ID;
97 }
98
99 $data = ilRbacLog::getLogItems($a_ref_id, $this->getLimit(), $this->getOffset(), $a_current_filter);
100
101 $this->setData($data["set"]);
102 $this->setMaxCount((int) $data["cnt"]);
103 }
104
105 protected function fillRow(array $a_set): void
106 {
107 $this->tpl->setVariable("DATE", ilDatePresentation::formatDate(new ilDateTime($a_set["created"] ?? 0, IL_CAL_UNIX)));
108 $name = ilObjUser::_lookupName((int) ($a_set["user_id"]) ?? 0);
109 $this->tpl->setVariable("LASTNAME", $name["lastname"] ?? '');
110 $this->tpl->setVariable("FIRSTNAME", $name["firstname"] ?? '');
111 $this->tpl->setVariable("LOGIN", $name["login"] ?? '');
112 $this->tpl->setVariable("ACTION", $this->action_map[$a_set["action"]] ?? '');
113
114 if ($a_set["action"] == ilRbacLog::CHANGE_OWNER) {
115 $user = ilObjUser::_lookupFullname($a_set["data"][0] ?? 0);
116 $changes = array(array("action" => $this->lng->txt("rbac_log_changed_owner"), "operation" => $user));
117 } elseif ($a_set["action"] == ilRbacLog::EDIT_TEMPLATE) {
118 $changes = $this->parseChangesTemplate($a_set["data"] ?? []);
119 } else {
120 $changes = $this->parseChangesFaPa($a_set["data"] ?? []);
121 }
122
123 $this->tpl->setCurrentBlock("changes");
124 foreach ($changes as $change) {
125 $this->tpl->setVariable("CHANGE_ACTION", $change["action"] ?? '');
126 $this->tpl->setVariable("CHANGE_OPERATION", $change["operation"] ?? '');
127 $this->tpl->parseCurrentBlock();
128 }
129 }
130
131 protected function parseChangesFaPa(array $raw): array
132 {
133 $result = array();
134
135 $type = ilObject::_lookupType($this->ref_id, true);
136
137 if (isset($raw["src"]) && is_numeric($raw['src'])) {
138 $obj_id = ilObject::_lookupObjectId($raw["src"]);
139 if ($obj_id) {
140 $result[] = array("action" => $this->lng->txt("rbac_log_source_object"),
141 "operation" => "<a href=\"" . ilLink::_getLink($raw["src"]) . "\">" . ilObject::_lookupTitle($obj_id) . "</a>"
142 );
143 }
144
145 // added only
146 foreach ($raw["ops"] as $role_id => $ops) {
147 foreach ($ops as $op) {
148 $result[] = ["action" => sprintf($this->lng->txt("rbac_log_operation_add"), ilObjRole::_getTranslation(ilObject::_lookupTitle((int) $role_id))),
149 "operation" => $this->getOPCaption($type, $op)];
150 }
151 }
152 } elseif (isset($raw["ops"])) {
153 foreach ($raw["ops"] as $role_id => $actions) {
154 foreach ($actions as $action => $ops) {
155 foreach ((array) $ops as $op) {
156 $result[] = ["action" => sprintf($this->lng->txt("rbac_log_operation_" . $action), ilObjRole::_getTranslation(ilObject::_lookupTitle((int) $role_id))),
157 "operation" => $this->getOPCaption($type, $op)];
158 }
159 }
160 }
161 }
162
163 if (isset($raw["inht"])) {
164 foreach ($raw["inht"] as $action => $role_ids) {
165 foreach ((array) $role_ids as $role_id) {
166 $result[] = array("action" => sprintf($this->lng->txt("rbac_log_inheritance_" . $action), ilObjRole::_getTranslation(ilObject::_lookupTitle((int) $role_id))));
167 }
168 }
169 }
170
171 return $result;
172 }
173
174 protected function parseChangesTemplate(array $raw): array
175 {
176 $result = array();
177 foreach ($raw as $type => $actions) {
178 foreach ($actions as $action => $ops) {
179 foreach ($ops as $op) {
180 $result[] = array("action" => sprintf(
181 $this->lng->txt("rbac_log_operation_" . $action),
182 $this->lng->txt("obj_" . $type)
183 ),
184 "operation" => $this->getOPCaption($type, $op)
185 );
186 }
187 }
188 }
189 return $result;
190 }
191
195 protected function getOPCaption(string $a_type, $a_op): string
196 {
197 // #11717
198 if (is_array($a_op)) {
199 $res = array();
200 foreach ($a_op as $op) {
201 $res[] = $this->getOPCaption($a_type, $op);
202 }
203 return implode(", ", $res);
204 }
205
206 if (is_numeric($a_op) && isset($this->operations[$a_op])) {
207 $op_id = $this->operations[$a_op];
208 if (substr($op_id, 0, 7) != "create_") {
209 $perm = $this->getTranslationFromPlugin($a_type, $op_id);
210
211 if ($this->notTranslated($perm, $op_id)) {
212 if ($this->lng->exists($a_type . '_' . $op_id . '_short')) {
213 $perm = $this->lng->txt($a_type . '_' . $op_id . '_short');
214 } else {
215 $perm = $this->lng->txt($op_id);
216 }
217 }
218
219 return $perm;
220 } else {
221 $type = substr($op_id, 7, strlen($op_id));
222 $perm = $this->getTranslationFromPlugin($type, $op_id);
223
224 if ($this->notTranslated($perm, $op_id)) {
225 $perm = $this->lng->txt("rbac_" . $op_id);
226 }
227
228 return $perm;
229 }
230 }
231 return '';
232 }
233
237 protected function getTranslationFromPlugin(string $type, string $op_id): ?string
238 {
239 global $objDefinition;
240
241 if ($objDefinition->isPlugin($type)) {
242 return ilObjectPlugin::lookupTxtById($type, $op_id);
243 }
244 return null;
245 }
246
250 protected function notTranslated(?string $perm, string $op_id): bool
251 {
252 return is_null($perm) || (strpos($perm, $op_id) !== false);
253 }
254}
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
static _getTranslation(string $a_role_title)
static _lookupFullname(int $a_user_id)
static _lookupName(int $a_user_id)
lookup user name
static lookupTxtById(string $plugin_id, string $lang_var)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
Class ilRbacLogTableGUI.
notTranslated(?string $perm, string $op_id)
Check the op is translated correctly.
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
getTranslationFromPlugin(string $type, string $op_id)
Check the type for plugin and get the translation for op_id.
getItems(int $a_ref_id, array $a_current_filter=null)
getOPCaption(string $a_type, $a_op)
const EDIT_PERMISSIONS
const COPY_OBJECT
static getLogItems(int $a_ref_id, int $a_limit, int $a_offset, array $a_filter=null)
const MOVE_OBJECT
const EDIT_TEMPLATE_EXISTING
const CHANGE_OWNER
const LINK_OBJECT
const EDIT_TEMPLATE
const CREATE_OBJECT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFilterCommand(string $a_val, string $a_caption="")
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
determineOffsetAndOrder(bool $a_omit_offset=false)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExternalSegmentation(bool $a_val)
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
const ROLE_FOLDER_ID
Definition: constants.php:34
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type