ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilStudyProgrammeChangeExpireDateGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5declare(strict_types=1);
6
7use GuzzleHttp\Psr7\ServerRequest;
12
14{
15 const CMD_SHOW_EXPIRE_DATE_CONFIG = "showExpireDateConfig";
16 const CMD_CHANGE_EXPIRE_DATE = "changeExpireDate";
17 const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
18
22 protected $gui;
23
27 protected $ctrl;
28
32 protected $tpl;
33
37 protected $lng;
38
42 protected $access;
43
47 protected $user;
48
52 protected $back_target;
53
57 protected $input_factory;
58
62 protected $renderer;
63
67 protected $request;
68
73
77 protected $data_factory;
78
83
87 protected $progress_ids;
88
92 protected $ref_id;
93
97 protected $object;
98
99 public function __construct(
107 ServerRequest $request,
111 ) {
112 $this->ctrl = $ctrl;
113 $this->tpl = $tpl;
114 $this->lng = $lng;
115 $this->access = $access;
116 $this->user = $user;
117 $this->input_factory = $input_factory;
118 $this->renderer = $renderer;
119 $this->request = $request;
120 $this->refinery_factory = $refinery_factory;
121 $this->data_factory = $data_factory;
122 $this->user_progress_db = $user_progress_db;
123 }
124
125 public function executeCommand() : void
126 {
127 $next_class = $this->ctrl->getNextClass($this);
128 $cmd = $this->ctrl->getCmd();
129
130 switch ($next_class) {
131 default:
132 switch ($cmd) {
134 $this->showExpireDateConfig();
135 break;
137 $this->changeExpireDate();
138 break;
139 case 'cancel':
140 $this->redirectToParent();
141 break;
142 default:
143 throw new Exception('Unknown command ' . $cmd);
144 break;
145 }
146 break;
147 }
148 }
149
150 protected function showExpireDateConfig() : void
151 {
152 $this->tpl->loadStandardTemplate();
153 $this->ctrl->setParameter($this, 'prgrs_ids', implode(',', $this->getProgressIds()));
154 $action = $this->ctrl->getFormAction(
155 $this,
156 self::CMD_CHANGE_EXPIRE_DATE
157 );
158 $this->ctrl->clearParameters($this);
159
160 $form = $this->buildForm($this->getObject(), $action);
161
162 $this->tpl->setContent($this->renderer->render($form));
163 }
164
165 protected function buildForm(ilObjStudyProgramme $prg, string $submit_action) : Standard
166 {
167 $ff = $this->input_factory->field();
168 $txt = function ($id) {
169 return $this->lng->txt($id);
170 };
171
172 return $this->input_factory->container()->form()->standard(
173 $submit_action,
174 $this->buildFormElements(
175 $ff,
176 $txt,
177 $prg
178 )
179 );
180 }
181
183 {
184 $ff = $this->input_factory->field();
185 $txt = function ($id) {
186 return $this->lng->txt($id);
187 };
188
190 $format = $this->data_factory->dateFormat()->germanShort();
191 $vq_date_sub_form = $ff
192 ->dateTime('', $txt('validity_qualification_date_desc'))
193 ->withMinValue(new DateTimeImmutable())
194 ->withFormat($format);
195 $date = $prg->getValidityOfQualificationSettings()->getQualificationDate();
196 if ($date !== null) {
197 $vq_date_sub_form = $vq_date_sub_form->withValue($date->format($format->toString()));
199 }
200
201 $sg = $ff->switchableGroup(
202 [
204 $ff->group([], $txt('prg_no_validity_qualification')),
206 $ff->group([$vq_date_sub_form], $txt('validity_qualification_date'))
207 ],
208 ''
209 );
210 return $sg->withValue($option);
211 }
212
213 protected function buildFormElements(
214 \ILIAS\UI\Component\Input\Field\Factory $ff,
215 Closure $txt,
217 ) : array {
218 return [
219 $ff->section(
220 [
222 ],
223 $txt("prg_validity_of_qualification"),
224 ""
225 )
226 ];
227 }
228
229 protected function changeExpireDate() : void
230 {
231 $form = $this
232 ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "changeExpireDate"))
233 ->withRequest($this->request);
234
235 $result = $form->getInputGroup()->getContent();
236
237 if ($result->isOK()) {
238 $values = $result->value();
239 foreach ($this->getProgressIds() as $prgs_id) {
241 $progress = $this->user_progress_db->getInstanceById($prgs_id);
242 $status = $progress->getStatus();
243
244 if (
247 ) {
248 continue;
249 }
250
251 $vq_data = $values[0][self::PROP_VALIDITY_OF_QUALIFICATION];
252 $vq_type = $vq_data[0];
253
254 switch ($vq_type) {
256 $progress->setValidityOfQualification(null);
257 break;
259 $progress->setValidityOfQualification(
260 DateTime::createFromFormat('d.m.Y', array_shift($vq_data[1]))
261 );
262 break;
263 }
264
265 $progress->updateProgress($this->user->getId());
266 $progress->updateFromProgramNode();
267 }
268
269 ilUtil::sendSuccess($this->lng->txt('update_expire_date'), true);
270 $this->ctrl->redirectByClass('ilObjStudyProgrammeMembersGUI', 'view');
271 }
272
273 ilUtil::sendFailure($this->lng->txt('error_updating_expire_date'), true);
274 $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_EXPIRE_DATE_CONFIG);
275 }
276
277 protected function getBackTarget() : string
278 {
279 return $this->back_target;
280 }
281
282 public function setBackTarget(string $target) : void
283 {
284 $this->back_target = $target;
285 }
286
287 protected function getProgressIds() : array
288 {
289 return $this->progress_ids;
290 }
291
292 public function setProgressIds(array $progress_ids) : void
293 {
294 $this->progress_ids = $progress_ids;
295 }
296
297 protected function getRefId() : int
298 {
299 return $this->ref_id;
300 }
301
302 public function setRefId(int $ref_id) : void
303 {
304 $this->ref_id = $ref_id;
305 }
306
307 protected function getObject() : ilObjStudyProgramme
308 {
309 if ($this->object === null) {
310 $this->object = ilObjStudyProgramme::getInstanceByRefId($this->getRefId());
311 }
312 return $this->object;
313 }
314
315 protected function redirectToParent() : void
316 {
317 ilUtil::redirect($this->getBackTarget());
318 }
319}
$result
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
This class provides processing control methods.
language handling
@ilCtrl_Calls ilObjStudyProgrammeSettingsGUI: ilStudyProgrammeCommonSettingsGUI
static getInstanceByRefId($a_ref_id)
buildForm(ilObjStudyProgramme $prg, string $submit_action)
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccess $access, ilObjUser $user, Factory $input_factory, Renderer $renderer, ServerRequest $request, \ILIAS\Refinery\Factory $refinery_factory, \ILIAS\Data\Factory $data_factory, ilStudyProgrammeUserProgressDB $user_progress_db)
buildFormElements(\ILIAS\UI\Component\Input\Field\Factory $ff, Closure $txt, ilObjStudyProgramme $prg)
Storage implementation for ilStudyProgrammeUserProgress.
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$txt
Definition: error.php:13
This describes a standard form.
Definition: Standard.php:11
This is how a factory for inputs looks like.
Definition: Factory.php:11
This describes commonalities between all inputs.
Definition: Input.php:32
An entity that renders components to a string output.
Definition: Renderer.php:15
$format
Definition: metadata.php:218
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.