ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilStudyProgrammeChangeExpireDateGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 
27 {
28  private const CMD_SHOW_EXPIRE_DATE_CONFIG = "showExpireDateConfig";
29  private const CMD_CHANGE_EXPIRE_DATE = "changeExpireDate";
30  private const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
31 
32  protected ilCtrl $ctrl;
34  protected ilLanguage $lng;
35  protected ilAccess $access;
36  protected ilObjUser $user;
38  protected Renderer $renderer;
43 
44  protected ?string $back_target = null;
45  protected array $progress_ids = [];
46  protected ?int $ref_id = null;
47  protected ?ilObjStudyProgramme $object = null;
48 
49  public function __construct(
50  ilCtrl $ctrl,
52  ilLanguage $lng,
53  ilAccess $access,
54  ilObjUser $user,
55  Factory $input_factory,
56  Renderer $renderer,
57  Psr\Http\Message\ServerRequestInterface $request,
58  ILIAS\Refinery\Factory $refinery_factory,
59  ILIAS\Data\Factory $data_factory,
60  ilPRGMessagePrinter $messages
61  ) {
62  $this->ctrl = $ctrl;
63  $this->tpl = $tpl;
64  $this->lng = $lng;
65  $this->access = $access;
66  $this->user = $user;
67  $this->input_factory = $input_factory;
68  $this->renderer = $renderer;
69  $this->request = $request;
70  $this->refinery_factory = $refinery_factory;
71  $this->data_factory = $data_factory;
72  $this->messages = $messages;
73  }
74 
75  public function executeCommand(): void
76  {
77  $cmd = $this->ctrl->getCmd();
78 
79  switch ($cmd) {
80  case self::CMD_SHOW_EXPIRE_DATE_CONFIG:
81  $this->showExpireDateConfig();
82  break;
83  case self::CMD_CHANGE_EXPIRE_DATE:
84  $this->changeExpireDate();
85  break;
86  case 'cancel':
87  $this->redirectToParent();
88  break;
89  default:
90  throw new Exception('Unknown command ' . $cmd);
91  }
92  }
93 
94  protected function showExpireDateConfig(): void
95  {
96  $this->tpl->loadStandardTemplate();
97  $this->ctrl->setParameter($this, 'prgrs_ids', implode(',', $this->getProgressIds()));
98  $action = $this->ctrl->getFormAction(
99  $this,
100  self::CMD_CHANGE_EXPIRE_DATE
101  );
102  $this->ctrl->clearParameters($this);
103 
104  $form = $this->buildForm($this->getObject(), $action);
105 
106  $this->tpl->setContent($this->renderer->render($form));
107  }
108 
109  protected function buildForm(ilObjStudyProgramme $prg, string $submit_action): Standard
110  {
111  $ff = $this->input_factory->field();
112  $txt = function ($id) {
113  return $this->lng->txt($id);
114  };
115 
116  return $this->input_factory->container()->form()->standard(
117  $submit_action,
118  $this->buildFormElements(
119  $ff,
120  $txt,
121  $prg
122  )
123  );
124  }
125 
127  {
128  $ff = $this->input_factory->field();
129  $txt = function ($id) {
130  return $this->lng->txt($id);
131  };
132 
134  $format = $this->data_factory->dateFormat()->germanShort();
135  $vq_date_sub_form = $ff
136  ->dateTime('', $txt('validity_qualification_date_desc'))
137  ->withFormat($format);
138  $date = $prg->getSettings()->getValidityOfQualificationSettings()->getQualificationDate();
139  if ($date !== null) {
140  $vq_date_sub_form = $vq_date_sub_form->withValue($date->format($format->toString()));
142  }
143 
144  $sg = $ff->switchableGroup(
145  [
147  $ff->group([], $txt('prg_no_validity_qualification')),
149  $ff->group([$vq_date_sub_form], $txt('validity_qualification_date'))
150  ],
151  ''
152  );
153  return $sg->withValue($option);
154  }
155 
156  protected function buildFormElements(
157  ILIAS\UI\Component\Input\Field\Factory $ff,
158  Closure $txt,
160  ): array {
161  return [
162  $ff->section(
163  [
165  ],
166  $txt("prg_validity_of_qualification"),
167  ""
168  )
169  ];
170  }
171 
172  protected function changeExpireDate(): void
173  {
174  $form = $this
175  ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "changeExpireDate"))
176  ->withRequest($this->request);
177 
178  $result = $form->getInputGroup()->getContent();
179 
180  $msg_collection = $this->messages->getMessageCollection('msg_change_expire_date');
181 
182  if ($result->isOK()) {
183  $values = $result->value();
184  $programme = $this->getObject();
185  $acting_usr_id = $this->user->getId();
186 
187  $vq_data = $values[0][self::PROP_VALIDITY_OF_QUALIFICATION];
188  $vq_type = $vq_data[0];
189  $validity = null;
191  $validity = array_shift($vq_data[1]);
192  if (!$validity) {
193  $this->tpl->setOnScreenMessage("failure", $this->lng->txt('error_updating_expire_date'), true);
194  $this->ctrl->setParameter($this, 'prgrs_ids', implode(',', $this->getProgressIds()));
195  $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_EXPIRE_DATE_CONFIG);
196  }
197  }
198  foreach ($this->getProgressIds() as $progress_id) {
199  $assignment_id = $progress_id->getAssignmentId();
200  $programme->changeProgressValidityDate($assignment_id, $acting_usr_id, $msg_collection, $validity, );
201  }
202 
203  $this->messages->showMessages($msg_collection);
204  $this->ctrl->redirectByClass('ilObjStudyProgrammeMembersGUI', 'view');
205  }
206  $this->tpl->setOnScreenMessage("failure", $this->lng->txt('error_updating_expire_date'), true);
207  $this->ctrl->setParameter($this, 'prgrs_ids', implode(',', $this->getProgressIds()));
208  $this->ctrl->redirectByClass(self::class, self::CMD_SHOW_EXPIRE_DATE_CONFIG);
209  }
210 
211  protected function getBackTarget(): ?string
212  {
213  return $this->back_target;
214  }
215 
216  public function setBackTarget(string $target): void
217  {
218  $this->back_target = $target;
219  }
220 
221  protected function getProgressIds(): array
222  {
223  return $this->progress_ids;
224  }
225 
226  public function setProgressIds(array $progress_ids): void
227  {
228  $this->progress_ids = $progress_ids;
229  }
230 
231  protected function getRefId(): ?int
232  {
233  return $this->ref_id;
234  }
235 
236  public function setRefId(int $ref_id): void
237  {
238  $this->ref_id = $ref_id;
239  }
240 
241  protected function getObject(): ilObjStudyProgramme
242  {
243  $ref_id = $this->getRefId();
244  if (is_null($ref_id)) {
245  throw new LogicException("Can't create object. No ref_id given.");
246  }
247 
248  if ($this->object === null) {
249  $this->object = ilObjStudyProgramme::getInstanceByRefId($ref_id);
250  }
251  return $this->object;
252  }
253 
254  protected function redirectToParent(): void
255  {
256  $back_target = $this->getBackTarget();
257  if (is_null($back_target)) {
258  throw new LogicException("Can't redirect. No back target given.");
259  }
260 
261  $this->ctrl->redirectToURL($back_target);
262  }
263 }
An entity that renders components to a string output.
Definition: Renderer.php:30
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccess $access, ilObjUser $user, Factory $input_factory, Renderer $renderer, Psr\Http\Message\ServerRequestInterface $request, ILIAS\Refinery\Factory $refinery_factory, ILIAS\Data\Factory $data_factory, ilPRGMessagePrinter $messages)
Class Factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$format
Definition: metadata.php:235
$txt
Definition: error.php:13
This describes a standard form.
Definition: Standard.php:26
buildFormElements(ILIAS\UI\Component\Input\Field\Factory $ff, Closure $txt, ilObjStudyProgramme $prg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
buildForm(ilObjStudyProgramme $prg, string $submit_action)