ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilObjStudyProgrammeSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27
33{
34 private const TAB_SETTINGS = 'settings';
35 private const TAB_COMMON_SETTINGS = 'commonSettings';
36
37 public const PROP_TITLE = "title";
38 public const PROP_DESC = "desc";
39 public const PROP_DEADLINE = "deadline";
40 public const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
41
42 public const OPT_NO_DEADLINE = 'opt_no_deadline';
43 public const OPT_DEADLINE_PERIOD = "opt_deadline_period";
44 public const OPT_DEADLINE_DATE = "opt_deadline_date";
45
46 public const OPT_NO_VALIDITY_OF_QUALIFICATION = 'opt_no_validity_qualification';
47 public const OPT_VALIDITY_OF_QUALIFICATION_PERIOD = "opt_validity_qualification_period";
48 public const OPT_VALIDITY_OF_QUALIFICATION_DATE = "opt_validity_qualification_date";
49
51 protected ilCtrl $ctrl;
52 protected ilLanguage $lng;
55 protected Psr\Http\Message\ServerRequestInterface $request;
60 protected ilTabsGUI $tabs;
62 protected LOMServices $lom_services;
63
65 protected string $tmp_heading;
66 protected int $ref_id;
67
68 public function __construct(
70 ilCtrl $ilCtrl,
74 Psr\Http\Message\ServerRequestInterface $request,
80 ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper,
81 LOMServices $lom_services
82 ) {
83 $this->tpl = $tpl;
84 $this->ctrl = $ilCtrl;
85 $this->lng = $lng;
86 $this->input_factory = $input_factory;
87 $this->renderer = $renderer;
88 $this->request = $request;
89 $this->refinery_factory = $refinery_factory;
90 $this->data_factory = $data_factory;
91 $this->type_repository = $type_repository;
92 $this->common_settings_gui = $common_settings_gui;
93 $this->tabs = $tabs;
94 $this->request_wrapper = $request_wrapper;
95 $this->lom_services = $lom_services;
96
97 $this->object = null;
98
99 $lng->loadLanguageModule("prg");
100 }
101
102 public function setRefId(int $ref_id): void
103 {
104 $this->ref_id = $ref_id;
105 }
106
107 public function executeCommand(): void
108 {
109 $next_class = $this->ctrl->getNextClass();
110 switch ($next_class) {
111 case 'ilstudyprogrammecommonsettingsgui':
112 $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
113 $this->common_settings_gui->setObject($this->getObject());
114 $content = $this->ctrl->forwardCommand($this->common_settings_gui);
115 break;
116 default:
117 $cmd = $this->ctrl->getCmd();
118 if ($cmd === "" || $cmd === null) {
119 $cmd = "view";
120 }
121 switch ($cmd) {
122 case "view":
123 $content = $this->view();
124 break;
125 case "update":
126 $content = $this->$cmd();
127 break;
128 default:
129 throw new ilException(
130 "ilObjStudyProgrammeSettingsGUI: Command not supported: $cmd"
131 );
132 }
133 }
134
135 $this->tpl->setContent($content);
136 }
137
138 protected function view(): string
139 {
140 $this->tmp_heading = "<div class=''>" . $this->lng->txt('prg_async_settings') . "</div>";
141 $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"));
142 return $this->renderer->render($form);
143 }
144
148 protected function update()
149 {
150 $form = $this
151 ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"))
152 ->withRequest($this->request);
153
154 $result = $form->getInputGroup()->getContent();
155
156 if ($result->isOK()) {
157 $result->value()->update();
158 $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
159 $this->ctrl->redirect($this);
160 } else {
161 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("msg_form_save_error"));
162 return $this->renderer->render($form);
163 }
164 }
165
166 protected function buildForm(
168 string $submit_action
169 ): ILIAS\UI\Component\Input\Container\Form\Form {
170 $trans = $prg->getObjectTranslation();
171 $ff = $this->input_factory->field();
172 $sp_types = $this->type_repository->getAllTypesArray();
173 $settings = $prg->getSettings();
174
175 return $this->input_factory->container()->form()->standard(
176 $submit_action,
177 $this->buildFormElements(
178 $ff,
179 $trans,
180 $sp_types,
181 $settings
182 )
183 )->withAdditionalTransformation(
184 $this->refinery_factory->custom()->transformation(
185 function ($values) use ($prg) {
186 $object_data = $values[0];
187 $prg->setTitle($object_data[self::PROP_TITLE]);
188 $prg->setDescription($object_data[self::PROP_DESC]);
189
190 $settings = $prg->getSettings()
191 ->withAssessmentSettings($values['prg_assessment'])
192 ->withDeadlineSettings($values['prg_deadline'])
193 ->withValidityOfQualificationSettings($values['prg_validity_of_qualification'])
194 ->withAutoMailSettings($values['automail_settings'])
195 ->withTypeSettings($values['prg_type']);
196
197 $prg->updateSettings($settings);
198 $prg->updateCustomIcon();
199 return $prg;
200 }
201 )
202 );
203 }
204
205 protected function buildFormElements(
206 InputFieldFactory $ff,
207 Translations $trans,
208 array $sp_types,
210 ): array {
211 $return = [
212 $this->getEditSection($ff, $trans),
213 "prg_type" => $settings
214 ->getTypeSettings()
215 ->toFormInput($ff, $this->lng, $this->refinery_factory, $sp_types)
216 ,
217 "prg_assessment" => $settings
218 ->getAssessmentSettings()
219 ->toFormInput($ff, $this->lng, $this->refinery_factory)
220 ,
221 "prg_deadline" => $settings
222 ->getDeadlineSettings()
223 ->toFormInput($ff, $this->lng, $this->refinery_factory, $this->data_factory)
224 ,
225 "prg_validity_of_qualification" => $settings
226 ->getValidityOfQualificationSettings()
227 ->toFormInput($ff, $this->lng, $this->refinery_factory, $this->data_factory)
228 ,
229 "automail_settings" => $settings
230 ->getAutoMailSettings()
231 ->toFormInput($ff, $this->lng, $this->refinery_factory)
232 ];
233
234 return $return;
235 }
236
237 protected function getEditSection(
238 InputFieldFactory $ff,
239 Translations $trans
240 ): ILIAS\UI\Component\Input\Field\Section {
241 $lang = '?';
242 foreach ($this->lom_services->dataHelper()->getAllLanguages() as $language) {
243 if ($language->value() === $trans->getDefaultLanguage()) {
244 $lang = $language->presentableLabel();
245 }
246 }
247 return $ff->section(
248 [
249 self::PROP_TITLE =>
250 $ff->text($this->txt("title"))
251 ->withValue($trans->getDefaultTitle())
252 ->withRequired(true),
253 self::PROP_DESC =>
254 $ff->textarea($this->txt("description"))
255 ->withValue($trans->getDefaultDescription() ?? "")
256 ],
257 $this->txt("prg_edit"),
258 $this->txt("language") . ": " . $lang .
259 ' <a href="' . $this->ctrl->getLinkTargetByClass(TranslationGUI::class, "") .
260 '">&raquo; ' . $this->txt("obj_more_translations") . '</a>'
261 );
262 }
263
264 protected function getObject(): ilObjStudyProgramme
265 {
266 if ($this->object === null) {
267 $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
268 }
269 return $this->object;
270 }
271
272 protected function txt(string $code): string
273 {
274 return $this->lng->txt($code);
275 }
276}
renderer()
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
Class handles translation mode for an object.
Class ilCtrl provides processing control methods.
Base class for ILIAS Exception handling.
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
getEditSection(InputFieldFactory $ff, Translations $trans)
buildFormElements(InputFieldFactory $ff, Translations $trans, array $sp_types, ilStudyProgrammeSettings $settings)
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, LOMServices $lom_services)
Psr Http Message ServerRequestInterface $request
updateSettings(ilStudyProgrammeSettings $settings)
setTitle(string $title)
setDescription(string $description)
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
Covers the persistence of sp-type related information.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.