ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjQuestionPoolSettingsGeneralGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Factory as UIFactory;
23use ILIAS\Refinery\Factory as Refinery;
24use ILIAS\UI\Renderer as UIRenderer;
25use Psr\Http\Message\ServerRequestInterface as HttpRequest;
28
41{
42 public const CMD_SHOW_GENERAL_FORM = 'showForm';
43 public const CMD_SAVE_GENERAL_FORM = 'saveForm';
44 public const TAB_COMMON_SETTINGS = 'settings';
46
47 public function __construct(
48 private readonly ilCtrl $ctrl,
49 private readonly ilAccessHandler $access,
50 private readonly ilLanguage $lng,
51 private readonly ilGlobalTemplateInterface $tpl,
52 private readonly ilTabsGUI $tabs,
53 private readonly ilObjQuestionPoolGUI $poolGUI,
54 private readonly Refinery $refinery,
55 private readonly UIFactory $ui_factory,
56 private readonly UIRenderer $ui_renderer,
57 private readonly HttpRequest $http_request,
58 ) {
59 $this->poolOBJ = $poolGUI->getObject();
60 }
61
65 public function executeCommand(): void
66 {
67 // allow only write access
68
69 if (!$this->access->checkAccess('write', '', $this->poolGUI->getRefId())) {
70 $this->tpl->setOnScreenMessage('info', $this->lng->txt('cannot_edit_question_pool'), true);
71 $this->ctrl->redirectByClass(
72 [
73 ilRepositoryGUI::class,
74 self::class,
75 ilInfoScreenGUI::class
76 ],
77 'showSummary'
78 );
79 }
80
81 $this->tabs->activateTab('settings');
82 $this->tabs->activateSubTab('qpl_settings_subtab_general');
83
84 // process command
85
86 $nextClass = $this->ctrl->getNextClass();
87
88 switch ($nextClass) {
89 default:
90 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_FORM) . 'Cmd';
91 $this->$cmd();
92 }
93 }
94
95 private function showFormCmd(?Form $form = null): void
96 {
97 $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
98 if ($form === null) {
99 $form = $this->buildForm();
100 }
101 $this->tpl->setContent($this->ui_renderer->render($form));
102 }
103
104 private function saveFormCmd(): void
105 {
106 $form = $this->buildForm()->withRequest($this->http_request);
107 $result = $form->getInputGroup()->getContent();
108
109 if (!$result->isOK()) {
110 $this->tpl->setOnScreenMessage(MessageBox::FAILURE, $this->lng->txt('form_input_not_valid'));
111 $this->showFormCmd($form);
112 return;
113 }
114
115 $this->performSaveForm($result->value());
116 $this->tpl->setOnScreenMessage(MessageBox::SUCCESS, $this->lng->txt("msg_obj_modified"), true);
117 $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_FORM);
118
119 }
120
121 private function performSaveForm($data): void
122 {
123 $title_and_description = $data['general_settings']['title_and_description'] ?? null;
124 if ($title_and_description instanceof TitleAndDescription) {
125 $this->poolOBJ->getObjectProperties()->storePropertyTitleAndDescription(
126 $title_and_description
127 );
128 }
129
130 $this->poolOBJ->getObjectProperties()->storePropertyIsOnline(
131 $data['availability']['online'] ?? $this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->withOffline()
132 );
133
134 $display_settings = $data['display_settings'] ?? [];
135 if (isset($display_settings['tile_image'])) {
136 $this->poolOBJ->getObjectProperties()->storePropertyTileImage($display_settings['tile_image']);
137 }
138
139 $this->poolOBJ->setSkillServiceEnabled($data['additional_features']['skill_service'] ?? false);
140
141 $this->poolOBJ->saveToDb();
142 }
143
144 private function buildForm(): Form
145 {
146 $items = [];
147
148 $title_and_description = $this->poolOBJ->getObjectProperties()->getPropertyTitleAndDescription()->toForm(
149 $this->lng,
150 $this->ui_factory->input()->field(),
151 $this->refinery
152 );
153
154 $items['general_settings'] = $this->ui_factory->input()->field()->section(
155 [
156 'title_and_description' => $title_and_description
157 ],
158 $this->lng->txt('qpl_form_general_settings')
159 );
160
161 $online = $this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->toForm(
162 $this->lng,
163 $this->ui_factory->input()->field(),
164 $this->refinery
165 );
166 $availability = $this->ui_factory->input()->field()->section(
167 ['online' => $online],
168 $this->lng->txt('qpl_settings_availability')
169 );
170 $items['availability'] = $availability;
171
172 $timg = $this->poolOBJ->getObjectProperties()->getPropertyTileImage()->toForm(
173 $this->lng,
174 $this->ui_factory->input()->field(),
175 $this->refinery
176 );
177 $items['display_settings'] = $this->ui_factory->input()->field()->section(
178 ['tile_image' => $timg],
179 $this->lng->txt('tst_presentation_settings_section')
180 );
181
182 $additional_features_inputs = [];
183
185 $additional_features_inputs['skill_service'] = $this->ui_factory->input()->field()->checkbox(
186 $this->lng->txt('tst_activate_skill_service')
187 )->withValue($this->poolOBJ->isSkillServiceEnabled());
188 }
189
190 $items['additional_features'] = $this->ui_factory->input()->field()->section(
191 $additional_features_inputs,
192 $this->lng->txt('obj_features')
193 );
194
195 return $this->ui_factory->input()->container()->form()->standard(
196 $this->ctrl->getFormAction($this, self::CMD_SAVE_GENERAL_FORM),
197 $items
198 );
199 }
200}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class ilCtrl provides processing control methods.
language handling
Class ilObjQuestionPoolGUI.
__construct(private readonly ilCtrl $ctrl, private readonly ilAccessHandler $access, private readonly ilLanguage $lng, private readonly ilGlobalTemplateInterface $tpl, private readonly ilTabsGUI $tabs, private readonly ilObjQuestionPoolGUI $poolGUI, private readonly Refinery $refinery, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly HttpRequest $http_request,)
Class ilObject Basic functions for all objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes a standard form.
Definition: Standard.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
@ FAILURE
The progress of the process/task cannot be calculated (yet), but it has started processing.
Definition: Status.php:42
global $lng
Definition: privfeed.php:31