ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTGroupFormBridge.php
Go to the documentation of this file.
1 <?php
2 
3 require_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  {
18  return;
19  }
20 
21  $this->elements = array();
22  $factory = ilADTFactory::getInstance();
23 
24  // convert ADTs to form bridges
25 
26  foreach($this->getADT()->getElements() as $name => $element)
27  {
28  $this->elements[$name] = $factory->getFormBridgeForInstance($element);
29  $this->elements[$name]->setForm($this->getForm());
30  $this->elements[$name]->setElementId($name);
31  }
32  }
33 
34  public function getElements()
35  {
36  $this->prepareElements();
37  return $this->elements;
38  }
39 
40  public function getElement($a_name)
41  {
42  $this->prepareElements();
43  if(array_key_exists($a_name, $this->elements))
44  {
45  return $this->elements[$a_name];
46  }
47  }
48 
49  public function addToForm()
50  {
51  if($this->getTitle())
52  {
54  $section->setTitle($this->getTitle());
55 
56  if($this->getInfo())
57  {
58  $section->setInfo($this->getInfo());
59  }
60 
61  $this->getForm()->addItem($section);
62  }
63 
64  $this->prepareElements();
65  foreach($this->elements as $element)
66  {
67  $element->addToForm();
68  }
69  }
70 
71  public function addJS(ilTemplate $a_tpl)
72  {
73  $this->prepareElements();
74  foreach($this->elements as $element)
75  {
76  $element->addJS($a_tpl);
77  }
78  }
79 
80  public function importFromPost()
81  {
82  $this->prepareElements();
83  foreach($this->elements as $element)
84  {
85  // parse parent element
86  $parent = $element->getParentElement();
87  if($parent)
88  {
89  if(is_array($parent))
90  {
91  $parent = $parent[0];
92  }
93  if(isset($adt_forms[$parent]))
94  {
95  $parent = $adt_forms[$parent];
96  }
97  else
98  {
99  $parent = null;
100  }
101  }
102  if($element->shouldBeImportedFromPost($parent))
103  {
104  $element->importFromPost();
105  }
106  }
107  }
108 
109  public function validate()
110  {
111  global $lng;
112 
113  $valid = true;
114 
115  // ilADTFormBridge->isRequired() != ilADT->allowNull()
116  foreach($this->getElements() as $element_id => $element)
117  {
118  if($element->isRequired() && $element->getADT()->isNull())
119  {
120  $field = $this->getForm()->getItemByPostvar($element_id);
121  $field->setAlert($lng->txt("msg_input_is_required"));
122  $valid = false;
123  }
124  // #17232 - date time input GUI special case
125  else if(!$element->validate())
126  {
127  $valid = false;
128  }
129  }
130 
131  if(!$this->getADT()->isValid())
132  {
133  $tmp = array();
134 
135  // map errors to elements
136 
137  $mess = $this->getADT()->getValidationErrorsByElements();
138  foreach($mess as $error_code => $element_id)
139  {
140  $tmp[$element_id][] = $this->getADT()->translateErrorCode($error_code);
141  }
142 
143  foreach($tmp as $element_id => $errors)
144  {
145  $field = $this->getForm()->getItemByPostvar($element_id);
146  $field->setAlert(implode("<br />", $errors));
147  }
148 
149  $valid = false;
150  }
151 
152  return $valid;
153  }
154 }
155 
156 ?>
ADT form bridge base class.
This class represents a section header in a property form.
$valid
static getInstance()
Get singleton.
ADT base class.
Definition: class.ilADT.php:11
$section
Definition: Utf8Test.php:83
special template class to simplify handling of ITX/PEAR
Create styles array
The data for the language used.
$errors
global $lng
Definition: privfeed.php:17