ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjDashboardSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
16{
20 protected $rbacsystem;
21
25 protected $error;
26
30 protected $ui_factory;
31
35 protected $ui_renderer;
36
40 protected $viewSettings;
41
45 protected $request;
46
50 protected $ui;
51
56
62 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
63 {
64 global $DIC;
65
66 $this->lng = $DIC->language();
67 $this->rbacsystem = $DIC->rbac()->system();
68 $this->error = $DIC["ilErr"];
69 $this->access = $DIC->access();
70 $this->ctrl = $DIC->ctrl();
71 $this->settings = $DIC->settings();
72 $lng = $DIC->language();
73 $this->ui_factory = $DIC->ui()->factory();
74 $this->ui_renderer = $DIC->ui()->renderer();
75 $this->request = $DIC->http()->request();
76 $this->ui = $DIC->ui();
77
78 $this->type = 'dshs';
79 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
80
81 $lng->loadLanguageModule("dash");
82
83 $this->viewSettings = new ilPDSelectedItemsBlockViewSettings($GLOBALS['DIC']->user());
84
85 $this->side_panel_settings = new ilDashboardSidePanelSettingsRepository();
86 }
87
94 public function executeCommand()
95 {
96 $next_class = $this->ctrl->getNextClass($this);
97 $cmd = $this->ctrl->getCmd();
98
99 $this->prepareOutput();
100
101 if (!$this->rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
102 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
103 }
104
105 switch ($next_class) {
106 case 'ilpermissiongui':
107 $this->tabs_gui->setTabActive('perm_settings');
108 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
109 $perm_gui = new ilPermissionGUI($this);
110 $ret = $this->ctrl->forwardCommand($perm_gui);
111 break;
112
113 default:
114 if (!$cmd || $cmd == 'view') {
115 $cmd = "editSettings";
116 }
117
118 $this->$cmd();
119 break;
120 }
121 return true;
122 }
123
130 public function getAdminTabs()
131 {
133 $ilAccess = $this->access;
134
135 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
136 $this->tabs_gui->addTarget(
137 "settings",
138 $this->ctrl->getLinkTarget($this, "editSettings"),
139 array("editSettings", "view")
140 );
141 }
142
143 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
144 $this->tabs_gui->addTarget(
145 "perm_settings",
146 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
147 array(),
148 'ilpermissiongui'
149 );
150 }
151 }
152
156 public function editSettings()
157 {
158 $this->setSettingsSubTabs("general");
159 $ui = $this->ui;
160 $form = $this->initForm();
161 $this->tpl->setContent($ui->renderer()->renderAsync($form));
162 }
163
168 public function initForm()
169 {
170 $ui = $this->ui;
171 $f = $ui->factory();
174
175 $side_panel = $this->side_panel_settings;
176
177 $fields["enable_favourites"] = $f->input()->field()->checkbox($lng->txt("dash_enable_favourites"))
178 ->withValue($this->viewSettings->enabledSelectedItems());
179 $info_text = ($this->viewSettings->enabledMemberships())
180 ? ""
181 : $lng->txt("dash_member_main_alt") . " " . $ui->renderer()->render(
182 $ui->factory()->link()->standard(
183 $lng->txt("dash_click_here"),
184 $ctrl->getLinkTargetByClass(["ilAdministrationGUI", "ilObjMainMenuGUI", "ilmmsubitemgui"])
185 )
186 );
187
188 $fields["enable_memberships"] = $f->input()->field()->checkbox($lng->txt("dash_enable_memberships"), $info_text)
189 ->withValue($this->viewSettings->enabledMemberships());
190
191 // main panel
192 $section1 = $f->input()->field()->section($this->maybeDisable($fields), $lng->txt("dash_main_panel"));
193
194 $sp_fields = [];
195 foreach ($side_panel->getValidModules() as $mod) {
196 $sp_fields["enable_" . $mod] = $f->input()->field()->checkbox($lng->txt("dash_enable_" . $mod))
197 ->withValue($side_panel->isEnabled($mod));
198 }
199
200 // side panel
201 $section2 = $f->input()->field()->section($this->maybeDisable($sp_fields), $lng->txt("dash_side_panel"));
202
203 $form_action = $ctrl->getLinkTarget($this, "saveSettings");
204 return $f->input()->container()->form()->standard(
205 $form_action,
206 ["main_panel" => $section1, "side_panel" => $section2]
207 );
208 }
209
213 public function saveSettings()
214 {
216 $ilAccess = $this->access;
217 $side_panel = $this->side_panel_settings;
218
219 if (!$this->canWrite()) {
220 ilUtil::sendFailure($this->lng->txt('no_permission'), true);
221 $ilCtrl->redirect($this, "editSettings");
222 }
223
225
226 $form = $this->initForm();
227 $form = $form->withRequest($request);
228 $form_data = $form->getData();
229 $this->viewSettings->enableSelectedItems((int) ($form_data['main_panel']['enable_favourites'] != ""));
230 $this->viewSettings->enableMemberships((int) ($form_data['main_panel']['enable_memberships'] != ""));
231
232 foreach ($side_panel->getValidModules() as $mod) {
233 $side_panel->enable($mod, (bool) $form_data['side_panel']['enable_' . $mod]);
234 }
235
236
237 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
238 $ilCtrl->redirect($this, "editSettings");
239 }
240
241
248 public function setSettingsSubTabs($a_active)
249 {
251 $ilAccess = $this->access;
252
253 $tabs = $this->tabs_gui;
256
257 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
258 $tabs->addSubtab(
259 "general",
260 $lng->txt("general_settings"),
261 $ctrl->getLinkTarget($this, "editSettings")
262 );
263
264 if ($this->viewSettings->enabledSelectedItems()) {
265 $tabs->addSubtab(
266 "view_favourites",
267 $lng->txt("dash_view_favourites"),
268 $ctrl->getLinkTarget($this, "editViewFavourites")
269 );
270 }
271
272 if ($this->viewSettings->enabledMemberships()) {
273 $tabs->addSubtab(
274 "view_courses_groups",
275 $lng->txt("dash_view_courses_groups"),
276 $ctrl->getLinkTarget($this, "editViewCoursesGroups")
277 );
278 }
279 }
280
281 $tabs->activateSubtab($a_active);
282 }
283
287 protected function editViewCoursesGroups()
288 {
289 $main_tpl = $this->tpl;
290 $tabs = $this->tabs_gui;
292
293 $tabs->activateTab("settings");
294 $this->setSettingsSubTabs("view_courses_groups");
295
296 $form = $this->getViewSettingsForm($this->viewSettings->getMembershipsView());
297
298 $main_tpl->setContent($ui_renderer->render($form));
299 }
300
306 protected function getViewSettingsForm(int $view)
307 {
311
312 if ($view == $this->viewSettings->getSelectedItemsView()) {
313 $save_cmd = "saveViewFavourites";
314 } else {
315 $save_cmd = "saveViewCoursesGroups";
316 }
317
318 // presentation
319 $ops = $this->viewSettings->getAvailablePresentationsByView($view);
320 $pres_options = array_column(array_map(function ($k, $v) use ($lng) {
321 return [$v, $lng->txt("dash_" . $v)];
322 }, array_keys($ops), $ops), 1, 0);
323 $avail_pres = $ui_factory->input()->field()->multiselect($lng->txt("dash_avail_presentation"), $pres_options)
324 ->withValue($this->viewSettings->getActivePresentationsByView($view));
325 $default_pres = $ui_factory->input()->field()->radio($lng->txt("dash_default_presentation"))
326 ->withOption('list', $lng->txt("dash_list"))
327 ->withOption('tile', $lng->txt("dash_tile"));
328 $default_pres = $default_pres->withValue((string) $this->viewSettings->getDefaultPresentationByView($view));
329 $sec_presentation = $ui_factory->input()->field()->section(
330 $this->maybeDisable(["avail_pres" => $avail_pres, "default_pres" => $default_pres]),
331 $lng->txt("dash_presentation")
332 );
333
334 // sortation
335 $ops = $this->viewSettings->getAvailableSortOptionsByView($view);
336 $sortation_options = array_column(array_map(function ($k, $v) use ($lng) {
337 return [$v, $lng->txt("dash_sort_by_" . $v)];
338 }, array_keys($ops), $ops), 1, 0);
339 $avail_sort = $ui_factory->input()->field()->multiselect($lng->txt("dash_avail_sortation"), $sortation_options)
340 ->withValue($this->viewSettings->getActiveSortingsByView($view));
341 $default_sort = $ui_factory->input()->field()->radio($lng->txt("dash_default_sortation"));
342 foreach ($sortation_options as $k => $text) {
343 $default_sort = $default_sort->withOption($k, $text);
344 }
345 $default_sort = $default_sort->withValue((string) $this->viewSettings->getDefaultSortingByView($view));
346 $sec_sortation = $ui_factory->input()->field()->section(
347 $this->maybeDisable(["avail_sort" => $avail_sort, "default_sort" => $default_sort]),
348 $lng->txt("dash_sortation")
349 );
350
351 $form = $ui_factory->input()->container()->form()->standard(
352 $ctrl->getFormAction($this, $save_cmd),
353 ["presentation" => $sec_presentation, "sortation" => $sec_sortation]
354 );
355
356 return $form;
357 }
358
359
363 protected function saveViewCoursesGroups()
364 {
365 $this->saveViewSettings(
366 $this->viewSettings->getMembershipsView(),
367 "editViewCoursesGroups"
368 );
369 }
370
374 protected function editViewFavourites()
375 {
376 $main_tpl = $this->tpl;
377 $tabs = $this->tabs_gui;
379
380 $tabs->activateTab("settings");
381 $this->setSettingsSubTabs("view_favourites");
382
383 $view = $this->viewSettings->getSelectedItemsView();
384
385 $form = $this->getViewSettingsForm($view);
386
387 $main_tpl->setContent($ui_renderer->render($form));
388 }
389
393 protected function saveViewFavourites()
394 {
395 $this->saveViewSettings(
396 $this->viewSettings->getSelectedItemsView(),
397 "editViewFavourites"
398 );
399 }
400
404 protected function saveViewSettings(int $view, string $redirect_cmd)
405 {
409
410 if (!$this->canWrite()) {
411 ilUtil::sendFailure($this->lng->txt('no_permission'), true);
412 $ctrl->redirect($this, $redirect_cmd);
413 }
414
415 $form = $this->getViewSettingsForm($view);
416 $form = $form->withRequest($request);
417 $form_data = $form->getData();
418 $this->viewSettings->storeViewSorting(
419 $view,
420 $form_data['sortation']['default_sort'],
421 $form_data['sortation']['avail_sort'] ?: []
422 );
423 $this->viewSettings->storeViewPresentation(
424 $view,
425 $form_data['presentation']['default_pres'],
426 $form_data['presentation']['avail_pres'] ?: []
427 );
428
429 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
430 $ctrl->redirect($this, $redirect_cmd);
431 }
432
437 private function maybeDisable(array $fields) : array
438 {
439 if ($this->canWrite()) {
440 return $fields;
441 }
442
443 return array_map(static function (Input $field) : Input {
444 return $field->withDisabled(true);
445 }, $fields);
446 }
447
448 private function canWrite() : bool
449 {
450 return $this->rbacsystem->checkAccess('write', $this->object->getRefId());
451 }
452}
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 $ilCtrl
Definition: ilias.php:18
This describes commonalities between all inputs.
Definition: Input.php:32
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
$DIC
Definition: xapitoken.php:46