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