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