ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTGroupFormBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTFormBridge.php";
4
6{
7 protected $elements = []; // [array]
8
9 protected function isValidADT(ilADT $a_adt)
10 {
11 return ($a_adt instanceof ilADTGroup);
12 }
13
14 protected function prepareElements()
15 {
16 if (sizeof($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($name);
29 }
30 }
31
32 public function getElements()
33 {
34 $this->prepareElements();
35 return $this->elements;
36 }
37
38 public function getElement($a_name)
39 {
40 $this->prepareElements();
41 if (array_key_exists($a_name, $this->elements)) {
42 return $this->elements[$a_name];
43 }
44 }
45
46 public function addToForm()
47 {
48 if ($this->getTitle()) {
50 $section->setTitle($this->getTitle());
51
52 if ($this->getInfo()) {
53 $section->setInfo($this->getInfo());
54 }
55
56 $this->getForm()->addItem($section);
57 }
58
59 $this->prepareElements();
60 foreach ($this->elements as $element) {
61 $element->addToForm();
62 }
63 }
64
65 public function addJS(ilTemplate $a_tpl)
66 {
67 $this->prepareElements();
68 foreach ($this->elements as $element) {
69 $element->addJS($a_tpl);
70 }
71 }
72
73 public function importFromPost()
74 {
75 $this->prepareElements();
76 foreach ($this->elements as $element) {
77 // parse parent element
78 $parent = $element->getParentElement();
79 if ($parent) {
80 if (is_array($parent)) {
81 $parent = $parent[0];
82 }
83 if (isset($adt_forms[$parent])) {
84 $parent = $adt_forms[$parent];
85 } else {
86 $parent = null;
87 }
88 }
89 if ($element->shouldBeImportedFromPost($parent)) {
90 $element->importFromPost();
91 }
92 }
93 }
94
95 public function validate()
96 {
97 global $DIC;
98
99 $lng = $DIC['lng'];
100
101 $valid = true;
102
103 // ilADTFormBridge->isRequired() != ilADT->allowNull()
104 foreach ($this->getElements() as $element_id => $element) {
105 if ($element->isRequired() && $element->getADT()->isNull()) {
106 $field = $this->getForm()->getItemByPostvar($element_id);
107 $field->setAlert($lng->txt("msg_input_is_required"));
108 $valid = false;
109 }
110 // #17232 - date time input GUI special case
111 elseif (!$element->validate()) {
112 $valid = false;
113 }
114 }
115
116 if (!$this->getADT()->isValid()) {
117 $tmp = array();
118
119 // map errors to elements
120
121 $mess = $this->getADT()->getValidationErrorsByElements();
122 foreach ($mess as $error_code => $element_id) {
123 $tmp[$element_id][] = $this->getADT()->translateErrorCode($error_code);
124 }
125
126 foreach ($tmp as $element_id => $errors) {
127 $field = $this->getForm()->getItemByPostvar($element_id);
128 $field->setAlert(implode("<br />", $errors));
129 }
130
131 $valid = false;
132 }
133
134 return $valid;
135 }
136}
$factory
Definition: metadata.php:43
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Get singleton.
ADT form bridge base class.
importFromPost()
Import values from form request POST data.
validate()
Validate ADT and parse error codes.
addJS(ilTemplate $a_tpl)
Add ADT-specific JS-files to template.
addToForm()
Add ADT-specific fields to form.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
ADT base class.
Definition: class.ilADT.php:12
This class represents a section header in a property form.
special template class to simplify handling of ITX/PEAR
$valid
$errors
Definition: index.php:6
global $DIC
Definition: saml.php:7
$lng