ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjDashboardSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32{
36 protected $rbacsystem;
37
41 protected $error;
42
46 protected $ui_factory;
47
51 protected $ui_renderer;
52
56 protected $viewSettings;
57
61 protected $request;
62
66 protected $ui;
67
72
78 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
79 {
80 global $DIC;
81
82 $this->lng = $DIC->language();
83 $this->rbacsystem = $DIC->rbac()->system();
84 $this->error = $DIC["ilErr"];
85 $this->access = $DIC->access();
86 $this->ctrl = $DIC->ctrl();
87 $this->settings = $DIC->settings();
88 $lng = $DIC->language();
89 $this->ui_factory = $DIC->ui()->factory();
90 $this->ui_renderer = $DIC->ui()->renderer();
91 $this->request = $DIC->http()->request();
92 $this->ui = $DIC->ui();
93
94 $this->type = 'dshs';
95 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
96
97 $lng->loadLanguageModule("dash");
98
99 $this->viewSettings = new ilPDSelectedItemsBlockViewSettings($GLOBALS['DIC']->user());
100
101 $this->side_panel_settings = new ilDashboardSidePanelSettingsRepository();
102 }
103
110 public function executeCommand()
111 {
112 $next_class = $this->ctrl->getNextClass($this);
113 $cmd = $this->ctrl->getCmd();
114
115 $this->prepareOutput();
116
117 if (!$this->rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
118 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
119 }
120
121 switch ($next_class) {
122 case 'ilpermissiongui':
123 $this->tabs_gui->setTabActive('perm_settings');
124 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
125 $perm_gui = new ilPermissionGUI($this);
126 $ret = $this->ctrl->forwardCommand($perm_gui);
127 break;
128
129 default:
130 if (!$cmd || $cmd == 'view') {
131 $cmd = "editSettings";
132 }
133
134 $this->$cmd();
135 break;
136 }
137 return true;
138 }
139
146 public function getAdminTabs()
147 {
149 $ilAccess = $this->access;
150
151 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
152 $this->tabs_gui->addTarget(
153 "settings",
154 $this->ctrl->getLinkTarget($this, "editSettings"),
155 array("editSettings", "view")
156 );
157 }
158
159 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
160 $this->tabs_gui->addTarget(
161 "perm_settings",
162 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
163 array(),
164 'ilpermissiongui'
165 );
166 }
167 }
168
172 public function editSettings()
173 {
174 if ($this->settings->get('rep_favourites', '0') !== '1') {
175 $content[] = $this->ui->factory()->messageBox()->info($this->lng->txt('favourites_disabled_info'));
176 }
177
178 if ($this->settings->get('mmbr_my_crs_grp', '0') !== '1') {
179 $content[] = $this->ui->factory()->messageBox()->info($this->lng->txt('memberships_disabled_info'));
180 }
181 $this->setSettingsSubTabs('general');
182 $content[] = $this->initForm();
183 $this->tpl->setContent($this->ui->renderer()->renderAsync($content));
184 }
185
190 public function initForm()
191 {
192 $ui = $this->ui;
193 $f = $ui->factory();
196
197 $side_panel = $this->side_panel_settings;
198
199 $fields["enable_favourites"] = $f->input()->field()->checkbox($lng->txt("dash_enable_favourites"))
200 ->withValue($this->viewSettings->enabledSelectedItems());
201 $info_text = ($this->viewSettings->enabledMemberships())
202 ? ""
203 : $lng->txt("dash_member_main_alt") . " " . $ui->renderer()->render(
204 $ui->factory()->link()->standard(
205 $lng->txt("dash_click_here"),
206 $ctrl->getLinkTargetByClass(["ilAdministrationGUI", "ilObjMainMenuGUI", "ilmmsubitemgui"])
207 )
208 );
209
210 $fields["enable_memberships"] = $f->input()->field()->checkbox($lng->txt("dash_enable_memberships"), $info_text)
211 ->withValue($this->viewSettings->enabledMemberships());
212
213 // main panel
214 $section1 = $f->input()->field()->section($this->maybeDisable($fields), $lng->txt("dash_main_panel"));
215
216 $sp_fields = [];
217 foreach ($side_panel->getValidModules() as $mod) {
218 $sp_fields["enable_" . $mod] = $f->input()->field()->checkbox($lng->txt("dash_enable_" . $mod))
219 ->withValue($side_panel->isEnabled($mod));
220 }
221
222 // side panel
223 $section2 = $f->input()->field()->section($this->maybeDisable($sp_fields), $lng->txt("dash_side_panel"));
224
225 $form_action = $ctrl->getLinkTarget($this, "saveSettings");
226 return $f->input()->container()->form()->standard(
227 $form_action,
228 ["main_panel" => $section1, "side_panel" => $section2]
229 );
230 }
231
235 public function saveSettings()
236 {
237 $ilCtrl = $this->ctrl;
238 $ilAccess = $this->access;
239 $side_panel = $this->side_panel_settings;
240
241 if (!$this->canWrite()) {
242 ilUtil::sendFailure($this->lng->txt('no_permission'), true);
243 $ilCtrl->redirect($this, "editSettings");
244 }
245
247
248 $form = $this->initForm();
249 $form = $form->withRequest($request);
250 $form_data = $form->getData();
251 $this->viewSettings->enableSelectedItems($form_data['main_panel']['enable_favourites']);
252 $this->viewSettings->enableMemberships($form_data['main_panel']['enable_memberships']);
253
254 foreach ($side_panel->getValidModules() as $mod) {
255 $side_panel->enable($mod, (bool) $form_data['side_panel']['enable_' . $mod]);
256 }
257
258
259 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
260 $ilCtrl->redirect($this, "editSettings");
261 }
262
263
270 public function setSettingsSubTabs($a_active)
271 {
273 $ilAccess = $this->access;
274
275 $tabs = $this->tabs_gui;
278
279 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
280 $tabs->addSubtab(
281 "general",
282 $lng->txt("general_settings"),
283 $ctrl->getLinkTarget($this, "editSettings")
284 );
285
286 if ($this->viewSettings->enabledSelectedItems()) {
287 $tabs->addSubtab(
288 "view_favourites",
289 $lng->txt("dash_view_favourites"),
290 $ctrl->getLinkTarget($this, "editViewFavourites")
291 );
292 }
293
294 if ($this->viewSettings->enabledMemberships()) {
295 $tabs->addSubtab(
296 "view_courses_groups",
297 $lng->txt("dash_view_courses_groups"),
298 $ctrl->getLinkTarget($this, "editViewCoursesGroups")
299 );
300 }
301 }
302
303 $tabs->activateSubtab($a_active);
304 }
305
309 protected function editViewCoursesGroups()
310 {
311 if ($this->settings->get('mmbr_my_crs_grp', '0') !== '1') {
312 $content[] = $this->ui->factory()->messageBox()->info($this->lng->txt('memberships_disabled_info'));
313 }
314 $this->tabs_gui->activateTab("settings");
315 $this->setSettingsSubTabs("view_courses_groups");
316
317 $content[] = $this->getViewSettingsForm($this->viewSettings->getMembershipsView());
318 $this->tpl->setContent($this->ui_renderer->render($content));
319 }
320
326 protected function getViewSettingsForm(int $view)
327 {
331
332 if ($view == $this->viewSettings->getSelectedItemsView()) {
333 $save_cmd = "saveViewFavourites";
334 } else {
335 $save_cmd = "saveViewCoursesGroups";
336 }
337
338 // presentation
339 $ops = $this->viewSettings->getAvailablePresentationsByView($view);
340 $pres_options = array_column(array_map(function ($k, $v) use ($lng) {
341 return [$v, $lng->txt("dash_" . $v)];
342 }, array_keys($ops), $ops), 1, 0);
343 $avail_pres = $ui_factory->input()->field()->multiselect($lng->txt("dash_avail_presentation"), $pres_options)
344 ->withValue($this->viewSettings->getActivePresentationsByView($view));
345 $default_pres = $ui_factory->input()->field()->radio($lng->txt("dash_default_presentation"))
346 ->withOption('list', $lng->txt("dash_list"))
347 ->withOption('tile', $lng->txt("dash_tile"));
348 $default_pres = $default_pres->withValue((string) $this->viewSettings->getDefaultPresentationByView($view));
349 $sec_presentation = $ui_factory->input()->field()->section(
350 $this->maybeDisable(["avail_pres" => $avail_pres, "default_pres" => $default_pres]),
351 $lng->txt("dash_presentation")
352 );
353
354 // sortation
355 $ops = $this->viewSettings->getAvailableSortOptionsByView($view);
356 $sortation_options = array_column(array_map(function ($k, $v) use ($lng) {
357 return [$v, $lng->txt("dash_sort_by_" . $v)];
358 }, array_keys($ops), $ops), 1, 0);
359 $avail_sort = $ui_factory->input()->field()->multiselect($lng->txt("dash_avail_sortation"), $sortation_options)
360 ->withValue($this->viewSettings->getActiveSortingsByView($view));
361 $default_sort = $ui_factory->input()->field()->radio($lng->txt("dash_default_sortation"));
362 foreach ($sortation_options as $k => $text) {
363 $default_sort = $default_sort->withOption($k, $text);
364 }
365 $default_sort = $default_sort->withValue((string) $this->viewSettings->getDefaultSortingByView($view));
366 $sec_sortation = $ui_factory->input()->field()->section(
367 $this->maybeDisable(["avail_sort" => $avail_sort, "default_sort" => $default_sort]),
368 $lng->txt("dash_sortation")
369 );
370
371 $form = $ui_factory->input()->container()->form()->standard(
372 $ctrl->getFormAction($this, $save_cmd),
373 ["presentation" => $sec_presentation, "sortation" => $sec_sortation]
374 );
375
376 return $form;
377 }
378
379
383 protected function saveViewCoursesGroups()
384 {
385 $this->saveViewSettings(
386 $this->viewSettings->getMembershipsView(),
387 "editViewCoursesGroups"
388 );
389 }
390
394 protected function editViewFavourites()
395 {
396 if ($this->settings->get('rep_favourites', "0") !== '1') {
397 $content[] = $this->ui->factory()->messageBox()->info($this->lng->txt('favourites_disabled_info'));
398 }
399 $this->tabs_gui->activateTab("settings");
400 $this->setSettingsSubTabs("view_favourites");
401
402 $content[] = $this->getViewSettingsForm($this->viewSettings->getSelectedItemsView());
403 $this->tpl->setContent($this->ui_renderer->render($content));
404 }
405
409 protected function saveViewFavourites()
410 {
411 $this->saveViewSettings(
412 $this->viewSettings->getSelectedItemsView(),
413 "editViewFavourites"
414 );
415 }
416
420 protected function saveViewSettings(int $view, string $redirect_cmd)
421 {
425
426 if (!$this->canWrite()) {
427 ilUtil::sendFailure($this->lng->txt('no_permission'), true);
428 $ctrl->redirect($this, $redirect_cmd);
429 }
430
431 $form = $this->getViewSettingsForm($view);
432 $form = $form->withRequest($request);
433 $form_data = $form->getData();
434 $this->viewSettings->storeViewSorting(
435 $view,
436 $form_data['sortation']['default_sort'],
437 $form_data['sortation']['avail_sort'] ?: []
438 );
439 $this->viewSettings->storeViewPresentation(
440 $view,
441 $form_data['presentation']['default_pres'],
442 $form_data['presentation']['avail_pres'] ?: []
443 );
444
445 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
446 $ctrl->redirect($this, $redirect_cmd);
447 }
448
453 private function maybeDisable(array $fields) : array
454 {
455 if ($this->canWrite()) {
456 return $fields;
457 }
458
459 return array_map(static function (FormInput $field) : FormInput {
460 return $field->withDisabled(true);
461 }, $fields);
462 }
463
464 private function canWrite() : bool
465 {
466 return $this->rbacsystem->checkAccess('write', $this->object->getRefId());
467 }
468}
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor.
saveViewCoursesGroups()
Save settings of courses and groups overview.
saveViewFavourites()
Save settings of favourites overview.
editViewCoursesGroups()
Edit settings of courses and groups overview.
editSettings()
Edit personal desktop settings.
saveSettings()
Save personal desktop settings.
saveViewSettings(int $view, string $redirect_cmd)
Save settings of favourites overview.
getViewSettingsForm(int $view)
Get view courses and groups settings form.
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput($a_show_subobjects=true)
prepare output
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
This describes inputs that can be used in forms.
Definition: FormInput.php:16
withDisabled($is_disabled)
Get an input like this, but set it to a disabled state.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
settings()
Definition: settings.php:2
ui()
Definition: ui.php:5