ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
BaseForm.php
Go to the documentation of this file.
1 <?php
2 
21 
26 abstract class BaseForm extends \ilPropertyFormGUI
27 {
29  protected \ILIAS\DI\Container $DIC;
30  protected \ActiveRecord $object;
31  protected \ilLanguage $lng;
32  protected \ilCtrl $ctrl;
33 
37  public function __construct(BaseCommands $parent_gui, \ActiveRecord $object)
38  {
39  global $DIC;
40 
41  $this->parent_gui = $parent_gui;
42  $this->object = $object;
43  $this->lng = $DIC->language();
44 
45  $this->ctrl = $DIC->ctrl();
46  $this->ctrl->saveParameter($parent_gui, 'arid');
47  $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
48  $this->initFormElements();
49  $this->initButtons();
50  $this->setTarget('_top');
52  }
53 
54  abstract protected function initFormElements(): void;
55 
56  abstract public function fillForm(): void;
57 
58  abstract protected function fillObject(): bool;
59 
60  public function saveObject(): bool
61  {
62  if ($this->fillObject() === false) {
63  return false;
64  }
65  if ($this->object->getId()) {
66  $this->object->update();
67  } else {
68  $this->object->create();
69  }
70 
71  return $this->object->getId();
72  }
73 
74  private function initButtons(): void
75  {
76  if (!$this->object->getId()) {
77  $this->setTitle($this->txt('create'));
80  } else {
81  $this->setTitle($this->txt('update'));
84  }
85  }
86 
87 
88  private function txt(string $key): string
89  {
90  return $this->lng->txt($key);
91  }
92 
93  private function infoTxt(string $key): string
94  {
95  return $this->lng->txt($key . '_info');
96  }
97 }
This class represents a property form user interface.
setTarget(string $a_target)
setFormAction(string $a_formaction)
__construct(BaseCommands $parent_gui, \ActiveRecord $object)
Definition: BaseForm.php:37
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)