ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
5 declare(strict_types=1);
6 
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 
72  protected $refinery_factory;
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(
100  ilCtrl $ctrl,
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) {
133  case self::CMD_SHOW_EXPIRE_DATE_CONFIG:
134  $this->showExpireDateConfig();
135  break;
136  case self::CMD_CHANGE_EXPIRE_DATE:
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  ->withFormat($format);
194  $date = $prg->getSettings()->getValidityOfQualificationSettings()->getQualificationDate();
195  if ($date !== null) {
196  $vq_date_sub_form = $vq_date_sub_form->withValue($date->format($format->toString()));
198  }
199 
200  $sg = $ff->switchableGroup(
201  [
203  $ff->group([], $txt('prg_no_validity_qualification')),
205  $ff->group([$vq_date_sub_form], $txt('validity_qualification_date'))
206  ],
207  ''
208  );
209  return $sg->withValue($option);
210  }
211 
212  protected function buildFormElements(
213  \ILIAS\UI\Component\Input\Field\Factory $ff,
214  Closure $txt,
216  ) : array {
217  return [
218  $ff->section(
219  [
221  ],
222  $txt("prg_validity_of_qualification"),
223  ""
224  )
225  ];
226  }
227 
228  protected function changeExpireDate() : void
229  {
230  $form = $this
231  ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "changeExpireDate"))
232  ->withRequest($this->request);
233 
234  $result = $form->getInputGroup()->getContent();
235 
236  $msg_collection = $this->messages->getMessageCollection('msg_change_expire_date');
237 
238  if ($result->isOK()) {
239  $values = $result->value();
240  $programme = $this->getObject();
241  $acting_usr_id = $this->user->getId();
242 
243  $vq_data = $values[0][self::PROP_VALIDITY_OF_QUALIFICATION];
244  $vq_type = $vq_data[0];
245  $validity = null;
247  $validity = DateTimeImmutable::createFromFormat('d.m.Y', array_shift($vq_data[1]));
248  if (!$validity) {
249  ilUtil::sendFailure($this->lng->txt('error_updating_expire_date'), true);
250  $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_EXPIRE_DATE_CONFIG);
251  }
252  }
253  foreach ($this->getProgressIds() as $progress_id) {
254  $programme->changeProgressValidityDate($progress_id, $acting_usr_id, $msg_collection, $validity, );
255  }
256 
257  $this->messages->showMessages($msg_collection);
258  $this->ctrl->redirectByClass('ilObjStudyProgrammeMembersGUI', 'view');
259  }
260  ilUtil::sendFailure($this->lng->txt('error_updating_expire_date'), true);
261  $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_EXPIRE_DATE_CONFIG);
262  }
263 
264  protected function getBackTarget() : string
265  {
266  return $this->back_target;
267  }
268 
269  public function setBackTarget(string $target) : void
270  {
271  $this->back_target = $target;
272  }
273 
274  protected function getProgressIds() : array
275  {
276  return $this->progress_ids;
277  }
278 
279  public function setProgressIds(array $progress_ids) : void
280  {
281  $this->progress_ids = array_map('intval', $progress_ids);
282  }
283 
284  protected function getRefId() : int
285  {
286  return $this->ref_id;
287  }
288 
289  public function setRefId(int $ref_id) : void
290  {
291  $this->ref_id = $ref_id;
292  }
293 
294  protected function getObject() : ilObjStudyProgramme
295  {
296  if ($this->object === null) {
297  $this->object = ilObjStudyProgramme::getInstanceByRefId($this->getRefId());
298  }
299  return $this->object;
300  }
301 
302  protected function redirectToParent() : void
303  {
305  }
306 }
An entity that renders components to a string output.
Definition: Renderer.php:14
This class provides processing control methods.
Class Factory.
$result
Util around ilPRGMessageCollection factors and output collections.
Class ChatMainBarProvider .
This is how a factory for inputs looks like.
Definition: Factory.php:10
__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)
user()
Definition: user.php:4
static getInstanceByRefId($a_ref_id)
$format
Definition: metadata.php:218
$txt
Definition: error.php:13
This describes a standard form.
Definition: Standard.php:10
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
buildFormElements(\ILIAS\UI\Component\Input\Field\Factory $ff, Closure $txt, ilObjStudyProgramme $prg)
static redirect($a_script)
buildForm(ilObjStudyProgramme $prg, string $submit_action)