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