ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFileCommonSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  public const CMD_EDIT = 'editSettings';
25  public const CMD_SAVE = 'saveSettings';
26  private array $services;
27 
28  protected ilObjFile $object;
29  protected ilCtrl $ctrl;
31  protected ilLanguage $lng;
33 
34  public function __construct(
35  ilObjFile $object,
36  ilCtrl $ctrl,
38  ilLanguage $lng,
39  ilObjectService $object_service
40  ) {
41  $this->object = $object;
42  $this->ctrl = $ctrl;
43  $this->tpl = $tpl;
44  $this->lng = $lng;
45  $this->object_service = $object_service;
46  $this->services = [
48  ];
49  }
50 
51  public function executeCommand(): void
52  {
53  $cmd = $this->ctrl->getCmd();
54  switch ($cmd) {
55  case self::CMD_EDIT:
56  $this->editSettings();
57  break;
58  case self::CMD_SAVE:
59  $this->saveSettings();
60  break;
61  default:
62  throw new Exception('Unknown command ' . $cmd);
63  }
64  }
65 
66  protected function editSettings(ilPropertyFormGUI $form = null): void
67  {
68  if (is_null($form)) {
69  $form = $this->buildForm();
70  }
71  $this->tpl->setContent($form->getHTML());
72  }
73 
74  protected function buildForm(): ilPropertyFormGUI
75  {
76  $form = new ilPropertyFormGUI();
77  $form->setFormAction($this->ctrl->getFormAction($this));
78  $form->setTitle($this->txt('obj_features'));
79  $form->addCommandButton(self::CMD_SAVE, $this->txt('save'));
80  $form->addCommandButton(self::CMD_EDIT, $this->txt('cancel'));
81 
82  $this->addServiceSettingsToForm($form);
83  $this->addCommonFieldsToForm($form);
84 
85  return $form;
86  }
87 
88  protected function addServiceSettingsToForm(ilPropertyFormGUI $form): void
89  {
91  $this->object->getId(),
92  $form,
94  );
95  }
96 
97  protected function addCommonFieldsToForm(ilPropertyFormGUI $form): void
98  {
99  //
100  }
101 
102  protected function saveSettings(): void
103  {
104  $form = $this->buildForm();
105 
106  if (!$form->checkInput()) {
107  $form->setValuesByPost();
108  $this->editSettings($form);
109  return;
110  }
111 
113  $this->object->getId(),
114  $form,
116  );
117 
118  $this->tpl->setOnScreenMessage("success", $this->lng->txt('service_settings_saved'), true);
119  $this->ctrl->redirect($this, self::CMD_EDIT);
120  }
121 
122  protected function txt(string $code): string
123  {
124  return $this->lng->txt($code);
125  }
126 }
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
addServiceSettingsToForm(ilPropertyFormGUI $form)
Class ilObjFile.
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
editSettings(ilPropertyFormGUI $form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addCommonFieldsToForm(ilPropertyFormGUI $form)
__construct(ilObjFile $object, ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilObjectService $object_service)