ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjStudyProgrammeSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
30 {
31  private const TAB_SETTINGS = 'settings';
32  private const TAB_COMMON_SETTINGS = 'commonSettings';
33 
34  public const PROP_TITLE = "title";
35  public const PROP_DESC = "desc";
36  public const PROP_DEADLINE = "deadline";
37  public const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
38 
39  public const OPT_NO_DEADLINE = 'opt_no_deadline';
40  public const OPT_DEADLINE_PERIOD = "opt_deadline_period";
41  public const OPT_DEADLINE_DATE = "opt_deadline_date";
42 
43  public const OPT_NO_VALIDITY_OF_QUALIFICATION = 'opt_no_validity_qualification';
44  public const OPT_VALIDITY_OF_QUALIFICATION_PERIOD = "opt_validity_qualification_period";
45  public const OPT_VALIDITY_OF_QUALIFICATION_DATE = "opt_validity_qualification_date";
46 
48  protected ilCtrl $ctrl;
49  protected ilLanguage $lng;
57  protected ilTabsGUI $tabs;
59 
61  protected string $tmp_heading;
62  protected int $ref_id;
63 
64  public function __construct(
66  ilCtrl $ilCtrl,
67  ilLanguage $lng,
68  Factory $input_factory,
69  Renderer $renderer,
70  Psr\Http\Message\ServerRequestInterface $request,
71  ILIAS\Refinery\Factory $refinery_factory,
72  ILIAS\Data\Factory $data_factory,
73  ilStudyProgrammeTypeRepository $type_repository,
74  ilStudyProgrammeCommonSettingsGUI $common_settings_gui,
75  ilTabsGUI $tabs,
76  ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper
77  ) {
78  $this->tpl = $tpl;
79  $this->ctrl = $ilCtrl;
80  $this->lng = $lng;
81  $this->input_factory = $input_factory;
82  $this->renderer = $renderer;
83  $this->request = $request;
84  $this->refinery_factory = $refinery_factory;
85  $this->data_factory = $data_factory;
86  $this->type_repository = $type_repository;
87  $this->common_settings_gui = $common_settings_gui;
88  $this->tabs = $tabs;
89  $this->request_wrapper = $request_wrapper;
90 
91  $this->object = null;
92 
93  $lng->loadLanguageModule("prg");
94  }
95 
96  public function setRefId(int $ref_id): void
97  {
98  $this->ref_id = $ref_id;
99  }
100 
101  public function executeCommand(): void
102  {
103  $next_class = $this->ctrl->getNextClass();
104  switch ($next_class) {
105  case 'ilstudyprogrammecommonsettingsgui':
106  $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
107  $this->common_settings_gui->setObject($this->getObject());
108  $content = $this->ctrl->forwardCommand($this->common_settings_gui);
109  break;
110  default:
111  $cmd = $this->ctrl->getCmd();
112  if ($cmd === "" || $cmd === null) {
113  $cmd = "view";
114  }
115  switch ($cmd) {
116  case "view":
117  $content = $this->view();
118  break;
119  case "update":
120  $content = $this->$cmd();
121  break;
122  default:
123  throw new ilException(
124  "ilObjStudyProgrammeSettingsGUI: Command not supported: $cmd"
125  );
126  }
127  }
128 
129  if (!$this->ctrl->isAsynch()) {
130  $this->tpl->setContent($content);
131  } else {
132  $output_handler = new ilAsyncOutputHandler();
133  $heading = $this->tmp_heading ?? $this->lng->txt("prg_async_" . $this->ctrl->getCmd());
134  $output_handler->setHeading($heading);
135  $output_handler->setContent($content);
136  $output_handler->terminate();
137  }
138  }
139 
140  protected function view(): string
141  {
142  $this->tmp_heading = "<div class=''>" . $this->lng->txt('prg_async_settings') . "</div>";
143  $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"));
144  return $this->renderer->render($form);
145  }
146 
150  protected function update()
151  {
152  $form = $this
153  ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"))
154  ->withRequest($this->request);
155 
156  $result = $form->getInputGroup()->getContent();
157 
158  // This could further be improved by providing a new container for async-forms in the
159  // UI-Framework.
160 
161  if ($result->isOK()) {
162  $result->value()->update();
163  $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
164 
165  if ($this->ctrl->isAsynch()) {
167  array(
168  "success" => true,
169  "message" => $this->lng->txt("msg_obj_modified"))
170  );
171  return ilAsyncOutputHandler::handleAsyncOutput($this->renderer->render($form), $response, false);
172  }
173 
174  $this->ctrl->redirect($this);
175  } else {
176  $this->tpl->setOnScreenMessage("failure", $this->lng->txt("msg_form_save_error"));
177 
178  if ($this->ctrl->isAsynch()) {
180  array(
181  "success" => false,
182  "errors" => $form->getError())
183  );
184  return ilAsyncOutputHandler::handleAsyncOutput($this->renderer->render($form), $response, false);
185  }
186 
187  return $this->renderer->render($form);
188  }
189  }
190 
191  protected function buildForm(
192  ilObjStudyProgramme $prg,
193  string $submit_action
194  ): ILIAS\UI\Component\Input\Container\Form\Form {
195  $trans = $prg->getObjectTranslation();
196  $ff = $this->input_factory->field();
197  $sp_types = $this->type_repository->getAllTypesArray();
198  $settings = $prg->getSettings();
199 
200  return $this->input_factory->container()->form()->standard(
201  $submit_action,
202  $this->buildFormElements(
203  $ff,
204  $trans,
205  $sp_types,
206  $settings
207  )
208  )->withAdditionalTransformation(
209  $this->refinery_factory->custom()->transformation(
210  function ($values) use ($prg) {
211  $object_data = $values[0];
212  $prg->setTitle($object_data[self::PROP_TITLE]);
213  $prg->setDescription($object_data[self::PROP_DESC]);
214 
215  $settings = $prg->getSettings()
216  ->withAssessmentSettings($values['prg_assessment'])
217  ->withDeadlineSettings($values['prg_deadline'])
218  ->withValidityOfQualificationSettings($values['prg_validity_of_qualification'])
219  ->withAutoMailSettings($values['automail_settings'])
220  ->withTypeSettings($values['prg_type']);
221 
222  $prg->updateSettings($settings);
223  $prg->updateCustomIcon();
224  return $prg;
225  }
226  )
227  );
228  }
229 
230  protected function buildFormElements(
231  InputFieldFactory $ff,
232  ilObjectTranslation $trans,
233  array $sp_types,
235  ): array {
236  $return = [
237  $this->getEditSection($ff, $trans),
238  "prg_type" => $settings
239  ->getTypeSettings()
240  ->toFormInput($ff, $this->lng, $this->refinery_factory, $sp_types)
241  ,
242  "prg_assessment" => $settings
244  ->toFormInput($ff, $this->lng, $this->refinery_factory)
245  ,
246  "prg_deadline" => $settings
248  ->toFormInput($ff, $this->lng, $this->refinery_factory, $this->data_factory)
249  ,
250  "prg_validity_of_qualification" => $settings
252  ->toFormInput($ff, $this->lng, $this->refinery_factory, $this->data_factory)
253  ,
254  "automail_settings" => $settings
256  ->toFormInput($ff, $this->lng, $this->refinery_factory)
257  ];
258 
259  return $return;
260  }
261 
262  protected function getEditSection(
263  InputFieldFactory $ff,
264  ilObjectTranslation $trans
265  ): ILIAS\UI\Component\Input\Field\Section {
266  $languages = ilMDLanguageItem::_getLanguages();
267  $lang = array_key_exists($trans->getDefaultLanguage(), $languages) ? $languages[$trans->getDefaultLanguage()] : '?';
268  return $ff->section(
269  [
270  self::PROP_TITLE =>
271  $ff->text($this->txt("title"))
272  ->withValue($trans->getDefaultTitle())
273  ->withRequired(true),
274  self::PROP_DESC =>
275  $ff->textarea($this->txt("description"))
276  ->withValue($trans->getDefaultDescription() ?? "")
277  ],
278  $this->txt("prg_edit"),
279  $this->txt("language") . ": " . $lang .
280  ' <a href="' . $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "") .
281  '">&raquo; ' . $this->txt("obj_more_translations") . '</a>'
282  );
283  }
284 
285  protected function getObject(): ilObjStudyProgramme
286  {
287  if ($this->object === null) {
288  $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
289  }
290  return $this->object;
291  }
292 
293  protected function txt(string $code): string
294  {
295  return $this->lng->txt($code);
296  }
297 }
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
Class ilAsyncOutputHandler Handles the output for async-requests.
An entity that renders components to a string output.
Definition: Renderer.php:30
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static handleAsyncOutput(string $normal_content, string $async_content=null, bool $apply_to_tpl=true)
Handles async output.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$response
Definition: xapitoken.php:93
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
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
$lang
Definition: xapiexit.php:26
__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)
ILIAS UI Component Input Factory $input_factory
setDescription(string $description)
ilObjStudyProgrammeSettingsGUI: ilStudyProgrammeCommonSettingsGUI
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateSettings(ilStudyProgrammeSettings $settings)
getEditSection(InputFieldFactory $ff, ilObjectTranslation $trans)