ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammeChangeDeadlineGUI.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_DEADLINE_CONFIG = "showDeadlineConfig";
16 const CMD_CHANGE_DEADLINE = "changeDeadline";
17 const PROP_DEADLINE = "deadline";
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
82 protected $progress_ids;
83
87 protected $ref_id;
88
92 protected $object;
93
97 protected $messages;
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->messages = $messages;
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->showDeadlineConfig();
135 break;
137 $this->changeDeadline();
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 showDeadlineConfig() : 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_DEADLINE
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 $deadline_date = $prg->getSettings()->getDeadlineSettings()->getDeadlineDate();
191 $format = $this->data_factory->dateFormat()->germanShort();
192 $deadline_date_sub_form = $ff
193 ->dateTime('', $txt('prg_deadline_date_desc'))
194 ->withFormat($format)
195 ;
196
197 if ($deadline_date !== null) {
198 $deadline_date_sub_form = $deadline_date_sub_form->withValue(
199 $deadline_date->format($format->toString())
200 );
202 }
203
204 $sg = $ff->switchableGroup(
205 [
207 $ff->group([], $txt('prg_no_deadline')),
209 $ff->group([$deadline_date_sub_form], $txt('prg_deadline_date'))
210 ],
211 ''
212 );
213
214 return $sg->withValue($option);
215 }
216
217 protected function buildFormElements(
218 $ff,
219 Closure $txt,
221 ) : array {
222 $return = [
223 $ff->section(
224 [
226 ],
227 $txt("prg_deadline_settings"),
228 ""
229 )
230 ];
231
232 return $return;
233 }
234
235 protected function changeDeadline() : void
236 {
237 $form = $this
238 ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "changeDeadline"))
239 ->withRequest($this->request);
240
241 $result = $form->getInputGroup()->getContent();
242
243 $msg_collection = $this->messages->getMessageCollection('msg_change_deadline_date');
244
245 if ($result->isOK()) {
246 $values = $result->value();
247 $programme = $this->getObject();
248 $acting_usr_id = $this->user->getId();
249
250 $deadline_data = $values[0][self::PROP_DEADLINE];
251 $deadline_type = $deadline_data[0];
252 $deadline = null;
254 $deadline = DateTimeImmutable::createFromFormat(
255 'd.m.Y',
256 array_shift($deadline_data[1])
257 );
258
259 if (!$deadline) {
260 ilUtil::sendFailure($this->lng->txt('error_updating_deadline'), true);
261 $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_DEADLINE_CONFIG);
262 }
263 }
264
265 foreach ($this->getProgressIds() as $progress_id) {
266 $programme->changeProgressDeadline($progress_id, $acting_usr_id, $msg_collection, $deadline);
267 }
268
269 $this->messages->showMessages($msg_collection);
270 $this->ctrl->redirectByClass('ilObjStudyProgrammeMembersGUI', 'view');
271 }
272
273 ilUtil::sendFailure($this->lng->txt('error_updating_deadline'), true);
274 $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_DEADLINE_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 = array_map('intval', $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()
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)
Util around ilPRGMessageCollection factors and output collections.
buildFormElements( $ff, Closure $txt, ilObjStudyProgramme $prg)
__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, ilPRGMessagePrinter $messages)
buildForm(ilObjStudyProgramme $prg, string $submit_action)
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.