ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilRbacLogTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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 = [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  {
74  $item = $this->addFilterItemByMetaType('action', ilTable2GUI::FILTER_SELECT);
75  $item->setOptions(['' => $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 
88  $this->determineOffsetAndOrder();
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 = [['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 = [];
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[] = [
141  'action' => $this->lng->txt('rbac_log_source_object'),
142  'operation' => '<a href="' . ilLink::_getLink($raw['src']) . '">' . ilObject::_lookupTitle($obj_id) . '</a>'
143  ];
144  }
145 
146  // added only
147  foreach ($raw['ops'] as $role_id => $ops) {
148  foreach ($ops as $op) {
149  $result[] = [
150  'action' => sprintf(
151  $this->lng->txt('rbac_log_operation_add'),
153  ),
154  'operation' => $this->getOPCaption($type, $op)
155  ];
156  }
157  }
158  } elseif (isset($raw['ops'])) {
159  foreach ($raw['ops'] as $role_id => $actions) {
160  foreach ($actions as $action => $ops) {
161  foreach ((array) $ops as $op) {
162  $result[] = [
163  'action' => sprintf(
164  $this->lng->txt('rbac_log_operation_' . $action),
166  ),
167  'operation' => $this->getOPCaption($type, $op)
168  ];
169  }
170  }
171  }
172  }
173 
174  if (isset($raw['inht'])) {
175  foreach ($raw['inht'] as $action => $role_ids) {
176  foreach ((array) $role_ids as $role_id) {
177  $result[] = [
178  'action' => sprintf(
179  $this->lng->txt('rbac_log_inheritance_' . $action),
181  )
182  ];
183  }
184  }
185  }
186 
187  return $result;
188  }
189 
190  protected function parseChangesTemplate(array $raw): array
191  {
192  $result = [];
193  foreach ($raw as $type => $actions) {
194  foreach ($actions as $action => $ops) {
195  foreach ($ops as $op) {
196  $result[] = ['action' => sprintf(
197  $this->lng->txt('rbac_log_operation_' . $action),
198  $this->lng->txt('obj_' . $type)
199  ),
200  'operation' => $this->getOPCaption($type, $op)
201  ];
202  }
203  }
204  }
205  return $result;
206  }
207 
211  protected function getOPCaption(string $a_type, $a_op): string
212  {
213  // #11717
214  if (is_array($a_op)) {
215  $res = [];
216  foreach ($a_op as $op) {
217  $res[] = $this->getOPCaption($a_type, $op);
218  }
219  return implode(', ', $res);
220  }
221 
222  if (is_numeric($a_op) && isset($this->operations[$a_op])) {
223  $op_id = $this->operations[$a_op];
224  if (substr($op_id, 0, 7) != 'create_') {
225  $perm = $this->getTranslationFromPlugin($a_type, $op_id);
226 
227  if ($this->notTranslated($perm, $op_id)) {
228  if ($this->lng->exists($a_type . '_' . $op_id . '_short')) {
229  $perm = $this->lng->txt($a_type . '_' . $op_id . '_short');
230  } else {
231  $perm = $this->lng->txt($op_id);
232  }
233  }
234 
235  return $perm;
236  } else {
237  $type = substr($op_id, 7, strlen($op_id));
238  $perm = $this->getTranslationFromPlugin($type, $op_id);
239 
240  if ($this->notTranslated($perm, $op_id)) {
241  $perm = $this->lng->txt('rbac_' . $op_id);
242  }
243 
244  return $perm;
245  }
246  }
247  return '';
248  }
249 
253  protected function getTranslationFromPlugin(string $type, string $op_id): ?string
254  {
255  global $objDefinition;
256 
257  if ($objDefinition->isPlugin($type)) {
258  return ilObjectPlugin::lookupTxtById($type, $op_id);
259  }
260  return null;
261  }
262 
266  protected function notTranslated(?string $perm, string $op_id): bool
267  {
268  return is_null($perm) || (strpos($perm, $op_id) !== false);
269  }
270 }
getItems(int $a_ref_id, array $a_current_filter=null)
setData(array $a_data)
$res
Definition: ltiservices.php:69
setFormAction(string $a_form_action, bool $a_multipart=false)
const ROOT_FOLDER_ID
Definition: constants.php:32
static _lookupFullname(int $a_user_id)
setResetCommand(string $a_val, string $a_caption="")
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const CHANGE_OWNER
static _lookupName(int $a_user_id)
lookup user name
static getLogItems(int $a_ref_id, int $a_limit, int $a_offset, array $a_filter=null)
getTranslationFromPlugin(string $type, string $op_id)
Check the type for plugin and get the translation for op_id.
const IL_CAL_UNIX
setId(string $a_val)
global $DIC
Definition: feed.php:28
const EDIT_PERMISSIONS
getOPCaption(string $a_type, $a_op)
const CREATE_OBJECT
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
static _getTranslation(string $a_role_title)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
static _lookupObjectId(int $ref_id)
const COPY_OBJECT
const LINK_OBJECT
const ROLE_FOLDER_ID
Definition: constants.php:34
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static lookupTxtById(string $plugin_id, string $lang_var)
Class ilRbacLogTableGUI.
setLimit(int $a_limit=0, int $a_default_limit=0)
const EDIT_TEMPLATE_EXISTING
notTranslated(?string $perm, string $op_id)
Check the op is translated correctly.
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)
const EDIT_TEMPLATE
const MOVE_OBJECT
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static _lookupType(int $id, bool $reference=false)
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)
setMaxCount(int $a_max_count)
set max.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
setExternalSegmentation(bool $a_val)