ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ConfigurationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
26 {
27  protected const DEFAULT_CMD = 'showForm';
28 
29  protected \ilGlobalTemplateInterface $main_tpl;
30 
31  public function __construct(
32  private readonly Container $dic,
33  \ilObjectGUI $parentGui,
34  private readonly \ilObject $object
35  ) {
36  $this->main_tpl = $dic['tpl'];
37  }
38 
39  public function executeCommand(): void
40  {
41  $this->dic->ctrl()->getNextClass($this);
42  $cmd = $this->dic->ctrl()->getCmd(self::DEFAULT_CMD);
43 
44  switch (true) {
45  case method_exists($this, $cmd):
46  $this->{$cmd}();
47  break;
48 
49  default:
50  $this->{self::DEFAULT_CMD}();
51  break;
52  }
53  }
54 
55  protected function showForm(?\ilPropertyFormGUI $form = null): void
56  {
57  if (null === $form) {
58  $form = $this->getForm();
59  }
60 
61  $this->main_tpl->setContent($form->getHTML());
62  }
63 
64  protected function getForm(): \ilPropertyFormGUI
65  {
66  $this->dic->language()->loadLanguageModule('cntr');
67 
68  $form = new \ilPropertyFormGUI();
69  $form->setFormAction($this->dic->ctrl()->getFormAction($this, 'saveForm'));
70  $form->setTitle($this->dic->language()->txt('icon_settings'));
71 
72  $this->addSettingsToForm($form);
73 
74  $form->addCommandButton('saveForm', $this->dic->language()->txt('save'));
75 
76  return $form;
77  }
78 
79  public function addSettingsToForm(\ilPropertyFormGUI $form): void
80  {
84  throw new Exception('Not Implemented Exception!');
85  }
86 
87  protected function saveForm(): void
88  {
89  $form = $this->getForm();
90  if ($form->checkInput()) {
91  $this->saveIcon($form);
92 
93  $this->main_tpl->setOnScreenMessage('success', $this->dic->language()->txt('msg_obj_modified'), true);
94  $this->dic->ctrl()->redirect($this, 'showForm');
95  }
96 
97  $form->setValuesByPost();
98  $this->showForm($form);
99  }
100 
101  public function saveIcon(\ilPropertyFormGUI $form): void
102  {
103  $customIconFactory = $this->dic['object.customicons.factory'];
104  $customIcon = $customIconFactory->getByObjId($this->object->getId(), $this->object->getType());
105 
107  $fileData = (array) $form->getInput('icon');
108  $item = $form->getItemByPostVar('icon');
109 
110  if ($item && $item->getDeletionFlag()) {
111  $customIcon->remove();
112  }
113 
114  if (isset($fileData['tmp_name']) && $fileData['tmp_name']) {
115  $customIcon->saveFromHttpRequest();
116  }
117  }
118 }
getItemByPostVar(string $a_post_var)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private readonly Container $dic, \ilObjectGUI $parentGui, private readonly \ilObject $object)
Class ilObjectGUI Basic methods of all Output classes.
$dic
Definition: result.php:31