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