@@ -24,39 +24,39 @@ discard block |
||
24 | 24 | private $_inverted; |
25 | 25 | |
26 | 26 | public function __construct($identifier, $modelInstance=NULL) { |
27 | - parent::__construct($identifier, null,$modelInstance); |
|
27 | + parent::__construct($identifier, null, $modelInstance); |
|
28 | 28 | $this->_form=new HtmlForm($identifier); |
29 | 29 | $this->_init(new FormInstanceViewer($identifier), 'form', $this->_form, true); |
30 | 30 | } |
31 | 31 | |
32 | - protected function _getFieldIdentifier($prefix,$name=''){ |
|
32 | + protected function _getFieldIdentifier($prefix, $name='') { |
|
33 | 33 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
34 | 34 | } |
35 | 35 | |
36 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
37 | - if(!$this->_generated){ |
|
36 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
37 | + if (!$this->_generated) { |
|
38 | 38 | $this->_instanceViewer->setInstance($this->_modelInstance); |
39 | 39 | |
40 | 40 | $form=$this->content['form']; |
41 | 41 | $this->_generateContent($form); |
42 | 42 | |
43 | - if(isset($this->_toolbar)){ |
|
43 | + if (isset($this->_toolbar)) { |
|
44 | 44 | $this->_setToolbarPosition($form); |
45 | 45 | } |
46 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,'form',PositionInTable::AFTERTABLE]); |
|
47 | - if($this->_inverted){ |
|
46 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, 'form', PositionInTable::AFTERTABLE]); |
|
47 | + if ($this->_inverted) { |
|
48 | 48 | $this->content['form']->setInverted(true); |
49 | 49 | } |
50 | 50 | $this->_generated=true; |
51 | 51 | } |
52 | - return parent::compile($js,$view); |
|
52 | + return parent::compile($js, $view); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @param HtmlForm $form |
57 | 57 | */ |
58 | - protected function _generateContent($form){ |
|
59 | - $values= $this->_instanceViewer->getValues(); |
|
58 | + protected function _generateContent($form) { |
|
59 | + $values=$this->_instanceViewer->getValues(); |
|
60 | 60 | $count=$this->_instanceViewer->count(); |
61 | 61 | $separators=$this->_instanceViewer->getSeparators(); |
62 | 62 | $headers=$this->_instanceViewer->getHeaders(); |
@@ -65,42 +65,42 @@ discard block |
||
65 | 65 | \sort($separators); |
66 | 66 | $size=\count($separators); |
67 | 67 | $nb=0; |
68 | - if($size===1){ |
|
68 | + if ($size===1) { |
|
69 | 69 | $i=-1; |
70 | - foreach ($values as $k=>$v){ |
|
71 | - $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++,$names[$k]??''); |
|
70 | + foreach ($values as $k=>$v) { |
|
71 | + $this->_generateFields($form, [$v], $headers, $i, $wrappers, $nb++, $names[$k] ?? ''); |
|
72 | 72 | $i++; |
73 | 73 | } |
74 | - }else{ |
|
74 | + } else { |
|
75 | 75 | $separators[]=$count; |
76 | - for($i=0;$i<$size;$i++){ |
|
77 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
78 | - $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers,$nb++,$names[$i]??''); |
|
76 | + for ($i=0; $i<$size; $i++) { |
|
77 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
78 | + $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers, $nb++, $names[$i] ?? ''); |
|
79 | 79 | } |
80 | 80 | } |
81 | - if($this->_hasRules && !$this->getForm()->hasValidationParams()){ |
|
81 | + if ($this->_hasRules && !$this->getForm()->hasValidationParams()) { |
|
82 | 82 | $this->setValidationParams(['inline'=>true]); |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb, $name){ |
|
86 | + protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb, $name) { |
|
87 | 87 | $wrapper=null; |
88 | - if(isset($headers[$sepFirst+1])) |
|
89 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
90 | - if(isset($wrappers[$sepFirst+1])){ |
|
88 | + if (isset($headers[$sepFirst+1])) |
|
89 | + $form->addHeader($headers[$sepFirst+1], 4, true); |
|
90 | + if (isset($wrappers[$sepFirst+1])) { |
|
91 | 91 | $wrapper=$wrappers[$sepFirst+1]; |
92 | 92 | } |
93 | 93 | $count=\count($values); |
94 | - if($count===1){ |
|
94 | + if ($count===1) { |
|
95 | 95 | $added=$form->addField($values[0]); |
96 | - }elseif($count>1){ |
|
96 | + }elseif ($count>1) { |
|
97 | 97 | $added=$form->addFields($values); |
98 | - }else |
|
98 | + } else |
|
99 | 99 | return; |
100 | - if(isset($wrapper)){ |
|
101 | - $added->wrap($wrapper[0],$wrapper[1]); |
|
100 | + if (isset($wrapper)) { |
|
101 | + $added->wrap($wrapper[0], $wrapper[1]); |
|
102 | 102 | } |
103 | - $this->execHook('onGenerateFields',$added,$nb,$name); |
|
103 | + $this->execHook('onGenerateFields', $added, $nb, $name); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,18 +108,18 @@ discard block |
||
108 | 108 | * the generated field is the first parameter |
109 | 109 | * @param callable $callback the fonction to call when a field is generated |
110 | 110 | */ |
111 | - public function onGenerateField($callback){ |
|
112 | - $this->addHook('onGenerateFields',$callback); |
|
111 | + public function onGenerateField($callback) { |
|
112 | + $this->addHook('onGenerateFields', $callback); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @return HtmlForm |
117 | 117 | */ |
118 | - public function getForm(){ |
|
118 | + public function getForm() { |
|
119 | 119 | return $this->content['form']; |
120 | 120 | } |
121 | 121 | |
122 | - public function addSeparatorAfter($fieldNum){ |
|
122 | + public function addSeparatorAfter($fieldNum) { |
|
123 | 123 | $fieldNum=$this->_getIndex($fieldNum); |
124 | 124 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
125 | 125 | return $this; |
@@ -134,12 +134,12 @@ discard block |
||
134 | 134 | return $this; |
135 | 135 | } |
136 | 136 | |
137 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
138 | - return $this->_fieldAs(function($id,$name,$value) use ($cssStyle){ |
|
139 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
137 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
138 | + return $this->_fieldAs(function($id, $name, $value) use ($cssStyle){ |
|
139 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
140 | 140 | $button->setProperty('type', 'reset'); |
141 | 141 | return $button; |
142 | - }, $index,$attributes); |
|
142 | + }, $index, $attributes); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
159 | 159 | } |
160 | 160 | |
161 | - public function addDividerBefore($index,$title){ |
|
161 | + public function addDividerBefore($index, $title) { |
|
162 | 162 | $index=$this->_getIndex($index); |
163 | 163 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
164 | 164 | return $this; |
165 | 165 | } |
166 | 166 | |
167 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
167 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
168 | 168 | $index=$this->_getIndex($index); |
169 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
169 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
170 | 170 | return $this; |
171 | 171 | } |
172 | 172 | |
173 | - public function run(JsUtils $js){ |
|
173 | + public function run(JsUtils $js) { |
|
174 | 174 | parent::run($js); |
175 | 175 | } |
176 | 176 |