ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjStudyProgrammeSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6 /* Copyright (c) 2020 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
7 
12 
18 {
19  const TAB_SETTINGS = 'settings';
20  const TAB_COMMON_SETTINGS = 'commonSettings';
21 
22  const PROP_TITLE = "title";
23  const PROP_DESC = "desc";
24  const PROP_DEADLINE = "deadline";
25  const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
26  const PROP_ACCESS_CONTROL_BY_ORGU_POSITION = "access_ctr_by_orgu_position";
27 
28  const OPT_NO_DEADLINE = 'opt_no_deadline';
29  const OPT_DEADLINE_PERIOD = "opt_deadline_period";
30  const OPT_DEADLINE_DATE = "opt_deadline_date";
31 
32  const OPT_NO_VALIDITY_OF_QUALIFICATION = 'opt_no_validity_qualification';
33  const OPT_VALIDITY_OF_QUALIFICATION_PERIOD = "opt_validity_qualification_period";
34  const OPT_VALIDITY_OF_QUALIFICATION_DATE = "opt_validity_qualification_date";
35 
36 
40  public $ctrl;
41 
45  public $tpl;
46 
50  public $object;
51 
55  public $lng;
56 
60  protected $tmp_heading;
61 
65  protected $input_factory;
66 
70  protected $renderer;
71 
75  protected $request;
76 
80  protected $refinery_factory;
81 
85  protected $ref_id;
86 
90  protected $data_factory;
91 
95  protected $type_repository;
96 
101 
105  protected $tabs;
106 
107  public function __construct(
109  \ilCtrl $ilCtrl,
110  \ilLanguage $lng,
113  ServerRequest $request,
119  ) {
120  $this->tpl = $tpl;
121  $this->ctrl = $ilCtrl;
122  $this->lng = $lng;
123  $this->input_factory = $input_factory;
124  $this->renderer = $renderer;
125  $this->request = $request;
126  $this->refinery_factory = $refinery_factory;
127  $this->data_factory = $data_factory;
128  $this->type_repository = $type_repository;
129  $this->object = null;
130  $this->common_settings_gui = $common_settings_gui;
131  $this->tabs = $tabs;
132 
133  $lng->loadLanguageModule("prg");
134  }
135 
136  public function setRefId($a_ref_id)
137  {
138  $this->ref_id = $a_ref_id;
139  }
140 
141  public function executeCommand()
142  {
143  $next_class = $this->ctrl->getNextClass();
144  switch ($next_class) {
145  case 'ilstudyprogrammecommonsettingsgui':
146  $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
147  $this->common_settings_gui->setObject($this->getObject());
148  $content = $this->ctrl->forwardCommand($this->common_settings_gui);
149  break;
150  default:
151  $cmd = $this->ctrl->getCmd();
152  if ($cmd == "") {
153  $cmd = "view";
154  }
155  switch ($cmd) {
156  case "view":
157  $content = $this->view();
158  break;
159  case "update":
160  $content = $this->$cmd();
161  break;
162  default:
163  throw new ilException(
164  "ilObjStudyProgrammeSettingsGUI: " . "Command not supported: $cmd"
165  );
166  }
167  }
168 
169  if (!$this->ctrl->isAsynch()) {
170  $this->tpl->setContent($content);
171  } else {
172  $output_handler = new ilAsyncOutputHandler();
173  $heading = $this->lng->txt("prg_async_" . $this->ctrl->getCmd());
174  if (isset($this->tmp_heading)) {
175  $heading = $this->tmp_heading;
176  }
177  $output_handler->setHeading($heading);
178  $output_handler->setContent($content);
179  $output_handler->terminate();
180  }
181  }
182 
183  protected function view()
184  {
185  $this->buildModalHeading($this->lng->txt('prg_async_settings'), isset($_GET["currentNode"]));
186 
187  $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"));
188  return $this->renderer->render($form);
189  }
190 
191  protected function update()
192  {
193  $form = $this
194  ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"))
195  ->withRequest($this->request);
196 
197  $result = $form->getInputGroup()->getContent();
198 
199  // This could further improved by providing a new container for asynch-forms in the
200  // UI-Framework.
201 
202  if ($result->isOK()) {
203  $result->value()->update();
204  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
205 
206  if ($this->ctrl->isAsynch()) {
208  array(
209  "success" => true,
210  "message" => $this->lng->txt("msg_obj_modified"))
211  );
212  return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
213  } else {
214  $this->ctrl->redirect($this);
215  }
216  } else {
217  ilUtil::sendFailure($this->lng->txt("msg_form_save_error"));
218 
219  if ($this->ctrl->isAsynch()) {
221  array(
222  "success" => false,
223  "errors" => $form->getErrors())
224  );
225  return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
226  } else {
227  return $this->renderer->render($form);
228  }
229  }
230  }
231 
232  protected function buildModalHeading($label, $current_node)
233  {
234  if (!$current_node) {
235  $this->ctrl->saveParameterByClass('ilobjstudyprogrammesettingsgui', 'ref_id');
236  $heading_button = ilLinkButton::getInstance();
237  $heading_button->setCaption('prg_open_node');
238  $heading_button->setUrl(
239  $this->ctrl->getLinkTargetByClass(
240  'ilobjstudyprogrammetreegui',
241  'view'
242  )
243  );
244 
245  $heading =
246  "<div class=''>" .
247  $label .
248  "<div class='pull-right'>" .
249  $heading_button->render() .
250  "</div></div>"
251  ;
252  $this->tmp_heading = $heading;
253  } else {
254  $this->tmp_heading = "<div class=''>" . $label . "</div>";
255  }
256  }
257 
258  protected function buildForm(
259  \ilObjStudyProgramme $prg,
260  string $submit_action
261  ) : ILIAS\UI\Component\Input\Container\Form\Form {
262  $trans = $prg->getObjectTranslation();
263  $ff = $this->input_factory->field();
264  $sp_types = $this->type_repository->getAllTypesArray();
265  $settings = $prg->getSettings();
266 
267  return $this->input_factory->container()->form()->standard(
268  $submit_action,
269  $this->buildFormElements(
270  $ff,
271  $trans,
272  $sp_types,
273  $settings
274  )
275  )->withAdditionalTransformation(
276  $this->refinery_factory->custom()->transformation(
277  function ($values) use ($prg) {
278  $object_data = $values[0];
279  $prg->setTitle($object_data[self::PROP_TITLE]);
280  $prg->setDescription($object_data[self::PROP_DESC]);
281 
282  $settings = $prg->getSettings()
283  ->withAssessmentSettings($values['prg_assessment'])
284  ->withDeadlineSettings($values['prg_deadline'])
285  ->withValidityOfQualificationSettings($values['prg_validity_of_qualification'])
286  ->withAutoMailSettings($values['automail_settings'])
287  ->withTypeSettings($values['prg_type']);
288 
289  $prg->updateSettings($settings);
290  $prg->updateCustomIcon();
291  return $prg;
292  }
293  )
294  );
295  }
296 
297  protected function buildFormElements(
298  InputFieldFactory $ff,
299  ilObjectTranslation $trans,
300  array $sp_types,
301  ilStudyProgrammeSettings $settings
302  ) : array {
303  global $DIC;
304  $ilLng = $DIC->language();
305  $refinery = $DIC["refinery"];
306 
307  $return = [
308  $this->getEditSection($ff, $trans),
309  "prg_type" => $settings
310  ->getTypeSettings()
311  ->toFormInput($ff, $ilLng, $refinery, $sp_types)
312  ,
313  "prg_assessment" => $settings
315  ->toFormInput($ff, $ilLng, $refinery)
316  ,
317  "prg_deadline" => $settings
319  ->toFormInput($ff, $ilLng, $refinery, $this->data_factory)
320  ,
321  "prg_validity_of_qualification" => $settings
323  ->toFormInput($ff, $ilLng, $refinery, $this->data_factory)
324  ,
325  "automail_settings" => $settings
327  ->toFormInput($ff, $ilLng, $refinery)
328  ];
329 
330  return $return;
331  }
332 
333  protected function getEditSection(
334  InputFieldFactory $ff,
335  ilObjectTranslation $trans
336  ) {
337  $languages = ilMDLanguageItem::_getLanguages();
338  return $ff->section(
339  [
340  self::PROP_TITLE =>
341  $ff->text($this->txt("title"))
342  ->withValue($trans->getDefaultTitle())
343  ->withRequired(true),
344  self::PROP_DESC =>
345  $ff->textarea($this->txt("description"))
346  ->withValue($trans->getDefaultDescription() ?? "")
347  ],
348  $this->txt("prg_edit"),
349  $this->txt("language") . ": " . $languages[$trans->getDefaultLanguage()] .
350  ' <a href="' . $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "") .
351  '">&raquo; ' . $this->txt("obj_more_translations") . '</a>'
352  );
353  }
354 
355  protected function getObject() : ilObjStudyProgramme
356  {
357  if ($this->object === null) {
358  $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
359  }
360  return $this->object;
361  }
362 
363  protected function txt(string $code) : string
364  {
365  return $this->lng->txt($code);
366  }
367 }
Class ilAsyncOutputHandler Handles the output for async-requests.
An entity that renders components to a string output.
Definition: Renderer.php:14
This class provides processing control methods.
Class Factory.
$result
Tabs GUI.
$_GET["client_id"]
Class ChatMainBarProvider .
This is how a factory for inputs looks like.
Definition: Factory.php:10
buildFormElements(InputFieldFactory $ff, ilObjectTranslation $trans, array $sp_types, ilStudyProgrammeSettings $settings)
setTitle($a_title)
set object title
Covers the persistence of sp-type related information.
getDefaultDescription()
Get default description.
static getInstanceByRefId($a_ref_id)
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
global $DIC
Definition: goto.php:24
getDefaultTitle()
Get default title.
Builds data types.
Definition: Factory.php:19
getObjectTranslation()
Get object translation.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
loadLanguageModule($a_module)
setDescription($a_desc)
set object description
__construct(\ilGlobalTemplateInterface $tpl, \ilCtrl $ilCtrl, \ilLanguage $lng, Factory $input_factory, Renderer $renderer, ServerRequest $request, \ILIAS\Refinery\Factory $refinery_factory, \ILIAS\Data\Factory $data_factory, ilStudyProgrammeTypeRepository $type_repository, ilStudyProgrammeCommonSettingsGUI $common_settings_gui, ilTabsGUI $tabs)
getDefaultLanguage()
Get default language.
$response
buildForm(\ilObjStudyProgramme $prg, string $submit_action)
ilObjStudyProgrammeSettingsGUI: ilStudyProgrammeCommonSettingsGUI
static handleAsyncOutput($normal_content, $async_content=null, $apply_to_tpl=true)
Handles async output.
Class handles translation mode for an object.
updateSettings(ilStudyProgrammeSettings $settings)
getEditSection(InputFieldFactory $ff, ilObjectTranslation $trans)