ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilIndividualAssessmentSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5use \ILIAS\UI\Component\Input\Container\Form;
6use \ILIAS\UI\Component\Input;
7use \ILIAS\Refinery;
8use \ILIAS\UI;
9
14{
15 const TAB_EDIT = 'settings';
16 const TAB_EDIT_INFO = 'infoSettings';
17 const TAB_COMMON_SETTINGS = 'commonSettings';
18
22 protected $ctrl;
23
27 protected $object;
28
32 protected $tpl;
33
37 protected $lng;
38
42 protected $tabs_gui;
43
47 protected $iass_access;
48
52 protected $input_factory;
53
57 protected $refinery;
58
62 protected $ui_renderer;
63
67 protected $http_request;
68
72 protected $error_object;
73
75
76 public function __construct(
82 Input\Factory $factory,
83 Refinery\Factory $refinery,
88 ) {
89 $this->ctrl = $ctrl;
90 $this->object = $object;
91 $this->tpl = $tpl;
92 $this->lng = $lng;
93 $this->tabs_gui = $tabs_gui;
94 $this->iass_access = $this->object->accessHandler();
95
96 $this->input_factory = $factory;
97 $this->refinery = $refinery;
98 $this->ui_renderer = $ui_renderer;
99 $this->http_request = $http_request;
100
101 $this->error_object = $error_object;
102 $this->common_settings_gui = $common_settings_gui;
103
104 $this->getSubTabs($this->tabs_gui);
105 $this->lng->loadLanguageModule('content');
106 $this->lng->loadLanguageModule('obj');
107 $this->lng->loadLanguageModule('cntr');
108 }
109
110 protected function getSubTabs(ilTabsGUI $tabs)
111 {
112 $tabs->addSubTab(
113 self::TAB_EDIT,
114 $this->lng->txt("edit"),
115 $this->ctrl->getLinkTarget($this, 'edit')
116 );
117 $tabs->addSubTab(
118 self::TAB_COMMON_SETTINGS,
119 $this->lng->txt("obj_features"),
120 $this->ctrl->getLinkTargetByClass(
121 [
122 self::class,
123 ilIndividualAssessmentCommonSettingsGUI::class
124 ],
126 )
127 );
128 $tabs->addSubTab(
129 self::TAB_EDIT_INFO,
130 $this->lng->txt("iass_edit_info"),
131 $this->ctrl->getLinkTarget($this, 'editInfo')
132 );
133 }
134
135 public function executeCommand()
136 {
137 if (!$this->iass_access->mayEditObject()) {
138 $this->handleAccessViolation();
139 }
140 $next_class = $this->ctrl->getNextClass();
141 $cmd = $this->ctrl->getCmd();
142 switch ($next_class) {
143 case 'ilindividualassessmentcommonsettingsgui':
144 $this->tabs_gui->activateSubTab(self::TAB_COMMON_SETTINGS);
145 $this->ctrl->forwardCommand($this->common_settings_gui);
146 break;
147 default:
148 switch ($cmd) {
149 case 'edit':
150 $this->edit();
151 break;
152 case 'update':
153 $this->update();
154 break;
155 case 'editInfo':
156 $this->editInfo();
157 break;
158 case 'updateInfo':
159 $this->updateInfo();
160 break;
161 }
162 }
163 }
164
165 protected function buildForm() : Form\Form
166 {
167 $settings = $this->object->getSettings();
168 $field = $settings->toFormInput(
169 $this->input_factory->field(),
170 $this->lng,
171 $this->refinery
172 );
173 return $this->input_factory->container()->form()->standard(
174 $this->ctrl->getFormAction($this, "update"),
175 [$field]
176 )
178 $this->refinery->custom()->transformation(function ($v) {
179 return array_shift($v);
180 })
181 );
182 }
183
184 protected function edit()
185 {
186 $this->tabs_gui->setSubTabActive(self::TAB_EDIT);
187 $form = $this->buildForm();
188 $this->tpl->setContent($this->ui_renderer->render($form));
189 }
190
191 protected function update()
192 {
193 $form = $this->buildForm();
194 $form = $form->withRequest($this->http_request);
195
196 $settings = $form->getData();
197
198 if (!is_null($settings)) {
199 $this->object->setSettings($settings);
200 $this->object->update();
201 ilUtil::sendSuccess($this->lng->txt("iass_settings_saved"), true);
202 $this->ctrl->redirect($this, "edit");
203 } else {
204 $this->tpl->setContent($this->ui_renderer->render($form));
205 }
206 }
207
208 protected function editInfo()
209 {
210 $this->tabs_gui->setSubTabActive(self::TAB_EDIT_INFO);
211 $form = $this->buildInfoSettingsForm();
212 $this->tpl->setContent($this->ui_renderer->render($form));
213 }
214
215 protected function updateInfo()
216 {
217 $form = $this->buildInfoSettingsForm();
218 $form = $form->withRequest($this->http_request);
219
220 $info_settings = $form->getData();
221
222 if (!is_null($info_settings)) {
223 $this->object->setInfoSettings($info_settings);
224 $this->object->updateInfo();
225 ilUtil::sendSuccess($this->lng->txt("iass_settings_saved"), true);
226 $this->ctrl->redirect($this, "editInfo");
227 } else {
228 $this->tpl->setContent($this->ui_renderer->render($form));
229 }
230 }
231
232 protected function buildInfoSettingsForm() : Form\Form
233 {
234 $info_settings = $this->object->getInfoSettings();
235 $field = $info_settings->toFormInput(
236 $this->input_factory->field(),
237 $this->lng,
238 $this->refinery
239 );
240 return $this->input_factory->container()->form()->standard(
241 $this->ctrl->getFormAction($this, "updateInfo"),
242 [$field]
243 )
245 $this->refinery->custom()->transformation(function ($v) {
246 return array_shift($v);
247 })
248 );
249 }
250
251 public function handleAccessViolation()
252 {
253 $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
254 }
255}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
This class provides processing control methods.
Class ilGlobalPageTemplate.
@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)
language handling
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
Tabs GUI.
addSubTab($a_id, $a_text, $a_link, $a_frame="")
Add a Subtab.
This describes commonalities between all forms.
Definition: Form.php:16
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the data of the form.
An entity that renders components to a string output.
Definition: Renderer.php:15
$factory
Definition: metadata.php:58
Class Factory.