ILIAS  release_8 Revision v8.24
class.ilADTGroupFormBridge.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6{
7 protected array $elements = [];
8
9 protected function isValidADT(ilADT $a_adt): bool
10 {
11 return ($a_adt instanceof ilADTGroup);
12 }
13
14 protected function prepareElements(): void
15 {
16 if (count($this->elements)) {
17 return;
18 }
19
20 $this->elements = array();
22
23 // convert ADTs to form bridges
24
25 foreach ($this->getADT()->getElements() as $name => $element) {
26 $this->elements[$name] = $factory->getFormBridgeForInstance($element);
27 $this->elements[$name]->setForm($this->getForm());
28 $this->elements[$name]->setElementId((string) $name);
29 }
30 }
31
32 public function getElements(): array
33 {
34 $this->prepareElements();
35 return $this->elements;
36 }
37
38 public function getElement(string $a_name): ?ilADTFormBridge
39 {
40 $this->prepareElements();
41 if (array_key_exists($a_name, $this->elements)) {
42 return $this->elements[$a_name];
43 }
44 return null;
45 }
46
47 public function addToForm(): void
48 {
49 if ($this->getTitle()) {
50 $section = new ilFormSectionHeaderGUI();
51 $section->setTitle($this->getTitle());
52
53 if ($this->getInfo()) {
54 $section->setInfo($this->getInfo());
55 }
56
57 $this->getForm()->addItem($section);
58 }
59
60 $this->prepareElements();
61 foreach ($this->elements as $element) {
62 $element->addToForm();
63 }
64 }
65
66 public function addJS(ilGlobalTemplateInterface $a_tpl): void
67 {
68 $this->prepareElements();
69 foreach ($this->elements as $element) {
70 $element->addJS($a_tpl);
71 }
72 }
73
74 public function importFromPost(): void
75 {
76 $this->prepareElements();
77 foreach ($this->elements as $element) {
78 // parse parent element
79 $parent = $element->getParentElement();
80 if ($parent) {
81 if (is_array($parent)) {
82 $parent = $parent[0];
83 }
84 $parent = $adt_forms[$parent] ?? null;
85 }
86 if ($element->shouldBeImportedFromPost($parent)) {
87 $element->importFromPost();
88 }
89 }
90 }
91
92 public function validate(): bool
93 {
94 $valid = true;
95
96 // ilADTFormBridge->isRequired() != ilADT->allowNull()
97 foreach ($this->getElements() as $element_id => $element) {
98 if ($element->isRequired() && $element->getADT()->isNull()) {
99 $field = $this->getForm()->getItemByPostVar($element_id);
100 $field->setAlert($this->lng->txt("msg_input_is_required"));
101 $valid = false;
102 } // #17232 - date time input GUI special case
103 elseif (!$element->validate()) {
104 $valid = false;
105 }
106 }
107
108 if (!$this->getADT()->isValid()) {
109 $tmp = array();
110
111 // map errors to elements
112
113 $mess = $this->getADT()->getValidationErrorsByElements();
114 foreach ($mess as $error_code => $element_id) {
115 $tmp[$element_id][] = $this->getADT()->translateErrorCode($error_code);
116 }
117
118 foreach ($tmp as $element_id => $errors) {
119 $field = $this->getForm()->getItemByPostVar((string) $element_id);
120 $field->setAlert(implode("<br />", $errors));
121 }
122
123 $valid = false;
124 }
125
126 return $valid;
127 }
128}
ADT form bridge base class.
importFromPost()
Import values from form request POST data.
addJS(ilGlobalTemplateInterface $a_tpl)
Add ADT-specific JS-files to template.
addToForm()
Add ADT-specific fields to form.
ADT base class.
Definition: class.ilADT.php:12
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$valid
$errors
Definition: imgupload.php:65
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$factory
Definition: metadata.php:75
if($format !==null) $name
Definition: metadata.php:247