ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilIndividualAssessmentSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use ILIAS\UI;
25use Psr\Http\Message\RequestInterface;
26use Psr\Http\Message\ServerRequestInterface;
27
32{
33 public const TAB_EDIT = 'settings';
34 public const TAB_EDIT_INFO = 'infoSettings';
35 public const TAB_COMMON_SETTINGS = 'commonSettings';
36
37 protected ilCtrl $ctrl;
40 protected ilLanguage $lng;
44 protected Refinery\Factory $refinery;
45 protected UI\Renderer $ui_renderer;
46
50 protected $http_request;
53
54 public function __construct(
60 Input\Factory $factory,
66 ) {
67 $this->ctrl = $ctrl;
68 $this->object = $object;
69 $this->tpl = $tpl;
70 $this->lng = $lng;
71 $this->tabs_gui = $tabs_gui;
72 $this->iass_access = $this->object->accessHandler();
73
74 $this->input_factory = $factory;
75 $this->refinery = $refinery;
76 $this->ui_renderer = $ui_renderer;
77 $this->http_request = $http_request;
78
79 $this->error_object = $error_object;
80 $this->common_settings_gui = $common_settings_gui;
81
82 $this->getSubTabs($this->tabs_gui);
83 $this->lng->loadLanguageModule('content');
84 $this->lng->loadLanguageModule('obj');
85 $this->lng->loadLanguageModule('cntr');
86 }
87
88 protected function getSubTabs(ilTabsGUI $tabs): void
89 {
90 $tabs->addSubTab(
91 self::TAB_EDIT,
92 $this->lng->txt("general"),
93 $this->ctrl->getLinkTarget($this, 'edit')
94 );
95 $tabs->addSubTab(
96 self::TAB_COMMON_SETTINGS,
97 $this->lng->txt("obj_features"),
98 $this->ctrl->getLinkTargetByClass(
99 [
100 self::class,
101 ilIndividualAssessmentCommonSettingsGUI::class
102 ],
104 )
105 );
106 $tabs->addSubTab(
107 self::TAB_EDIT_INFO,
108 $this->lng->txt("iass_edit_info"),
109 $this->ctrl->getLinkTarget($this, 'editInfo')
110 );
111 }
112
113 public function executeCommand(): void
114 {
115 if (!$this->iass_access->mayEditObject()) {
116 $this->handleAccessViolation();
117 }
118 $next_class = $this->ctrl->getNextClass();
119 $cmd = $this->ctrl->getCmd();
120 switch ($next_class) {
121 case 'ilindividualassessmentcommonsettingsgui':
122 $this->tabs_gui->activateSubTab(self::TAB_COMMON_SETTINGS);
123 $this->ctrl->forwardCommand($this->common_settings_gui);
124 break;
125 default:
126 switch ($cmd) {
127 case 'edit':
128 $this->edit();
129 break;
130 case 'update':
131 $this->update();
132 break;
133 case 'editInfo':
134 $this->editInfo();
135 break;
136 case 'updateInfo':
137 $this->updateInfo();
138 break;
139 }
140 }
141 }
142
143 protected function buildForm(): Form\Form
144 {
145 $settings = $this->object->getSettings();
146 $field = $settings->toFormInput(
147 $this->input_factory->field(),
148 $this->lng,
149 $this->refinery
150 );
151
152 // Use centralized on/offline
153 $online = $this->object->getObjectProperties()->getPropertyIsOnline()->toForm(
154 $this->lng,
155 $this->input_factory->field(),
156 $this->refinery
157 );
158 $availability = $this->input_factory->field()->section(
159 [$online],
160 $this->lng->txt('iass_settings_availability')
162 $this->refinery->custom()->transformation(function ($v) {
163 return array_shift($v);
164 })
165 );
166
167 return $this->input_factory->container()->form()->standard(
168 $this->ctrl->getFormAction($this, "update"),
169 [$field, $availability]
170 );
171 }
172
173 protected function edit(): void
174 {
175 $this->tabs_gui->setSubTabActive(self::TAB_EDIT);
176 $form = $this->buildForm();
177 $this->tpl->setContent($this->ui_renderer->render($form));
178 }
179
180 protected function update(): void
181 {
182 $form = $this->buildForm();
183 $form = $form->withRequest($this->http_request);
184
185 $settings = $form->getData();
186
187 if (!is_null($settings)) {
188 $this->object->setSettings($settings[0]);
189 $this->object->update();
190
191 $this->object->getObjectProperties()->storePropertyIsOnline($settings[1]);
192
193 $this->tpl->setOnScreenMessage("success", $this->lng->txt("settings_saved"), true);
194 $this->ctrl->redirect($this, "edit");
195 } else {
196 $this->tpl->setContent($this->ui_renderer->render($form));
197 }
198 }
199
200 protected function editInfo(): void
201 {
202 $this->tabs_gui->setSubTabActive(self::TAB_EDIT_INFO);
203 $form = $this->buildInfoSettingsForm();
204 $this->tpl->setContent($this->ui_renderer->render($form));
205 }
206
207 protected function updateInfo(): void
208 {
209 $form = $this->buildInfoSettingsForm();
210 $form = $form->withRequest($this->http_request);
211
212 $info_settings = $form->getData();
213
214 if (!is_null($info_settings)) {
215 $this->object->setInfoSettings($info_settings);
216 $this->object->updateInfo();
217 $this->ctrl->redirect($this, "editInfo");
218 } else {
219 $this->tpl->setContent($this->ui_renderer->render($form));
220 }
221 }
222
223 protected function buildInfoSettingsForm(): Form\Form
224 {
225 $info_settings = $this->object->getInfoSettings();
226 $field = $info_settings->toFormInput(
227 $this->input_factory->field(),
228 $this->lng,
229 $this->refinery
230 );
231 return $this->input_factory->container()->form()->standard(
232 $this->ctrl->getFormAction($this, "updateInfo"),
233 [$field]
234 )
236 $this->refinery->custom()->transformation(function ($v) {
237 return array_shift($v);
238 })
239 );
240 }
241
242 public function handleAccessViolation(): void
243 {
244 $this->error_object->raiseError($this->lng->txt("msg_no_perm_read"), $this->error_object->WARNING);
245 }
246}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Definition: UI.php:24
Class ilCtrl provides processing control methods.
Error Handling & global info handling.
@ilCtrl_Calls ilIndividualAssessmentSettingsGUI: ilIndividualAssessmentCommonSettingsGUI
__construct(ilObjIndividualAssessment $object, ilCtrl $ctrl, ilGlobalPageTemplate $tpl, ilLanguage $lng, ilTabsGUI $tabs_gui, Input\Factory $factory, Refinery\Factory $refinery, UI\Renderer $ui_renderer, $http_request, ilErrorHandling $error_object, ilIndividualAssessmentCommonSettingsGUI $common_settings_gui)
ilIndividualAssessmentCommonSettingsGUI $common_settings_gui
language handling
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the data of the form.
This describes commonalities between all forms.
Definition: Form.php:33
This is how a factory for inputs looks like.
Definition: Factory.php:27
This describes commonalities between all inputs.
Definition: Input.php:47
An entity that renders components to a string output.
Definition: Renderer.php:31
Mechanic regarding the access control and roles of an objet goes here.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
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...