ILIAS  release_8 Revision v8.24
class.ilObjDashboardSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
32{
36 protected UIServices $ui;
38
39 public function __construct(
40 $a_data,
41 int $a_id,
42 bool $a_call_by_reference = true,
43 bool $a_prepare_output = true
44 ) {
45 global $DIC;
46
47 $this->lng = $DIC->language();
48 $this->rbac_system = $DIC->rbac()->system();
49 $this->access = $DIC->access();
50 $this->ctrl = $DIC->ctrl();
51 $this->settings = $DIC->settings();
52 $lng = $DIC->language();
53 $this->ui_factory = $DIC->ui()->factory();
54 $this->ui_renderer = $DIC->ui()->renderer();
55 $this->request = $DIC->http()->request();
56 $this->ui = $DIC->ui();
57
58 $this->type = 'dshs';
59 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
60
61 $lng->loadLanguageModule('dash');
62
63 $this->viewSettings = new ilPDSelectedItemsBlockViewSettings($DIC->user());
64
65 $this->side_panel_settings = new ilDashboardSidePanelSettingsRepository();
66 }
67
68 public function executeCommand(): void
69 {
70 $cmd = $this->ctrl->getCmd();
71
72 $this->prepareOutput();
73
74 if (!$this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
75 throw new ilPermissionException($this->lng->txt('no_permission'));
76 }
77
78 switch ($this->ctrl->getNextClass($this)) {
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 = 'editSettings';
88 }
89
90 $this->$cmd();
91 break;
92 }
93 }
94
95 public function getAdminTabs(): void
96 {
97 if ($this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
98 $this->tabs_gui->addTarget(
99 'settings',
100 $this->ctrl->getLinkTarget($this, 'editSettings'),
101 array('editSettings', 'view')
102 );
103 }
104
105 if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
106 $this->tabs_gui->addTarget(
107 'perm_settings',
108 $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
109 array(),
110 'ilpermissiongui'
111 );
112 }
113 }
114
115 public function editSettings(): void
116 {
117 if ($this->settings->get('rep_favourites', '0') !== '1') {
118 $content[] = $this->ui_factory->messageBox()->info($this->lng->txt('favourites_disabled_info'));
119 }
120
121 if ($this->settings->get('mmbr_my_crs_grp', '0') !== '1') {
122 $content[] = $this->ui_factory->messageBox()->info($this->lng->txt('memberships_disabled_info'));
123 }
124 $this->setSettingsSubTabs('general');
125 $content[] = $this->initForm();
126 $this->tpl->setContent($this->ui->renderer()->renderAsync($content));
127 }
128
129 public function initForm(): Standard
130 {
132
133 $fields['enable_favourites'] = $this->ui_factory->input()->field()->checkbox($lng->txt('dash_enable_favourites'))
134 ->withValue($this->viewSettings->enabledSelectedItems());
135 $info_text = ($this->viewSettings->enabledMemberships())
136 ? ''
137 : $lng->txt('dash_member_main_alt') . ' ' . $this->ui->renderer()->render(
138 $this->ui_factory->link()->standard(
139 $lng->txt('dash_click_here'),
140 $this->ctrl->getLinkTargetByClass(['ilAdministrationGUI', 'ilObjMainMenuGUI', 'ilmmsubitemgui'])
141 )
142 );
143
144 $fields['enable_memberships'] = $this->ui_factory->input()->field()->checkbox($lng->txt('dash_enable_memberships'), $info_text)
145 ->withValue($this->viewSettings->enabledMemberships());
146
147 $section1 = $this->ui_factory->input()->field()->section($this->maybeDisable($fields), $lng->txt('dash_main_panel'));
148
149 $sp_fields = [];
150 foreach ($this->side_panel_settings->getValidModules() as $mod) {
151 $sp_fields['enable_' . $mod] = $this->ui_factory->input()->field()->checkbox($lng->txt('dash_enable_' . $mod))
152 ->withValue($this->side_panel_settings->isEnabled($mod));
153 }
154
155 $section2 = $this->ui_factory->input()->field()->section($this->maybeDisable($sp_fields), $lng->txt('dash_side_panel'));
156
157 $form_action = $this->ctrl->getLinkTarget($this, 'saveSettings');
158 return $this->ui_factory->input()->container()->form()->standard(
160 ['main_panel' => $section1, 'side_panel' => $section2]
161 );
162 }
163
164 public function saveSettings(): void
165 {
166 if ($this->canWrite()) {
167 $form = $this->initForm();
168 $form = $form->withRequest($this->request);
169 $form_data = $form->getData();
170 $this->viewSettings->enableSelectedItems($form_data['main_panel']['enable_favourites']);
171 $this->viewSettings->enableMemberships($form_data['main_panel']['enable_memberships']);
172
173 foreach ($this->side_panel_settings->getValidModules() as $mod) {
174 $this->side_panel_settings->enable($mod, (bool) $form_data['side_panel']['enable_' . $mod]);
175 }
176
177 $this->tpl->setOnScreenMessage(
178 $this->tpl::MESSAGE_TYPE_SUCCESS,
179 $this->lng->txt('settings_saved'),
180 true
181 );
182 } else {
183 $this->tpl->setOnScreenMessage(
184 $this->tpl::MESSAGE_TYPE_FAILURE,
185 $this->lng->txt('no_permission'),
186 true
187 );
188 }
189
190 $this->ctrl->redirect($this, 'editSettings');
191 }
192
193
194 public function setSettingsSubTabs(string $a_active): void
195 {
196 $tabs = $this->tabs_gui;
199
200 if ($this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
201 $tabs->addSubTab(
202 'general',
203 $lng->txt('general_settings'),
204 $ctrl->getLinkTarget($this, 'editSettings')
205 );
206
207 if ($this->viewSettings->enabledSelectedItems()) {
208 $tabs->addSubTab(
209 'view_favourites',
210 $lng->txt('dash_view_favourites'),
211 $ctrl->getLinkTarget($this, 'editViewFavourites')
212 );
213 }
214
215 if ($this->viewSettings->enabledMemberships()) {
216 $tabs->addSubTab(
217 'view_courses_groups',
218 $lng->txt('dash_view_courses_groups'),
219 $ctrl->getLinkTarget($this, 'editViewCoursesGroups')
220 );
221 }
222 }
223
224 $tabs->activateSubTab($a_active);
225 }
226
227 protected function editViewCoursesGroups(): void
228 {
229 if ($this->settings->get('mmbr_my_crs_grp', '0') !== '1') {
230 $content[] = $this->ui_factory->messageBox()->info($this->lng->txt('memberships_disabled_info'));
231 }
232 $this->tabs_gui->activateTab('settings');
233 $this->setSettingsSubTabs('view_courses_groups');
234
235 $content[] = $this->getViewSettingsForm($this->viewSettings->getMembershipsView());
236 $this->tpl->setContent($this->ui_renderer->render($content));
237 }
238
239 protected function getViewSettingsForm(int $view): Standard
240 {
243
244 if ($view === $this->viewSettings->getSelectedItemsView()) {
245 $save_cmd = 'saveViewFavourites';
246 } else {
247 $save_cmd = 'saveViewCoursesGroups';
248 }
249
250 $ops = $this->viewSettings->getAvailablePresentationsByView($view);
251 $pres_options = array_column(array_map(static fn ($v) => [$v, $lng->txt('dash_' . $v)], $ops), 1, 0);
252 $avail_pres = $this->ui_factory->input()->field()->multiSelect($lng->txt('dash_avail_presentation'), $pres_options)
253 ->withValue($this->viewSettings->getActivePresentationsByView($view));
254 $default_pres = $this->ui_factory->input()->field()->radio($lng->txt('dash_default_presentation'))
255 ->withOption('list', $lng->txt('dash_list'))
256 ->withOption('tile', $lng->txt('dash_tile'));
257 $default_pres = $default_pres->withValue($this->viewSettings->getDefaultPresentationByView($view));
258 $sec_presentation = $this->ui_factory->input()->field()->section(
259 $this->maybeDisable(['avail_pres' => $avail_pres, 'default_pres' => $default_pres]),
260 $lng->txt('dash_presentation')
261 );
262
263 $ops = $this->viewSettings->getAvailableSortOptionsByView($view);
264 $sortation_options = array_column(array_map(static fn ($v) => [$v, $lng->txt('dash_sort_by_' . $v)], $ops), 1, 0);
265 $avail_sort = $this->ui_factory->input()->field()->multiSelect($lng->txt('dash_avail_sortation'), $sortation_options)
266 ->withValue($this->viewSettings->getActiveSortingsByView($view));
267 $default_sort = $this->ui_factory->input()->field()->radio($lng->txt('dash_default_sortation'));
268 foreach ($sortation_options as $k => $text) {
269 $default_sort = $default_sort->withOption($k, $text);
270 }
271 $default_sort = $default_sort->withValue($this->viewSettings->getDefaultSortingByView($view));
272 $sec_sortation = $this->ui_factory->input()->field()->section(
273 $this->maybeDisable(['avail_sort' => $avail_sort, 'default_sort' => $default_sort]),
274 $lng->txt('dash_sortation')
275 );
276
277 $form = $this->ui_factory->input()->container()->form()->standard(
278 $this->ctrl->getFormAction($this, $save_cmd),
279 ['presentation' => $sec_presentation, 'sortation' => $sec_sortation]
280 );
281
282 return $form;
283 }
284
285
286 protected function saveViewCoursesGroups(): void
287 {
288 $this->saveViewSettings(
289 $this->viewSettings->getMembershipsView(),
290 'editViewCoursesGroups'
291 );
292 }
293
294 protected function editViewFavourites(): void
295 {
296 if ($this->settings->get('rep_favourites', '0') !== '1') {
297 $content[] = $this->ui_factory->messageBox()->info($this->lng->txt('favourites_disabled_info'));
298 }
299 $this->tabs_gui->activateTab('settings');
300 $this->setSettingsSubTabs('view_favourites');
301
302 $content[] = $this->getViewSettingsForm($this->viewSettings->getSelectedItemsView());
303 $this->tpl->setContent($this->ui_renderer->render($content));
304 }
305
306 protected function saveViewFavourites(): void
307 {
308 $this->saveViewSettings(
309 $this->viewSettings->getSelectedItemsView(),
310 'editViewFavourites'
311 );
312 }
313
314 protected function saveViewSettings(int $view, string $redirect_cmd): void
315 {
319
320 if (!$this->canWrite()) {
321 $this->tpl->setOnScreenMessage(
322 $this->tpl::MESSAGE_TYPE_FAILURE,
323 $this->lng->txt('no_permission'),
324 true
325 );
326 $ctrl->redirect($this, $redirect_cmd);
327 }
328
329 $form = $this->getViewSettingsForm($view);
330 $form = $form->withRequest($request);
331 $form_data = $form->getData();
332 $this->viewSettings->storeViewSorting(
333 $view,
334 $form_data['sortation']['default_sort'],
335 $form_data['sortation']['avail_sort'] ?: []
336 );
337 $this->viewSettings->storeViewPresentation(
338 $view,
339 $form_data['presentation']['default_pres'],
340 $form_data['presentation']['avail_pres'] ?: []
341 );
342
343 $this->tpl->setOnScreenMessage('success', $lng->txt('msg_obj_modified'), true);
344 $ctrl->redirect($this, $redirect_cmd);
345 }
346
351 private function maybeDisable(array $fields): array
352 {
353 if ($this->canWrite()) {
354 return $fields;
355 }
356
357 return array_map(static fn (FormInput $field): FormInput => $field->withDisabled(true), $fields);
358 }
359
360 private function canWrite(): bool
361 {
362 return $this->rbac_system->checkAccess('write', $this->object->getRefId());
363 }
364}
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
@ilCtrl_Calls ilObjDashboardSettingsGUI: ilPermissionGUI @ilCtrl_isCalledBy ilObjDashboardSettingsGUI...
ilDashboardSidePanelSettingsRepository $side_panel_settings
ilPDSelectedItemsBlockViewSettings $viewSettings
getAdminTabs()
administration tabs show only permissions and trash folder
__construct( $a_data, int $a_id, bool $a_call_by_reference=true, bool $a_prepare_output=true)
saveViewSettings(int $view, string $redirect_cmd)
Class ilObjectGUI Basic methods of all Output classes.
ilTabsGUI $tabs_gui
prepareOutput(bool $show_sub_objects=true)
ServerRequestInterface $request
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
global $DIC
Definition: feed.php:28
This describes inputs that can be used in forms.
Definition: FormInput.php:32
This describes a standard form.
Definition: Standard.php:27
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: FormInput.php:32
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59