ILIAS  release_8 Revision v8.24
class.ilObjStudyProgrammeSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
24
30{
31 private const TAB_SETTINGS = 'settings';
32 private const TAB_COMMON_SETTINGS = 'commonSettings';
33
34 public const PROP_TITLE = "title";
35 public const PROP_DESC = "desc";
36 public const PROP_DEADLINE = "deadline";
37 public const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
38
39 public const OPT_NO_DEADLINE = 'opt_no_deadline';
40 public const OPT_DEADLINE_PERIOD = "opt_deadline_period";
41 public const OPT_DEADLINE_DATE = "opt_deadline_date";
42
43 public const OPT_NO_VALIDITY_OF_QUALIFICATION = 'opt_no_validity_qualification';
44 public const OPT_VALIDITY_OF_QUALIFICATION_PERIOD = "opt_validity_qualification_period";
45 public const OPT_VALIDITY_OF_QUALIFICATION_DATE = "opt_validity_qualification_date";
46
48 protected ilCtrl $ctrl;
49 protected ilLanguage $lng;
52 protected Psr\Http\Message\ServerRequestInterface $request;
57 protected ilTabsGUI $tabs;
59
61 protected string $tmp_heading;
62 protected int $ref_id;
63
64 public function __construct(
66 ilCtrl $ilCtrl,
70 Psr\Http\Message\ServerRequestInterface $request,
76 ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper
77 ) {
78 $this->tpl = $tpl;
79 $this->ctrl = $ilCtrl;
80 $this->lng = $lng;
81 $this->input_factory = $input_factory;
82 $this->renderer = $renderer;
83 $this->request = $request;
84 $this->refinery_factory = $refinery_factory;
85 $this->data_factory = $data_factory;
86 $this->type_repository = $type_repository;
87 $this->common_settings_gui = $common_settings_gui;
88 $this->tabs = $tabs;
89 $this->request_wrapper = $request_wrapper;
90
91 $this->object = null;
92
93 $lng->loadLanguageModule("prg");
94 }
95
96 public function setRefId(int $ref_id): void
97 {
98 $this->ref_id = $ref_id;
99 }
100
101 public function executeCommand(): void
102 {
103 $next_class = $this->ctrl->getNextClass();
104 switch ($next_class) {
105 case 'ilstudyprogrammecommonsettingsgui':
106 $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
107 $this->common_settings_gui->setObject($this->getObject());
108 $content = $this->ctrl->forwardCommand($this->common_settings_gui);
109 break;
110 default:
111 $cmd = $this->ctrl->getCmd();
112 if ($cmd === "" || $cmd === null) {
113 $cmd = "view";
114 }
115 switch ($cmd) {
116 case "view":
117 $content = $this->view();
118 break;
119 case "update":
120 $content = $this->$cmd();
121 break;
122 default:
123 throw new ilException(
124 "ilObjStudyProgrammeSettingsGUI: Command not supported: $cmd"
125 );
126 }
127 }
128
129 if (!$this->ctrl->isAsynch()) {
130 $this->tpl->setContent($content);
131 } else {
132 $output_handler = new ilAsyncOutputHandler();
133 $heading = $this->tmp_heading ?? $this->lng->txt("prg_async_" . $this->ctrl->getCmd());
134 $output_handler->setHeading($heading);
135 $output_handler->setContent($content);
136 $output_handler->terminate();
137 }
138 }
139
140 protected function view(): string
141 {
142 $this->buildModalHeading(
143 $this->lng->txt('prg_async_settings'),
144 $this->request_wrapper->has("currentNode")
145 );
146
147 $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"));
148 return $this->renderer->render($form);
149 }
150
154 protected function update()
155 {
156 $form = $this
157 ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"))
158 ->withRequest($this->request);
159
160 $result = $form->getInputGroup()->getContent();
161
162 // This could further be improved by providing a new container for async-forms in the
163 // UI-Framework.
164
165 if ($result->isOK()) {
166 $result->value()->update();
167 $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
168
169 if ($this->ctrl->isAsynch()) {
171 array(
172 "success" => true,
173 "message" => $this->lng->txt("msg_obj_modified"))
174 );
175 return ilAsyncOutputHandler::handleAsyncOutput($this->renderer->render($form), $response, false);
176 }
177
178 $this->ctrl->redirect($this);
179 } else {
180 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("msg_form_save_error"));
181
182 if ($this->ctrl->isAsynch()) {
184 array(
185 "success" => false,
186 "errors" => $form->getError())
187 );
188 return ilAsyncOutputHandler::handleAsyncOutput($this->renderer->render($form), $response, false);
189 }
190
191 return $this->renderer->render($form);
192 }
193 }
194
195 protected function buildModalHeading(string $label, bool $current_node): void
196 {
197 if (!$current_node) {
198 $this->ctrl->saveParameterByClass('ilobjstudyprogrammesettingsgui', 'ref_id');
199 $heading_button = ilLinkButton::getInstance();
200 $heading_button->setCaption('prg_open_node');
201 $heading_button->setUrl(
202 $this->ctrl->getLinkTargetByClass(
203 'ilobjstudyprogrammetreegui',
204 'view'
205 )
206 );
207
208 $heading =
209 "<div class=''>" .
210 $label .
211 "<div class='pull-right'>" .
212 $heading_button->render() .
213 "</div></div>"
214 ;
215 $this->tmp_heading = $heading;
216 } else {
217 $this->tmp_heading = "<div class=''>" . $label . "</div>";
218 }
219 }
220
221 protected function buildForm(
223 string $submit_action
224 ): ILIAS\UI\Component\Input\Container\Form\Form {
225 $trans = $prg->getObjectTranslation();
226 $ff = $this->input_factory->field();
227 $sp_types = $this->type_repository->getAllTypesArray();
228 $settings = $prg->getSettings();
229
230 return $this->input_factory->container()->form()->standard(
231 $submit_action,
232 $this->buildFormElements(
233 $ff,
234 $trans,
235 $sp_types,
237 )
238 )->withAdditionalTransformation(
239 $this->refinery_factory->custom()->transformation(
240 function ($values) use ($prg) {
241 $object_data = $values[0];
242 $prg->setTitle($object_data[self::PROP_TITLE]);
243 $prg->setDescription($object_data[self::PROP_DESC]);
244
245 $settings = $prg->getSettings()
246 ->withAssessmentSettings($values['prg_assessment'])
247 ->withDeadlineSettings($values['prg_deadline'])
248 ->withValidityOfQualificationSettings($values['prg_validity_of_qualification'])
249 ->withAutoMailSettings($values['automail_settings'])
250 ->withTypeSettings($values['prg_type']);
251
253 $prg->updateCustomIcon();
254 return $prg;
255 }
256 )
257 );
258 }
259
260 protected function buildFormElements(
261 InputFieldFactory $ff,
262 ilObjectTranslation $trans,
263 array $sp_types,
265 ): array {
266 $return = [
267 $this->getEditSection($ff, $trans),
268 "prg_type" => $settings
269 ->getTypeSettings()
270 ->toFormInput($ff, $this->lng, $this->refinery_factory, $sp_types)
271 ,
272 "prg_assessment" => $settings
273 ->getAssessmentSettings()
274 ->toFormInput($ff, $this->lng, $this->refinery_factory)
275 ,
276 "prg_deadline" => $settings
277 ->getDeadlineSettings()
278 ->toFormInput($ff, $this->lng, $this->refinery_factory, $this->data_factory)
279 ,
280 "prg_validity_of_qualification" => $settings
281 ->getValidityOfQualificationSettings()
282 ->toFormInput($ff, $this->lng, $this->refinery_factory, $this->data_factory)
283 ,
284 "automail_settings" => $settings
285 ->getAutoMailSettings()
286 ->toFormInput($ff, $this->lng, $this->refinery_factory)
287 ];
288
289 return $return;
290 }
291
292 protected function getEditSection(
293 InputFieldFactory $ff,
295 ): ILIAS\UI\Component\Input\Field\Section {
296 $languages = ilMDLanguageItem::_getLanguages();
297 $lang = array_key_exists($trans->getDefaultLanguage(), $languages) ? $languages[$trans->getDefaultLanguage()] : '?';
298 return $ff->section(
299 [
300 self::PROP_TITLE =>
301 $ff->text($this->txt("title"))
302 ->withValue($trans->getDefaultTitle())
303 ->withRequired(true),
304 self::PROP_DESC =>
305 $ff->textarea($this->txt("description"))
306 ->withValue($trans->getDefaultDescription() ?? "")
307 ],
308 $this->txt("prg_edit"),
309 $this->txt("language") . ": " . $lang .
310 ' <a href="' . $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "") .
311 '">&raquo; ' . $this->txt("obj_more_translations") . '</a>'
312 );
313 }
314
315 protected function getObject(): ilObjStudyProgramme
316 {
317 if ($this->object === null) {
318 $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
319 }
320 return $this->object;
321 }
322
323 protected function txt(string $code): string
324 {
325 return $this->lng->txt($code);
326 }
327}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:21
Class ilAsyncOutputHandler Handles the output for async-requests.
static handleAsyncOutput(string $normal_content, string $async_content=null, bool $apply_to_tpl=true)
Handles async output.
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
loadLanguageModule(string $a_module)
Load language module.
@ilCtrl_Calls ilObjStudyProgrammeSettingsGUI: ilStudyProgrammeCommonSettingsGUI
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
ilStudyProgrammeCommonSettingsGUI $common_settings_gui
ILIAS UI Component Input Factory $input_factory
buildFormElements(InputFieldFactory $ff, ilObjectTranslation $trans, array $sp_types, ilStudyProgrammeSettings $settings)
getEditSection(InputFieldFactory $ff, ilObjectTranslation $trans)
buildForm(ilObjStudyProgramme $prg, string $submit_action)
__construct(ilGlobalTemplateInterface $tpl, ilCtrl $ilCtrl, ilLanguage $lng, Factory $input_factory, Renderer $renderer, Psr\Http\Message\ServerRequestInterface $request, ILIAS\Refinery\Factory $refinery_factory, ILIAS\Data\Factory $data_factory, ilStudyProgrammeTypeRepository $type_repository, ilStudyProgrammeCommonSettingsGUI $common_settings_gui, ilTabsGUI $tabs, ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper)
Psr Http Message ServerRequestInterface $request
buildModalHeading(string $label, bool $current_node)
updateSettings(ilStudyProgrammeSettings $settings)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $title)
setDescription(string $desc)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface RequestWrapper.
This is how a factory for inputs looks like.
Definition: Factory.php:27
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$response
$lang
Definition: xapiexit.php:26