ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjLoggingSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
23 
33 {
34  protected const SECTION_SETTINGS = 'settings';
35  protected const SUB_SECTION_MAIN = 'log_general_settings';
36  protected const SUB_SECTION_COMPONENTS = 'log_components';
37  protected const SUB_SECTION_ERROR = 'log_error_settings';
38 
40  protected ilLogger $log;
42  protected Refinery $refinery;
43 
49  public function __construct($a_data, int $a_id, bool $a_call_by_reference, bool $a_prepare_output = true)
50  {
51  global $DIC;
52 
53  $this->type = 'logs';
54  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
55 
56  $this->lng = $DIC->language();
57 
58  $this->initSettings();
59  $this->initErrorSettings();
60  $this->lng->loadLanguageModule('logging');
61  $this->lng->loadLanguageModule('log');
62  $this->log = ilLoggerFactory::getLogger('log');
63 
64  $this->refinery = $DIC->refinery();
65  }
66 
67  public function getLogger(): ilLogger
68  {
69  return $this->log;
70  }
71 
72  public function executeCommand(): void
73  {
74  $next_class = $this->ctrl->getNextClass($this);
75  $cmd = $this->ctrl->getCmd();
76  $this->prepareOutput();
77 
78  switch ($next_class) {
79  case 'ilpermissiongui':
80  $this->tabs_gui->setTabActive('perm_settings');
81  $perm_gui = new ilPermissionGUI($this);
82  $this->ctrl->forwardCommand($perm_gui);
83  break;
84 
85  default:
86  if ($cmd == "" || $cmd == "view") {
87  $cmd = "settings";
88  }
89  $this->$cmd();
90 
91  break;
92  }
93  }
94 
95 
96  public function getAdminTabs(): void
97  {
98  if ($this->access->checkAccess("read", '', $this->object->getRefId())) {
99  $this->tabs_gui->addTarget(
100  static::SECTION_SETTINGS,
101  $this->ctrl->getLinkTargetByClass('ilobjloggingsettingsgui', "settings")
102  );
103  }
104  if ($this->access->checkAccess('edit_permission', '', $this->object->getRefId())) {
105  $this->tabs_gui->addTarget(
106  "perm_settings",
107  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
108  );
109  }
110  }
111 
112  public function setSubTabs(string $a_section): void
113  {
114  $this->tabs_gui->addSubTab(
115  static::SUB_SECTION_MAIN,
116  $this->lng->txt(static::SUB_SECTION_MAIN),
117  $this->ctrl->getLinkTarget($this, 'settings')
118  );
119  $this->tabs_gui->addSubTab(
120  static::SUB_SECTION_ERROR,
121  $this->lng->txt(static::SUB_SECTION_ERROR),
122  $this->ctrl->getLinkTarget($this, 'errorSettings')
123  );
124  $this->tabs_gui->addSubTab(
125  static::SUB_SECTION_COMPONENTS,
126  $this->lng->txt(static::SUB_SECTION_COMPONENTS),
127  $this->ctrl->getLinkTarget($this, 'components')
128  );
129  $this->tabs_gui->activateSubTab($a_section);
130  }
131 
132  protected function initSettings()
133  {
134  $this->log_settings = ilLoggingDBSettings::getInstance();
135  }
136 
137  public function getSettings(): ilLoggingDBSettings
138  {
139  return $this->log_settings;
140  }
141 
142  public function settings(?ilPropertyFormGUI $form = null)
143  {
144  if (!$this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
145  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
146  }
147 
148  $this->tabs_gui->setTabActive(static::SECTION_SETTINGS);
149  $this->setSubTabs(static::SUB_SECTION_MAIN);
150 
151  if (!$form instanceof ilPropertyFormGUI) {
152  $form = $this->initFormSettings();
153  }
154  $this->tpl->setContent($form->getHTML());
155  $this->getLogger()->debug('Currrent level is ' . $this->getSettings()->getLevel());
156  return true;
157  }
158 
159  public function updateSettings(): void
160  {
161  if (!$this->rbac_system->checkAccess('write', $this->object->getRefId())) {
162  $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
163  }
164  $form = $this->initFormSettings();
165  if ($form->checkInput()) {
166  $this->getSettings()->setLevel((int) $form->getInput('level'));
167  $this->getSettings()->enableCaching((bool) $form->getInput('cache'));
168  $this->getSettings()->setCacheLevel((int) $form->getInput('cache_level'));
169  $this->getSettings()->enableMemoryUsage((bool) $form->getInput('memory'));
170  $this->getSettings()->enableBrowserLog((bool) $form->getInput('browser'));
171  $this->getSettings()->setBrowserUsers($form->getInput('browser_users'));
172 
173  $this->getLogger()->info(print_r($form->getInput('browser_users'), true));
174 
175  $this->getSettings()->update();
176 
177  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
178  $this->ctrl->redirect($this, 'settings');
179  return;
180  }
181 
182  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
183  $form->setValuesByPost();
184  $this->settings($form);
185  }
186 
187  protected function initFormSettings(): ilPropertyFormGUI
188  {
189  $form = new ilPropertyFormGUI();
190  $form->setTitle($this->lng->txt('logs_settings'));
191  $form->setFormAction($this->ctrl->getFormAction($this));
192 
193  if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
194  $form->addCommandButton('updateSettings', $this->lng->txt('save'));
195  }
196 
197  $level = new ilSelectInputGUI($this->lng->txt('log_log_level'), 'level');
199  $level->setValue($this->getSettings()->getLevel());
200  $form->addItem($level);
201 
202  $cache = new ilCheckboxInputGUI($this->lng->txt('log_cache_'), 'cache');
203  $cache->setInfo($this->lng->txt('log_cache_info'));
204  $cache->setValue('1');
205  $cache->setChecked($this->getSettings()->isCacheEnabled());
206  $form->addItem($cache);
207 
208  $cache_level = new ilSelectInputGUI($this->lng->txt('log_cache_level'), 'cache_level');
209  $cache_level->setOptions(ilLogLevel::getLevelOptions());
210  $cache_level->setValue($this->getSettings()->getCacheLevel());
211  $cache->addSubItem($cache_level);
212 
213  $memory = new ilCheckboxInputGUI($this->lng->txt('log_memory'), 'memory');
214  $memory->setValue('1');
215  $memory->setChecked($this->getSettings()->isMemoryUsageEnabled());
216  $form->addItem($memory);
217 
218  // Browser handler
219  $browser = new ilCheckboxInputGUI($this->lng->txt('log_browser'), 'browser');
220  $browser->setValue('1');
221  $browser->setChecked($this->getSettings()->isBrowserLogEnabled());
222  $form->addItem($browser);
223 
224  // users
225  $users = new ilTextInputGUI($this->lng->txt('log_browser_users'), 'browser_users');
226  $users->setValue(current($this->getSettings()->getBrowserLogUsers()));
227  $users->setMulti(true);
228  $users->setMultiValues($this->getSettings()->getBrowserLogUsers());
229  $this->getLogger()->debug(print_r($this->getSettings()->getBrowserLogUsers(), true));
230  $browser->addSubItem($users);
231  return $form;
232  }
233 
234 
238  protected function components(): void
239  {
240  $this->tabs_gui->activateTab(static::SECTION_SETTINGS);
241  $this->setSubTabs(static::SUB_SECTION_COMPONENTS);
242 
243  $table = new ilLogComponentTableGUI($this, 'components');
244  $table->setEditable($this->checkPermissionBool('write'));
245  $table->init();
246  $table->parse();
247  $this->tpl->setContent($table->getHTML());
248  }
249 
253  protected function saveComponentLevels(): void
254  {
255  $this->checkPermission('write');
256 
257  $levels = [];
258  if ($this->http->wrapper()->post()->has('level')) {
259  $levels = $this->http->wrapper()->post()->retrieve(
260  'level',
261  $this->refinery->custom()->transformation(
262  function ($arr) {
263  // keep keys(!), transform all values to int
264  return array_column(
265  array_map(
266  static function ($k, $v): array {
267  return [$k, (int) $v];
268  },
269  array_keys($arr),
270  $arr
271  ),
272  1,
273  0
274  );
275  }
276  )
277  );
278  }
279  foreach ($levels as $component_id => $value) {
280  $level = new ilLogComponentLevel($component_id, $value);
281  $level->update();
282  }
283  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
284  $this->ctrl->redirect($this, 'components');
285  }
286 
287  protected function resetComponentLevels(): void
288  {
289  $this->checkPermission('write');
290  foreach (ilLogComponentLevels::getInstance()->getLogComponents() as $component) {
291  $component->setLevel(null);
292  $component->update();
293  }
294  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
295  $this->ctrl->redirect($this, 'components');
296  }
297 
298  protected function errorSettings(?ilPropertyFormGUI $form = null): void
299  {
300  $this->checkPermission('read');
301  $this->tabs_gui->setTabActive(static::SECTION_SETTINGS);
302  $this->setSubTabs(static::SUB_SECTION_ERROR);
303 
304  if (!$form instanceof ilPropertyFormGUI) {
305  $form = $this->initFormErrorSettings();
306  }
307  $this->tpl->setContent($form->getHTML());
308  }
309 
310  protected function updateErrorSettings(): void
311  {
312  $this->checkPermission('write');
313  $form = $this->initFormErrorSettings();
314  if ($form->checkInput()) {
315  $this->getErrorSettings()->setMail($form->getInput('error_mail'));
316  $this->getErrorSettings()->update();
317 
318  $this->tpl->setOnScreenMessage('success', $this->lng->txt('error_settings_saved'), true);
319  $this->ctrl->redirect($this, 'errorSettings');
320  }
321  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
322  $form->setValuesByPost();
323  $this->errorSettings($form);
324  }
325 
327  {
328  $form = new ilPropertyFormGUI();
329  $form->setTitle($this->lng->txt('logs_settings'));
330  $form->setFormAction($this->ctrl->getFormAction($this));
331 
332  if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
333  $form->addCommandButton('updateErrorSettings', $this->lng->txt('save'));
334  }
335 
336  $folder = new ilNonEditableValueGUI($this->lng->txt('log_error_folder'), 'error_folder');
337  $folder->setValue($this->getErrorSettings()->folder());
338  $form->addItem($folder);
339 
340  $mail = new ilTextInputGUI($this->lng->txt('log_error_mail'), 'error_mail');
341  $mail->setValue($this->getErrorSettings()->mail());
342  $form->addItem($mail);
343  return $form;
344  }
345 
346  protected function initErrorSettings(): void
347  {
348  $this->error_settings = ilLoggingErrorSettings::getInstance();
349  }
350 
352  {
353  return $this->error_settings;
354  }
355 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
This class represents a selection list property in a property form.
prepareOutput(bool $show_sub_objects=true)
static getLevelOptions()
setOptions(array $a_options)
ilLoggingErrorSettings $error_settings
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:26
Class ilObjForumAdministration.
individual log levels for components
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
settings(?ilPropertyFormGUI $form=null)
errorSettings(?ilPropertyFormGUI $form=null)
__construct(Container $dic, ilPlugin $plugin)
Component logger with individual log levels by component id.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
__construct($a_data, int $a_id, bool $a_call_by_reference, bool $a_prepare_output=true)