ILIAS  release_8 Revision v8.24
class.ilIndividualAssessmentSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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;
43 protected Input\Factory $input_factory;
44 protected Refinery\Factory $refinery;
46
50 protected $http_request;
53
54 public function __construct(
61 Refinery\Factory $refinery,
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("edit"),
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 return $this->input_factory->container()->form()->standard(
152 $this->ctrl->getFormAction($this, "update"),
153 [$field]
154 )
155 ->withAdditionalTransformation(
156 $this->refinery->custom()->transformation(function ($v) {
157 return array_shift($v);
158 })
159 );
160 }
161
162 protected function edit(): void
163 {
164 $this->tabs_gui->setSubTabActive(self::TAB_EDIT);
165 $form = $this->buildForm();
166 $this->tpl->setContent($this->ui_renderer->render($form));
167 }
168
169 protected function update(): void
170 {
171 $form = $this->buildForm();
172 $form = $form->withRequest($this->http_request);
173
174 $settings = $form->getData();
175
176 if (!is_null($settings)) {
177 $this->object->setSettings($settings);
178 $this->object->update();
179 $this->tpl->setOnScreenMessage("success", $this->lng->txt("settings_saved"), true);
180 $this->ctrl->redirect($this, "edit");
181 } else {
182 $this->tpl->setContent($this->ui_renderer->render($form));
183 }
184 }
185
186 protected function editInfo(): void
187 {
188 $this->tabs_gui->setSubTabActive(self::TAB_EDIT_INFO);
189 $form = $this->buildInfoSettingsForm();
190 $this->tpl->setContent($this->ui_renderer->render($form));
191 }
192
193 protected function updateInfo(): void
194 {
195 $form = $this->buildInfoSettingsForm();
196 $form = $form->withRequest($this->http_request);
197
198 $info_settings = $form->getData();
199
200 if (!is_null($info_settings)) {
201 $this->object->setInfoSettings($info_settings);
202 $this->object->updateInfo();
203 $this->ctrl->redirect($this, "editInfo");
204 } else {
205 $this->tpl->setContent($this->ui_renderer->render($form));
206 }
207 }
208
209 protected function buildInfoSettingsForm(): Form\Form
210 {
211 $info_settings = $this->object->getInfoSettings();
212 $field = $info_settings->toFormInput(
213 $this->input_factory->field(),
214 $this->lng,
215 $this->refinery
216 );
217 return $this->input_factory->container()->form()->standard(
218 $this->ctrl->getFormAction($this, "updateInfo"),
219 [$field]
220 )
222 $this->refinery->custom()->transformation(function ($v) {
223 return array_shift($v);
224 })
225 );
226 }
227
228 public function handleAccessViolation(): void
229 {
230 $this->error_object->raiseError($this->lng->txt("msg_no_perm_read"), $this->error_object->WARNING);
231 }
232}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
Class ilCtrl provides processing control methods.
Error Handling & global info handling uses PEAR error class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@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
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...
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 describes commonalities between all inputs.
Definition: Input.php:49
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$factory
Definition: metadata.php:75
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
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...
Class Factory.