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