@@ -249,6 +249,9 @@ discard block |
||
249 | 249 | return $this; |
250 | 250 | } |
251 | 251 | |
252 | + /** |
|
253 | + * @param integer $index |
|
254 | + */ |
|
252 | 255 | public static function setIndex($index) { |
253 | 256 | self::$index=$index; |
254 | 257 | } |
@@ -307,7 +310,7 @@ discard block |
||
307 | 310 | * The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position |
308 | 311 | * @param int $index postion of the compiled field |
309 | 312 | * @param callable $callback function called after the field compilation |
310 | - * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
|
313 | + * @return InstanceViewer |
|
311 | 314 | */ |
312 | 315 | public function afterCompile($index,$callback){ |
313 | 316 | $this->afterCompile[$index]=$callback; |
@@ -19,215 +19,215 @@ discard block |
||
19 | 19 | |
20 | 20 | public static $index=0; |
21 | 21 | |
22 | - public function __construct($identifier,$instance=NULL,$captions=NULL){ |
|
22 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
23 | 23 | $this->widgetIdentifier=$identifier; |
24 | 24 | $this->values=[]; |
25 | 25 | $this->afterCompile=[]; |
26 | - if(isset($instance)) |
|
26 | + if (isset($instance)) |
|
27 | 27 | $this->setInstance($instance); |
28 | 28 | $this->setCaptions($captions); |
29 | 29 | $this->captionCallback=NULL; |
30 | - $this->defaultValueFunction=function($name,$value){return $value;}; |
|
30 | + $this->defaultValueFunction=function($name, $value) {return $value; }; |
|
31 | 31 | } |
32 | 32 | |
33 | - public function moveFieldTo($from,$to){ |
|
34 | - if(JArray::moveElementTo($this->visibleProperties, $from, $to)){ |
|
33 | + public function moveFieldTo($from, $to) { |
|
34 | + if (JArray::moveElementTo($this->visibleProperties, $from, $to)) { |
|
35 | 35 | return JArray::moveElementTo($this->values, $from, $to); |
36 | 36 | } |
37 | 37 | return false; |
38 | 38 | } |
39 | 39 | |
40 | - public function swapFields($index1,$index2){ |
|
41 | - if(JArray::swapElements($this->visibleProperties, $index1, $index2)){ |
|
40 | + public function swapFields($index1, $index2) { |
|
41 | + if (JArray::swapElements($this->visibleProperties, $index1, $index2)) { |
|
42 | 42 | return JArray::swapElements($this->values, $index1, $index2); |
43 | 43 | } |
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | - public function removeField($index){ |
|
48 | - \array_splice($this->visibleProperties,$index,1); |
|
49 | - \array_splice($this->values,$index,1); |
|
50 | - \array_splice($this->captions,$index,1); |
|
47 | + public function removeField($index) { |
|
48 | + \array_splice($this->visibleProperties, $index, 1); |
|
49 | + \array_splice($this->values, $index, 1); |
|
50 | + \array_splice($this->captions, $index, 1); |
|
51 | 51 | return $this; |
52 | 52 | } |
53 | 53 | |
54 | - public function getValues(){ |
|
54 | + public function getValues() { |
|
55 | 55 | $values=[]; |
56 | 56 | $index=0; |
57 | 57 | $count=$this->count(); |
58 | - while($index<$count){ |
|
58 | + while ($index<$count) { |
|
59 | 59 | $values[]=$this->getValue($index++); |
60 | 60 | } |
61 | 61 | return $values; |
62 | 62 | } |
63 | 63 | |
64 | - public function getIdentifier($index=NULL){ |
|
65 | - if(!isset($index)) |
|
64 | + public function getIdentifier($index=NULL) { |
|
65 | + if (!isset($index)) |
|
66 | 66 | $index=self::$index; |
67 | 67 | $value=$index; |
68 | - if(isset($this->values["identifier"])){ |
|
69 | - if(\is_string($this->values["identifier"])) |
|
68 | + if (isset($this->values["identifier"])) { |
|
69 | + if (\is_string($this->values["identifier"])) |
|
70 | 70 | $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
71 | 71 | else |
72 | - $value=$this->values["identifier"]($index,$this->instance); |
|
72 | + $value=$this->values["identifier"]($index, $this->instance); |
|
73 | 73 | } |
74 | 74 | return $value; |
75 | 75 | } |
76 | 76 | |
77 | - public function getValue($index){ |
|
77 | + public function getValue($index) { |
|
78 | 78 | $property=$this->properties[$index]; |
79 | 79 | return $this->_getValue($property, $index); |
80 | 80 | } |
81 | 81 | |
82 | - protected function _beforeAddProperty($index,&$field){ |
|
82 | + protected function _beforeAddProperty($index, &$field) { |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | |
86 | - protected function _getDefaultValue($name,$value,$index){ |
|
86 | + protected function _getDefaultValue($name, $value, $index) { |
|
87 | 87 | $func=$this->defaultValueFunction; |
88 | - return $func($name,$value,$index,$this->instance); |
|
88 | + return $func($name, $value, $index, $this->instance); |
|
89 | 89 | } |
90 | 90 | |
91 | - protected function _getPropertyValue(\ReflectionProperty $property,$index){ |
|
91 | + protected function _getPropertyValue(\ReflectionProperty $property, $index) { |
|
92 | 92 | $property->setAccessible(true); |
93 | 93 | return $property->getValue($this->instance); |
94 | 94 | } |
95 | 95 | |
96 | - protected function _getValue($property,$index){ |
|
96 | + protected function _getValue($property, $index) { |
|
97 | 97 | $value=null; |
98 | 98 | $propertyName=$property; |
99 | - if($property instanceof \ReflectionProperty){ |
|
99 | + if ($property instanceof \ReflectionProperty) { |
|
100 | 100 | $value=$this->_getPropertyValue($property, $index); |
101 | 101 | $propertyName=$property->getName(); |
102 | - }elseif(\is_callable($property)) |
|
102 | + }elseif (\is_callable($property)) |
|
103 | 103 | $value=$property($this->instance); |
104 | - elseif(\is_array($property)){ |
|
105 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
104 | + elseif (\is_array($property)) { |
|
105 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
106 | 106 | $value=\implode("", $values); |
107 | - }elseif(\is_string($property)){ |
|
107 | + }elseif (\is_string($property)) { |
|
108 | 108 | $value=$property; |
109 | - if(isset($this->instance->{$property})){ |
|
109 | + if (isset($this->instance->{$property})) { |
|
110 | 110 | $value=$this->instance->{$property}; |
111 | - }elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
111 | + }elseif (\method_exists($this->instance, $getter=JReflection::getterName($property))) { |
|
112 | 112 | $value=JReflection::callMethod($this->instance, $getter, []); |
113 | 113 | } |
114 | 114 | } |
115 | 115 | return $this->_postGetValue($index, $propertyName, $value); |
116 | 116 | } |
117 | 117 | |
118 | - protected function _postGetValue($index,$propertyName,$value){ |
|
119 | - if(isset($this->values[$index])){ |
|
120 | - $value= $this->values[$index]($value,$this->instance,$index); |
|
121 | - }else{ |
|
122 | - $value=$this->_getDefaultValue($propertyName,$value, $index); |
|
118 | + protected function _postGetValue($index, $propertyName, $value) { |
|
119 | + if (isset($this->values[$index])) { |
|
120 | + $value=$this->values[$index]($value, $this->instance, $index); |
|
121 | + } else { |
|
122 | + $value=$this->_getDefaultValue($propertyName, $value, $index); |
|
123 | 123 | } |
124 | - if(isset($this->afterCompile[$index])){ |
|
125 | - if(\is_callable($this->afterCompile[$index])){ |
|
126 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
124 | + if (isset($this->afterCompile[$index])) { |
|
125 | + if (\is_callable($this->afterCompile[$index])) { |
|
126 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | return $value; |
130 | 130 | } |
131 | 131 | |
132 | - public function insertField($index,$field){ |
|
133 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
132 | + public function insertField($index, $field) { |
|
133 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
134 | 134 | return $this; |
135 | 135 | } |
136 | 136 | |
137 | - public function insertInField($index,$field){ |
|
137 | + public function insertInField($index, $field) { |
|
138 | 138 | $vb=$this->visibleProperties; |
139 | - if(isset($vb[$index])){ |
|
140 | - if(\is_array($vb[$index])){ |
|
139 | + if (isset($vb[$index])) { |
|
140 | + if (\is_array($vb[$index])) { |
|
141 | 141 | $this->visibleProperties[$index][]=$field; |
142 | - }else{ |
|
143 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
142 | + } else { |
|
143 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
144 | 144 | } |
145 | - }else{ |
|
145 | + } else { |
|
146 | 146 | return $this->insertField($index, $field); |
147 | 147 | } |
148 | 148 | return $this; |
149 | 149 | } |
150 | 150 | |
151 | - public function addField($field){ |
|
151 | + public function addField($field) { |
|
152 | 152 | $this->visibleProperties[]=$field; |
153 | 153 | return $this; |
154 | 154 | } |
155 | 155 | |
156 | - public function count(){ |
|
156 | + public function count() { |
|
157 | 157 | return \sizeof($this->properties); |
158 | 158 | } |
159 | 159 | |
160 | - public function visiblePropertiesCount(){ |
|
160 | + public function visiblePropertiesCount() { |
|
161 | 161 | return \sizeof($this->visibleProperties); |
162 | 162 | } |
163 | 163 | |
164 | - public function getProperty($index){ |
|
164 | + public function getProperty($index) { |
|
165 | 165 | return $this->properties[$index]; |
166 | 166 | } |
167 | 167 | |
168 | - public function getFieldName($index){ |
|
168 | + public function getFieldName($index) { |
|
169 | 169 | $property=$this->getProperty($index); |
170 | - if($property instanceof \ReflectionProperty){ |
|
170 | + if ($property instanceof \ReflectionProperty) { |
|
171 | 171 | $result=$property->getName(); |
172 | - }elseif(\is_callable($property)){ |
|
172 | + }elseif (\is_callable($property)) { |
|
173 | 173 | $result=$this->visibleProperties[$index]; |
174 | - }else{ |
|
174 | + } else { |
|
175 | 175 | $result=$property; |
176 | 176 | } |
177 | 177 | return $result; |
178 | 178 | } |
179 | 179 | |
180 | 180 | |
181 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
182 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
181 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
182 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | public function setInstance($instance) { |
186 | - if(\is_string($instance)){ |
|
186 | + if (\is_string($instance)) { |
|
187 | 187 | $instance=new $instance(); |
188 | 188 | } |
189 | 189 | $this->instance=$instance; |
190 | 190 | $this->properties=[]; |
191 | 191 | $this->reflect=new \ReflectionClass($instance); |
192 | - if(\sizeof($this->visibleProperties)===0){ |
|
192 | + if (\sizeof($this->visibleProperties)===0) { |
|
193 | 193 | $this->properties=$this->getDefaultProperties(); |
194 | - }else{ |
|
195 | - foreach ($this->visibleProperties as $property){ |
|
194 | + } else { |
|
195 | + foreach ($this->visibleProperties as $property) { |
|
196 | 196 | $this->setInstanceProperty($property); |
197 | 197 | } |
198 | 198 | } |
199 | 199 | return $this; |
200 | 200 | } |
201 | 201 | |
202 | - private function setInstanceProperty($property){ |
|
203 | - if(\is_callable($property)){ |
|
202 | + private function setInstanceProperty($property) { |
|
203 | + if (\is_callable($property)) { |
|
204 | 204 | $this->properties[]=$property; |
205 | - }elseif(\is_string($property)){ |
|
206 | - try{ |
|
205 | + }elseif (\is_string($property)) { |
|
206 | + try { |
|
207 | 207 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
208 | 208 | $rProperty=$this->reflect->getProperty($property); |
209 | 209 | $this->properties[]=$rProperty; |
210 | - }catch(\Exception $e){ |
|
210 | + }catch (\Exception $e) { |
|
211 | 211 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
212 | 212 | $this->properties[]=$property; |
213 | 213 | } |
214 | - }elseif(\is_int($property)){ |
|
214 | + }elseif (\is_int($property)) { |
|
215 | 215 | $props=$this->getDefaultProperties(); |
216 | - if(isset($props[$property])) |
|
216 | + if (isset($props[$property])) |
|
217 | 217 | $this->properties[]=$props[$property]; |
218 | 218 | else |
219 | 219 | $this->properties[]=$property; |
220 | - }else{ |
|
220 | + } else { |
|
221 | 221 | $this->properties[]=$property; |
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
225 | - protected function getDefaultProperties(){ |
|
225 | + protected function getDefaultProperties() { |
|
226 | 226 | $result=[]; |
227 | 227 | $properties=$this->reflect->getProperties(); |
228 | - foreach ($properties as $property){ |
|
228 | + foreach ($properties as $property) { |
|
229 | 229 | $showable=$this->showableProperty($property); |
230 | - if($showable!==false){ |
|
230 | + if ($showable!==false) { |
|
231 | 231 | $result[]=$property; |
232 | 232 | } |
233 | 233 | } |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | return $this; |
240 | 240 | } |
241 | 241 | |
242 | - public function setValueFunction($index,$callback){ |
|
242 | + public function setValueFunction($index, $callback) { |
|
243 | 243 | $this->values[$index]=$callback; |
244 | 244 | return $this; |
245 | 245 | } |
246 | 246 | |
247 | - public function setIdentifierFunction($callback){ |
|
247 | + public function setIdentifierFunction($callback) { |
|
248 | 248 | $this->values["identifier"]=$callback; |
249 | 249 | return $this; |
250 | 250 | } |
@@ -257,41 +257,41 @@ discard block |
||
257 | 257 | return $this->properties; |
258 | 258 | } |
259 | 259 | |
260 | - public function getCaption($index){ |
|
261 | - if(isset($this->captions[$index])){ |
|
260 | + public function getCaption($index) { |
|
261 | + if (isset($this->captions[$index])) { |
|
262 | 262 | return $this->captions[$index]; |
263 | 263 | } |
264 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
264 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
265 | 265 | return $this->properties[$index]->getName(); |
266 | - elseif(\is_callable($this->properties[$index])) |
|
266 | + elseif (\is_callable($this->properties[$index])) |
|
267 | 267 | return ""; |
268 | 268 | else |
269 | 269 | return $this->properties[$index]; |
270 | 270 | } |
271 | 271 | |
272 | - public function getCaptions(){ |
|
273 | - if(isset($this->captions)){ |
|
274 | - $captions= \array_values($this->captions); |
|
275 | - for($i=\sizeof($captions);$i<$this->count();$i++){ |
|
272 | + public function getCaptions() { |
|
273 | + if (isset($this->captions)) { |
|
274 | + $captions=\array_values($this->captions); |
|
275 | + for ($i=\sizeof($captions); $i<$this->count(); $i++) { |
|
276 | 276 | $captions[]=""; |
277 | 277 | } |
278 | - }else{ |
|
278 | + } else { |
|
279 | 279 | $captions=[]; |
280 | 280 | $index=0; |
281 | 281 | $count=$this->count(); |
282 | - while($index<$count){ |
|
282 | + while ($index<$count) { |
|
283 | 283 | $captions[]=$this->getCaption($index++); |
284 | 284 | } |
285 | 285 | } |
286 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
286 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
287 | 287 | $callback=$this->captionCallback; |
288 | - $callback($captions,$this->instance); |
|
288 | + $callback($captions, $this->instance); |
|
289 | 289 | } |
290 | 290 | return $captions; |
291 | 291 | } |
292 | 292 | |
293 | - public function setCaption($index,$caption){ |
|
294 | - if(isset($this->captions)===false) |
|
293 | + public function setCaption($index, $caption) { |
|
294 | + if (isset($this->captions)===false) |
|
295 | 295 | $this->captions=[]; |
296 | 296 | $this->captions[$index]=$caption; |
297 | 297 | return $this; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @param callable $callback function called after the field compilation |
310 | 310 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
311 | 311 | */ |
312 | - public function afterCompile($index,$callback){ |
|
312 | + public function afterCompile($index, $callback) { |
|
313 | 313 | $this->afterCompile[$index]=$callback; |
314 | 314 | return $this; |
315 | 315 | } |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | $this->widgetIdentifier=$identifier; |
24 | 24 | $this->values=[]; |
25 | 25 | $this->afterCompile=[]; |
26 | - if(isset($instance)) |
|
27 | - $this->setInstance($instance); |
|
26 | + if(isset($instance)) { |
|
27 | + $this->setInstance($instance); |
|
28 | + } |
|
28 | 29 | $this->setCaptions($captions); |
29 | 30 | $this->captionCallback=NULL; |
30 | 31 | $this->defaultValueFunction=function($name,$value){return $value;}; |
@@ -62,14 +63,16 @@ discard block |
||
62 | 63 | } |
63 | 64 | |
64 | 65 | public function getIdentifier($index=NULL){ |
65 | - if(!isset($index)) |
|
66 | - $index=self::$index; |
|
66 | + if(!isset($index)) { |
|
67 | + $index=self::$index; |
|
68 | + } |
|
67 | 69 | $value=$index; |
68 | 70 | if(isset($this->values["identifier"])){ |
69 | - if(\is_string($this->values["identifier"])) |
|
70 | - $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
71 | - else |
|
72 | - $value=$this->values["identifier"]($index,$this->instance); |
|
71 | + if(\is_string($this->values["identifier"])) { |
|
72 | + $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
73 | + } else { |
|
74 | + $value=$this->values["identifier"]($index,$this->instance); |
|
75 | + } |
|
73 | 76 | } |
74 | 77 | return $value; |
75 | 78 | } |
@@ -99,16 +102,16 @@ discard block |
||
99 | 102 | if($property instanceof \ReflectionProperty){ |
100 | 103 | $value=$this->_getPropertyValue($property, $index); |
101 | 104 | $propertyName=$property->getName(); |
102 | - }elseif(\is_callable($property)) |
|
103 | - $value=$property($this->instance); |
|
104 | - elseif(\is_array($property)){ |
|
105 | + } elseif(\is_callable($property)) { |
|
106 | + $value=$property($this->instance); |
|
107 | + } elseif(\is_array($property)){ |
|
105 | 108 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
106 | 109 | $value=\implode("", $values); |
107 | - }elseif(\is_string($property)){ |
|
110 | + } elseif(\is_string($property)){ |
|
108 | 111 | $value=$property; |
109 | 112 | if(isset($this->instance->{$property})){ |
110 | 113 | $value=$this->instance->{$property}; |
111 | - }elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
114 | + } elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
112 | 115 | $value=JReflection::callMethod($this->instance, $getter, []); |
113 | 116 | } |
114 | 117 | } |
@@ -118,7 +121,7 @@ discard block |
||
118 | 121 | protected function _postGetValue($index,$propertyName,$value){ |
119 | 122 | if(isset($this->values[$index])){ |
120 | 123 | $value= $this->values[$index]($value,$this->instance,$index); |
121 | - }else{ |
|
124 | + } else{ |
|
122 | 125 | $value=$this->_getDefaultValue($propertyName,$value, $index); |
123 | 126 | } |
124 | 127 | if(isset($this->afterCompile[$index])){ |
@@ -139,10 +142,10 @@ discard block |
||
139 | 142 | if(isset($vb[$index])){ |
140 | 143 | if(\is_array($vb[$index])){ |
141 | 144 | $this->visibleProperties[$index][]=$field; |
142 | - }else{ |
|
145 | + } else{ |
|
143 | 146 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
144 | 147 | } |
145 | - }else{ |
|
148 | + } else{ |
|
146 | 149 | return $this->insertField($index, $field); |
147 | 150 | } |
148 | 151 | return $this; |
@@ -169,9 +172,9 @@ discard block |
||
169 | 172 | $property=$this->getProperty($index); |
170 | 173 | if($property instanceof \ReflectionProperty){ |
171 | 174 | $result=$property->getName(); |
172 | - }elseif(\is_callable($property)){ |
|
175 | + } elseif(\is_callable($property)){ |
|
173 | 176 | $result=$this->visibleProperties[$index]; |
174 | - }else{ |
|
177 | + } else{ |
|
175 | 178 | $result=$property; |
176 | 179 | } |
177 | 180 | return $result; |
@@ -191,7 +194,7 @@ discard block |
||
191 | 194 | $this->reflect=new \ReflectionClass($instance); |
192 | 195 | if(\sizeof($this->visibleProperties)===0){ |
193 | 196 | $this->properties=$this->getDefaultProperties(); |
194 | - }else{ |
|
197 | + } else{ |
|
195 | 198 | foreach ($this->visibleProperties as $property){ |
196 | 199 | $this->setInstanceProperty($property); |
197 | 200 | } |
@@ -202,22 +205,23 @@ discard block |
||
202 | 205 | private function setInstanceProperty($property){ |
203 | 206 | if(\is_callable($property)){ |
204 | 207 | $this->properties[]=$property; |
205 | - }elseif(\is_string($property)){ |
|
208 | + } elseif(\is_string($property)){ |
|
206 | 209 | try{ |
207 | 210 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
208 | 211 | $rProperty=$this->reflect->getProperty($property); |
209 | 212 | $this->properties[]=$rProperty; |
210 | - }catch(\Exception $e){ |
|
213 | + } catch(\Exception $e){ |
|
211 | 214 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
212 | 215 | $this->properties[]=$property; |
213 | 216 | } |
214 | - }elseif(\is_int($property)){ |
|
217 | + } elseif(\is_int($property)){ |
|
215 | 218 | $props=$this->getDefaultProperties(); |
216 | - if(isset($props[$property])) |
|
217 | - $this->properties[]=$props[$property]; |
|
218 | - else |
|
219 | - $this->properties[]=$property; |
|
220 | - }else{ |
|
219 | + if(isset($props[$property])) { |
|
220 | + $this->properties[]=$props[$property]; |
|
221 | + } else { |
|
222 | + $this->properties[]=$property; |
|
223 | + } |
|
224 | + } else{ |
|
221 | 225 | $this->properties[]=$property; |
222 | 226 | } |
223 | 227 | } |
@@ -261,12 +265,13 @@ discard block |
||
261 | 265 | if(isset($this->captions[$index])){ |
262 | 266 | return $this->captions[$index]; |
263 | 267 | } |
264 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
265 | - return $this->properties[$index]->getName(); |
|
266 | - elseif(\is_callable($this->properties[$index])) |
|
267 | - return ""; |
|
268 | - else |
|
269 | - return $this->properties[$index]; |
|
268 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
269 | + return $this->properties[$index]->getName(); |
|
270 | + } elseif(\is_callable($this->properties[$index])) { |
|
271 | + return ""; |
|
272 | + } else { |
|
273 | + return $this->properties[$index]; |
|
274 | + } |
|
270 | 275 | } |
271 | 276 | |
272 | 277 | public function getCaptions(){ |
@@ -275,7 +280,7 @@ discard block |
||
275 | 280 | for($i=\sizeof($captions);$i<$this->count();$i++){ |
276 | 281 | $captions[]=""; |
277 | 282 | } |
278 | - }else{ |
|
283 | + } else{ |
|
279 | 284 | $captions=[]; |
280 | 285 | $index=0; |
281 | 286 | $count=$this->count(); |
@@ -291,8 +296,9 @@ discard block |
||
291 | 296 | } |
292 | 297 | |
293 | 298 | public function setCaption($index,$caption){ |
294 | - if(isset($this->captions)===false) |
|
295 | - $this->captions=[]; |
|
299 | + if(isset($this->captions)===false) { |
|
300 | + $this->captions=[]; |
|
301 | + } |
|
296 | 302 | $this->captions[$index]=$caption; |
297 | 303 | return $this; |
298 | 304 | } |
@@ -3,25 +3,25 @@ discard block |
||
3 | 3 | namespace Ajax\service; |
4 | 4 | |
5 | 5 | class JReflection { |
6 | - public static function shortClassName($object){ |
|
7 | - $classNameWithNamespace = get_class($object); |
|
6 | + public static function shortClassName($object) { |
|
7 | + $classNameWithNamespace=get_class($object); |
|
8 | 8 | return substr($classNameWithNamespace, strrpos($classNameWithNamespace, '\\')+1); |
9 | 9 | } |
10 | 10 | |
11 | - public static function jsonObject($classname){ |
|
11 | + public static function jsonObject($classname) { |
|
12 | 12 | $object=new $classname(); |
13 | - $class = new \ReflectionClass($classname); |
|
13 | + $class=new \ReflectionClass($classname); |
|
14 | 14 | $methods=$class->getMethods(\ReflectionMethod::IS_PUBLIC); |
15 | - foreach ($methods as $method){ |
|
15 | + foreach ($methods as $method) { |
|
16 | 16 | $name=$method->getName(); |
17 | - if(JString::startswith($name, "set")){ |
|
17 | + if (JString::startswith($name, "set")) { |
|
18 | 18 | $property=\lcfirst(JString::replaceAtFirst($name, "set", "")); |
19 | 19 | $value="__".$property."__"; |
20 | - try{ |
|
21 | - if($class->getProperty($property)!==null){ |
|
22 | - \call_user_func_array([$object,$name],[$value]); |
|
20 | + try { |
|
21 | + if ($class->getProperty($property)!==null) { |
|
22 | + \call_user_func_array([$object, $name], [$value]); |
|
23 | 23 | } |
24 | - }catch(\Exception $e){ |
|
24 | + }catch (\Exception $e) { |
|
25 | 25 | //Nothing to do |
26 | 26 | } |
27 | 27 | } |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | return $object; |
30 | 30 | } |
31 | 31 | |
32 | - public static function callMethod($object,$callback,array $values){ |
|
33 | - return \call_user_func_array([$object,$callback],$values); |
|
32 | + public static function callMethod($object, $callback, array $values) { |
|
33 | + return \call_user_func_array([$object, $callback], $values); |
|
34 | 34 | } |
35 | 35 | |
36 | - public static function getterName($propertyName,$prefix="get"){ |
|
36 | + public static function getterName($propertyName, $prefix="get") { |
|
37 | 37 | return $prefix.\ucfirst($propertyName); |
38 | 38 | } |
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | */ |
25 | 25 | class DataTable extends Widget { |
26 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
26 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
27 | 27 | protected $_searchField; |
28 | 28 | protected $_urls; |
29 | 29 | protected $_pagination; |
@@ -40,35 +40,35 @@ discard block |
||
40 | 40 | protected $_hiddenColumns; |
41 | 41 | |
42 | 42 | |
43 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
44 | - parent::__construct($identifier, $model,$modelInstance); |
|
45 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
43 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
44 | + parent::__construct($identifier, $model, $modelInstance); |
|
45 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
46 | 46 | $this->_urls=[]; |
47 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
47 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
48 | 48 | $this->_emptyMessage->setIcon("info circle"); |
49 | 49 | } |
50 | 50 | |
51 | - public function run(JsUtils $js){ |
|
52 | - if($this->_hasCheckboxes && isset($js)){ |
|
51 | + public function run(JsUtils $js) { |
|
52 | + if ($this->_hasCheckboxes && isset($js)) { |
|
53 | 53 | $this->_runCheckboxes($js); |
54 | 54 | } |
55 | - if($this->_visibleHover){ |
|
56 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
57 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
55 | + if ($this->_visibleHover) { |
|
56 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
57 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
58 | 58 | } |
59 | - if(\is_array($this->_deleteBehavior)) |
|
60 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
61 | - if(\is_array($this->_editBehavior)) |
|
62 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
59 | + if (\is_array($this->_deleteBehavior)) |
|
60 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
61 | + if (\is_array($this->_editBehavior)) |
|
62 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
63 | 63 | return parent::run($js); |
64 | 64 | } |
65 | 65 | |
66 | 66 | |
67 | 67 | |
68 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
69 | - if(isset($this->_urls[$op])){ |
|
70 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
71 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
68 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
69 | + if (isset($this->_urls[$op])) { |
|
70 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
71 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -81,146 +81,146 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | |
84 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
85 | - if(!$this->_generated){ |
|
84 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
85 | + if (!$this->_generated) { |
|
86 | 86 | $this->_instanceViewer->setInstance($this->_model); |
87 | 87 | $captions=$this->_instanceViewer->getCaptions(); |
88 | 88 | |
89 | 89 | $table=$this->content["table"]; |
90 | 90 | |
91 | - if($this->_hasCheckboxes){ |
|
91 | + if ($this->_hasCheckboxes) { |
|
92 | 92 | $this->_generateMainCheckbox($captions); |
93 | 93 | } |
94 | 94 | |
95 | 95 | $table->setRowCount(0, \sizeof($captions)); |
96 | - $this->_generateHeader($table,$captions); |
|
96 | + $this->_generateHeader($table, $captions); |
|
97 | 97 | |
98 | - if(isset($this->_compileParts)) |
|
98 | + if (isset($this->_compileParts)) |
|
99 | 99 | $table->setCompileParts($this->_compileParts); |
100 | 100 | |
101 | - if(isset($this->_searchField) && isset($js)){ |
|
102 | - if(isset($this->_urls["refresh"])) |
|
103 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
101 | + if (isset($this->_searchField) && isset($js)) { |
|
102 | + if (isset($this->_urls["refresh"])) |
|
103 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $this->_generateContent($table); |
107 | 107 | |
108 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
108 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
109 | 109 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
110 | 110 | } |
111 | 111 | |
112 | - if(isset($this->_toolbar)){ |
|
112 | + if (isset($this->_toolbar)) { |
|
113 | 113 | $this->_setToolbarPosition($table, $captions); |
114 | 114 | } |
115 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
116 | - $this->_generatePagination($table,$js); |
|
115 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
116 | + $this->_generatePagination($table, $js); |
|
117 | 117 | } |
118 | 118 | |
119 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
119 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
120 | 120 | $this->_compileForm(); |
121 | - if(isset($this->_hiddenColumns)) |
|
121 | + if (isset($this->_hiddenColumns)) |
|
122 | 122 | $this->_hideColumns(); |
123 | 123 | $this->_generated=true; |
124 | 124 | } |
125 | - return parent::compile($js,$view); |
|
125 | + return parent::compile($js, $view); |
|
126 | 126 | } |
127 | 127 | |
128 | - protected function _hideColumns(){ |
|
128 | + protected function _hideColumns() { |
|
129 | 129 | $table=$this->getTable(); |
130 | - foreach ($this->_hiddenColumns as $colIndex){ |
|
130 | + foreach ($this->_hiddenColumns as $colIndex) { |
|
131 | 131 | $table->hideColumn($colIndex); |
132 | 132 | } |
133 | 133 | return $this; |
134 | 134 | } |
135 | 135 | |
136 | - protected function _generateHeader(HtmlTable $table,$captions){ |
|
136 | + protected function _generateHeader(HtmlTable $table, $captions) { |
|
137 | 137 | $table->setHeaderValues($captions); |
138 | - if(isset($this->_sortable)){ |
|
138 | + if (isset($this->_sortable)) { |
|
139 | 139 | $table->setSortable($this->_sortable); |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | 143 | |
144 | 144 | |
145 | - protected function _generateContent($table){ |
|
145 | + protected function _generateContent($table) { |
|
146 | 146 | $objects=$this->_modelInstance; |
147 | - if(isset($this->_pagination)){ |
|
147 | + if (isset($this->_pagination)) { |
|
148 | 148 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
149 | 149 | } |
150 | 150 | InstanceViewer::setIndex(0); |
151 | 151 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
152 | 152 | return $this->_generateRow($instance, $table); |
153 | 153 | }); |
154 | - if($table->getRowCount()==0){ |
|
154 | + if ($table->getRowCount()==0) { |
|
155 | 155 | $result=$table->addRow(); |
156 | 156 | $result->mergeRow(); |
157 | 157 | $result->setValues([$this->_emptyMessage]); |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - protected function _generateRow($instance,&$table,$checkedClass=null){ |
|
161 | + protected function _generateRow($instance, &$table, $checkedClass=null) { |
|
162 | 162 | $this->_instanceViewer->setInstance($instance); |
163 | 163 | InstanceViewer::$index++; |
164 | - $values= $this->_instanceViewer->getValues(); |
|
164 | + $values=$this->_instanceViewer->getValues(); |
|
165 | 165 | $id=$this->_instanceViewer->getIdentifier(); |
166 | - if($this->_hasCheckboxes){ |
|
167 | - $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,""); |
|
166 | + if ($this->_hasCheckboxes) { |
|
167 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
168 | 168 | $ck->setOnChange("event.stopPropagation();"); |
169 | 169 | $field=$ck->getField(); |
170 | - $field->setProperty("value",$id); |
|
170 | + $field->setProperty("value", $id); |
|
171 | 171 | $field->setProperty("name", "selection[]"); |
172 | - if(isset($checkedClass)) |
|
172 | + if (isset($checkedClass)) |
|
173 | 173 | $field->setClass($checkedClass); |
174 | 174 | \array_unshift($values, $ck); |
175 | 175 | } |
176 | 176 | $result=$table->newRow(); |
177 | 177 | $result->setIdentifier($this->identifier."-tr-".$id); |
178 | - $result->setProperty("data-ajax",$id); |
|
178 | + $result->setProperty("data-ajax", $id); |
|
179 | 179 | $result->setValues($values); |
180 | - $result->addToProperty("class",$this->_rowClass); |
|
180 | + $result->addToProperty("class", $this->_rowClass); |
|
181 | 181 | return $result; |
182 | 182 | } |
183 | 183 | |
184 | - protected function _generatePagination($table,$js=NULL){ |
|
185 | - if(isset($this->_toolbar)){ |
|
186 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
184 | + protected function _generatePagination($table, $js=NULL) { |
|
185 | + if (isset($this->_toolbar)) { |
|
186 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
187 | 187 | $this->_toolbar->setFloated("left"); |
188 | 188 | } |
189 | 189 | $footer=$table->getFooter(); |
190 | 190 | $footer->mergeCol(); |
191 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
191 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
192 | 192 | $menu->floatRight(); |
193 | 193 | $menu->setActiveItem($this->_pagination->getPage()-1); |
194 | 194 | $footer->addValues($menu); |
195 | - $this->_associatePaginationBehavior($menu,$js); |
|
195 | + $this->_associatePaginationBehavior($menu, $js); |
|
196 | 196 | } |
197 | 197 | |
198 | - protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){ |
|
199 | - if(isset($this->_urls["refresh"])){ |
|
200 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
198 | + protected function _associatePaginationBehavior(HtmlMenu $menu, JsUtils $js=NULL) { |
|
199 | + if (isset($this->_urls["refresh"])) { |
|
200 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - protected function _getFieldName($index){ |
|
204 | + protected function _getFieldName($index) { |
|
205 | 205 | return parent::_getFieldName($index)."[]"; |
206 | 206 | } |
207 | 207 | |
208 | - protected function _getFieldCaption($index){ |
|
208 | + protected function _getFieldCaption($index) { |
|
209 | 209 | return null; |
210 | 210 | } |
211 | 211 | |
212 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
213 | - switch ($this->_toolbarPosition){ |
|
212 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
213 | + switch ($this->_toolbarPosition) { |
|
214 | 214 | case PositionInTable::BEFORETABLE: |
215 | 215 | case PositionInTable::AFTERTABLE: |
216 | - if(isset($this->_compileParts)===false){ |
|
216 | + if (isset($this->_compileParts)===false) { |
|
217 | 217 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
218 | 218 | } |
219 | 219 | break; |
220 | 220 | case PositionInTable::HEADER: |
221 | 221 | case PositionInTable::FOOTER: |
222 | 222 | case PositionInTable::BODY: |
223 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
223 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
224 | 224 | break; |
225 | 225 | } |
226 | 226 | } |
@@ -232,23 +232,23 @@ discard block |
||
232 | 232 | * @param callable $callback function called after the field compilation |
233 | 233 | * @return DataTable |
234 | 234 | */ |
235 | - public function afterCompile($index,$callback){ |
|
236 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
235 | + public function afterCompile($index, $callback) { |
|
236 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
237 | 237 | return $this; |
238 | 238 | } |
239 | 239 | |
240 | - private function addToolbarRow($part,$table,$captions){ |
|
240 | + private function addToolbarRow($part, $table, $captions) { |
|
241 | 241 | $hasPart=$table->hasPart($part); |
242 | - if($hasPart){ |
|
242 | + if ($hasPart) { |
|
243 | 243 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
244 | - }else{ |
|
244 | + } else { |
|
245 | 245 | $row=$table->getPart($part)->getRow(0); |
246 | 246 | } |
247 | 247 | $row->mergeCol(); |
248 | 248 | $row->setValues([$this->_toolbar]); |
249 | 249 | } |
250 | 250 | |
251 | - public function getHtmlComponent(){ |
|
251 | + public function getHtmlComponent() { |
|
252 | 252 | return $this->content["table"]; |
253 | 253 | } |
254 | 254 | |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | * @return DataTable |
263 | 263 | */ |
264 | 264 | public function setUrls($urls) { |
265 | - if(\is_array($urls)){ |
|
266 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
267 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
268 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
269 | - }else{ |
|
270 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
265 | + if (\is_array($urls)) { |
|
266 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
267 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
268 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
269 | + } else { |
|
270 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
271 | 271 | } |
272 | 272 | return $this; |
273 | 273 | } |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * @param number $pages_visibles The number of visible pages in the Pagination component |
281 | 281 | * @return DataTable |
282 | 282 | */ |
283 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
284 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
283 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
284 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
285 | 285 | return $this; |
286 | 286 | } |
287 | 287 | |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param number $pages_visibles The number of visible pages in the Pagination component |
293 | 293 | * @return DataTable |
294 | 294 | */ |
295 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
296 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
295 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
296 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
297 | 297 | return $this; |
298 | 298 | } |
299 | 299 | |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | * @param array $compileParts |
304 | 304 | * @return DataTable |
305 | 305 | */ |
306 | - public function refresh($compileParts=["tbody"]){ |
|
306 | + public function refresh($compileParts=["tbody"]) { |
|
307 | 307 | $this->_compileParts=$compileParts; |
308 | 308 | return $this; |
309 | 309 | } |
310 | 310 | |
311 | 311 | |
312 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
312 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
313 | 313 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
314 | 314 | } |
315 | 315 | |
316 | - public function getSearchField(){ |
|
317 | - if(isset($this->_searchField)===false){ |
|
318 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
319 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
316 | + public function getSearchField() { |
|
317 | + if (isset($this->_searchField)===false) { |
|
318 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
319 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
320 | 320 | } |
321 | 321 | return $this->_searchField; |
322 | 322 | } |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | return $this; |
333 | 333 | } |
334 | 334 | |
335 | - public function asForm(){ |
|
335 | + public function asForm() { |
|
336 | 336 | return $this->getForm(); |
337 | 337 | } |
338 | 338 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | |
341 | 341 | protected function getTargetSelector() { |
342 | 342 | $result=$this->_targetSelector; |
343 | - if(!isset($result)) |
|
343 | + if (!isset($result)) |
|
344 | 344 | $result="#".$this->identifier; |
345 | 345 | return $result; |
346 | 346 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | } |
357 | 357 | |
358 | 358 | public function getRefreshSelector() { |
359 | - if(isset($this->_refreshSelector)) |
|
359 | + if (isset($this->_refreshSelector)) |
|
360 | 360 | return $this->_refreshSelector; |
361 | 361 | return "#".$this->identifier." tbody"; |
362 | 362 | } |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | * {@inheritDoc} |
375 | 375 | * @see \Ajax\common\Widget::show() |
376 | 376 | */ |
377 | - public function show($modelInstance){ |
|
378 | - if(\is_array($modelInstance)){ |
|
379 | - if(\is_array(array_values($modelInstance)[0])) |
|
377 | + public function show($modelInstance) { |
|
378 | + if (\is_array($modelInstance)) { |
|
379 | + if (\is_array(array_values($modelInstance)[0])) |
|
380 | 380 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
381 | 381 | } |
382 | 382 | $this->_modelInstance=$modelInstance; |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | return $this; |
412 | 412 | } |
413 | 413 | |
414 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
415 | - $this->getTable()->setActiveRowSelector($class,$event,$multiple); |
|
414 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
415 | + $this->getTable()->setActiveRowSelector($class, $event, $multiple); |
|
416 | 416 | return $this; |
417 | 417 | } |
418 | 418 | |
419 | - public function hideColumn($colIndex){ |
|
420 | - if(!\is_array($this->_hiddenColumns)) |
|
419 | + public function hideColumn($colIndex) { |
|
420 | + if (!\is_array($this->_hiddenColumns)) |
|
421 | 421 | $this->_hiddenColumns=[]; |
422 | 422 | $this->_hiddenColumns[]=$colIndex; |
423 | 423 | return $this; |
@@ -56,10 +56,12 @@ discard block |
||
56 | 56 | $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
57 | 57 | $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
58 | 58 | } |
59 | - if(\is_array($this->_deleteBehavior)) |
|
60 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
61 | - if(\is_array($this->_editBehavior)) |
|
62 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
59 | + if(\is_array($this->_deleteBehavior)) { |
|
60 | + $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
61 | + } |
|
62 | + if(\is_array($this->_editBehavior)) { |
|
63 | + $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
64 | + } |
|
63 | 65 | return parent::run($js); |
64 | 66 | } |
65 | 67 | |
@@ -95,12 +97,14 @@ discard block |
||
95 | 97 | $table->setRowCount(0, \sizeof($captions)); |
96 | 98 | $this->_generateHeader($table,$captions); |
97 | 99 | |
98 | - if(isset($this->_compileParts)) |
|
99 | - $table->setCompileParts($this->_compileParts); |
|
100 | + if(isset($this->_compileParts)) { |
|
101 | + $table->setCompileParts($this->_compileParts); |
|
102 | + } |
|
100 | 103 | |
101 | 104 | if(isset($this->_searchField) && isset($js)){ |
102 | - if(isset($this->_urls["refresh"])) |
|
103 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
105 | + if(isset($this->_urls["refresh"])) { |
|
106 | + $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
107 | + } |
|
104 | 108 | } |
105 | 109 | |
106 | 110 | $this->_generateContent($table); |
@@ -118,8 +122,9 @@ discard block |
||
118 | 122 | |
119 | 123 | $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
120 | 124 | $this->_compileForm(); |
121 | - if(isset($this->_hiddenColumns)) |
|
122 | - $this->_hideColumns(); |
|
125 | + if(isset($this->_hiddenColumns)) { |
|
126 | + $this->_hideColumns(); |
|
127 | + } |
|
123 | 128 | $this->_generated=true; |
124 | 129 | } |
125 | 130 | return parent::compile($js,$view); |
@@ -169,8 +174,9 @@ discard block |
||
169 | 174 | $field=$ck->getField(); |
170 | 175 | $field->setProperty("value",$id); |
171 | 176 | $field->setProperty("name", "selection[]"); |
172 | - if(isset($checkedClass)) |
|
173 | - $field->setClass($checkedClass); |
|
177 | + if(isset($checkedClass)) { |
|
178 | + $field->setClass($checkedClass); |
|
179 | + } |
|
174 | 180 | \array_unshift($values, $ck); |
175 | 181 | } |
176 | 182 | $result=$table->newRow(); |
@@ -183,8 +189,9 @@ discard block |
||
183 | 189 | |
184 | 190 | protected function _generatePagination($table,$js=NULL){ |
185 | 191 | if(isset($this->_toolbar)){ |
186 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
187 | - $this->_toolbar->setFloated("left"); |
|
192 | + if($this->_toolbarPosition==PositionInTable::FOOTER) { |
|
193 | + $this->_toolbar->setFloated("left"); |
|
194 | + } |
|
188 | 195 | } |
189 | 196 | $footer=$table->getFooter(); |
190 | 197 | $footer->mergeCol(); |
@@ -241,7 +248,7 @@ discard block |
||
241 | 248 | $hasPart=$table->hasPart($part); |
242 | 249 | if($hasPart){ |
243 | 250 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
244 | - }else{ |
|
251 | + } else{ |
|
245 | 252 | $row=$table->getPart($part)->getRow(0); |
246 | 253 | } |
247 | 254 | $row->mergeCol(); |
@@ -266,7 +273,7 @@ discard block |
||
266 | 273 | $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
267 | 274 | $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
268 | 275 | $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
269 | - }else{ |
|
276 | + } else{ |
|
270 | 277 | $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
271 | 278 | } |
272 | 279 | return $this; |
@@ -340,8 +347,9 @@ discard block |
||
340 | 347 | |
341 | 348 | protected function getTargetSelector() { |
342 | 349 | $result=$this->_targetSelector; |
343 | - if(!isset($result)) |
|
344 | - $result="#".$this->identifier; |
|
350 | + if(!isset($result)) { |
|
351 | + $result="#".$this->identifier; |
|
352 | + } |
|
345 | 353 | return $result; |
346 | 354 | } |
347 | 355 | |
@@ -356,8 +364,9 @@ discard block |
||
356 | 364 | } |
357 | 365 | |
358 | 366 | public function getRefreshSelector() { |
359 | - if(isset($this->_refreshSelector)) |
|
360 | - return $this->_refreshSelector; |
|
367 | + if(isset($this->_refreshSelector)) { |
|
368 | + return $this->_refreshSelector; |
|
369 | + } |
|
361 | 370 | return "#".$this->identifier." tbody"; |
362 | 371 | } |
363 | 372 | |
@@ -376,8 +385,9 @@ discard block |
||
376 | 385 | */ |
377 | 386 | public function show($modelInstance){ |
378 | 387 | if(\is_array($modelInstance)){ |
379 | - if(\is_array(array_values($modelInstance)[0])) |
|
380 | - $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
388 | + if(\is_array(array_values($modelInstance)[0])) { |
|
389 | + $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
390 | + } |
|
381 | 391 | } |
382 | 392 | $this->_modelInstance=$modelInstance; |
383 | 393 | } |
@@ -417,8 +427,9 @@ discard block |
||
417 | 427 | } |
418 | 428 | |
419 | 429 | public function hideColumn($colIndex){ |
420 | - if(!\is_array($this->_hiddenColumns)) |
|
421 | - $this->_hiddenColumns=[]; |
|
430 | + if(!\is_array($this->_hiddenColumns)) { |
|
431 | + $this->_hiddenColumns=[]; |
|
432 | + } |
|
422 | 433 | $this->_hiddenColumns[]=$colIndex; |
423 | 434 | return $this; |
424 | 435 | } |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | * @property boolean $_edition |
28 | 28 | * @property mixed _modelInstance |
29 | 29 | */ |
30 | -trait FieldAsTrait{ |
|
30 | +trait FieldAsTrait { |
|
31 | 31 | |
32 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
33 | - abstract public function setValueFunction($index,$callback); |
|
32 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
33 | + abstract public function setValueFunction($index, $callback); |
|
34 | 34 | abstract protected function _getFieldName($index); |
35 | 35 | abstract protected function _getFieldCaption($index); |
36 | - abstract protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
36 | + abstract protected function _buttonAsSubmit(BaseHtml&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param HtmlFormField $element |
40 | 40 | * @param array $attributes |
41 | 41 | */ |
42 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
43 | - if(isset($attributes["jsCallback"])){ |
|
42 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
43 | + if (isset($attributes["jsCallback"])) { |
|
44 | 44 | $callback=$attributes["jsCallback"]; |
45 | - if(\is_callable($callback)){ |
|
46 | - $callback($element,$this->_modelInstance,$index); |
|
45 | + if (\is_callable($callback)) { |
|
46 | + $callback($element, $this->_modelInstance, $index); |
|
47 | 47 | unset($attributes["jsCallback"]); |
48 | 48 | } |
49 | 49 | } |
@@ -53,43 +53,43 @@ discard block |
||
53 | 53 | $element->fromArray($attributes); |
54 | 54 | } |
55 | 55 | |
56 | - private function _getLabelField($caption,$icon=NULL){ |
|
57 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
56 | + private function _getLabelField($caption, $icon=NULL) { |
|
57 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
58 | 58 | return $label; |
59 | 59 | } |
60 | 60 | |
61 | 61 | |
62 | - protected function _addRules($element,&$attributes){ |
|
63 | - if(isset($attributes["rules"])){ |
|
62 | + protected function _addRules($element, &$attributes) { |
|
63 | + if (isset($attributes["rules"])) { |
|
64 | 64 | $rules=$attributes["rules"]; |
65 | - if(\is_array($rules)){ |
|
65 | + if (\is_array($rules)) { |
|
66 | 66 | $element->addRules($rules); |
67 | 67 | } |
68 | - else{ |
|
68 | + else { |
|
69 | 69 | $element->addRule($rules); |
70 | 70 | } |
71 | 71 | unset($attributes["rules"]); |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - protected function _prepareFormFields(&$field,$name,&$attributes){ |
|
75 | + protected function _prepareFormFields(&$field, $name, &$attributes) { |
|
76 | 76 | $field->setName($name); |
77 | 77 | $this->_addRules($field, $attributes); |
78 | 78 | return $field; |
79 | 79 | } |
80 | 80 | |
81 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
82 | - $this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){ |
|
81 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
82 | + $this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){ |
|
83 | 83 | $caption=$this->_getFieldCaption($index); |
84 | 84 | $name=$this->_getFieldName($index); |
85 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
86 | - if(isset($attributes["name"])){ |
|
85 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
86 | + if (isset($attributes["name"])) { |
|
87 | 87 | $name=$attributes["name"]; |
88 | 88 | unset($attributes["name"]); |
89 | 89 | } |
90 | - $element=$elementCallback($id,$name,$value,$caption); |
|
91 | - if(\is_array($attributes)){ |
|
92 | - $this->_applyAttributes($element, $attributes,$index); |
|
90 | + $element=$elementCallback($id, $name, $value, $caption); |
|
91 | + if (\is_array($attributes)) { |
|
92 | + $this->_applyAttributes($element, $attributes, $index); |
|
93 | 93 | } |
94 | 94 | $element->setDisabled(!$this->_edition); |
95 | 95 | return $element; |
@@ -98,176 +98,176 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | |
101 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
102 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
103 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
101 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
102 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
103 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
104 | 104 | return $pb; |
105 | 105 | }); |
106 | 106 | return $this; |
107 | 107 | } |
108 | 108 | |
109 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
110 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
111 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
109 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
110 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
111 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
112 | 112 | return $rating; |
113 | 113 | }); |
114 | 114 | return $this; |
115 | 115 | } |
116 | 116 | |
117 | - public function fieldAsLabel($index,$icon=NULL,$attributes=NULL){ |
|
118 | - return $this->_fieldAs(function($id,$name,$value) use($icon){ |
|
119 | - $lbl=new HtmlLabel($id,$value); |
|
120 | - if(isset($icon)) |
|
117 | + public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) { |
|
118 | + return $this->_fieldAs(function($id, $name, $value) use($icon){ |
|
119 | + $lbl=new HtmlLabel($id, $value); |
|
120 | + if (isset($icon)) |
|
121 | 121 | $lbl->addIcon($icon); |
122 | 122 | return $lbl; |
123 | - }, $index,$attributes,"label"); |
|
123 | + }, $index, $attributes, "label"); |
|
124 | 124 | } |
125 | 125 | |
126 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
127 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
128 | - $header=new HtmlHeader($id,$niveau,$value); |
|
129 | - if(isset($icon)) |
|
126 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
127 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
128 | + $header=new HtmlHeader($id, $niveau, $value); |
|
129 | + if (isset($icon)) |
|
130 | 130 | $header->asIcon($icon, $value); |
131 | 131 | return $header; |
132 | - }, $index,$attributes,"header"); |
|
132 | + }, $index, $attributes, "header"); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
136 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
137 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
138 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
136 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
137 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
138 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
139 | 139 | return $image; |
140 | 140 | }); |
141 | 141 | return $this; |
142 | 142 | } |
143 | 143 | |
144 | - public function fieldAsFlag($index){ |
|
145 | - $this->setValueFunction($index,function($flag){ |
|
146 | - $flag=new HtmlFlag($this->_getFieldIdentifier("flag"),$flag); |
|
144 | + public function fieldAsFlag($index) { |
|
145 | + $this->setValueFunction($index, function($flag) { |
|
146 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
147 | 147 | return $flag; |
148 | 148 | }); |
149 | 149 | return $this; |
150 | 150 | } |
151 | 151 | |
152 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
153 | - return $this->_fieldAs(function($id,$name,$value){ |
|
154 | - $img=new HtmlImage($id,$value); |
|
152 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
153 | + return $this->_fieldAs(function($id, $name, $value) { |
|
154 | + $img=new HtmlImage($id, $value); |
|
155 | 155 | $img->asAvatar(); |
156 | 156 | return $img; |
157 | - }, $index,$attributes,"avatar"); |
|
157 | + }, $index, $attributes, "avatar"); |
|
158 | 158 | } |
159 | 159 | |
160 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
161 | - return $this->_fieldAs(function($id,$name,$value) use($attributes){ |
|
162 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
160 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
161 | + return $this->_fieldAs(function($id, $name, $value) use($attributes){ |
|
162 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
163 | 163 | return $this->_prepareFormFields($input, $name, $attributes); |
164 | - }, $index,$attributes,"radio"); |
|
164 | + }, $index, $attributes, "radio"); |
|
165 | 165 | } |
166 | 166 | |
167 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
168 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
169 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
170 | - }, $index,$attributes,"radios"); |
|
167 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
168 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
169 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
170 | + }, $index, $attributes, "radios"); |
|
171 | 171 | } |
172 | 172 | |
173 | - public function fieldAsInput($index,$attributes=NULL){ |
|
174 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
175 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
173 | + public function fieldAsInput($index, $attributes=NULL) { |
|
174 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
175 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
176 | 176 | return $this->_prepareFormFields($input, $name, $attributes); |
177 | - }, $index,$attributes,"input"); |
|
177 | + }, $index, $attributes, "input"); |
|
178 | 178 | } |
179 | 179 | |
180 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
181 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
182 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
180 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
181 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
182 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
183 | 183 | return $this->_prepareFormFields($textarea, $name, $attributes); |
184 | - }, $index,$attributes,"textarea"); |
|
184 | + }, $index, $attributes, "textarea"); |
|
185 | 185 | } |
186 | 186 | |
187 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
188 | - if(!\is_array($attributes)){ |
|
187 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
188 | + if (!\is_array($attributes)) { |
|
189 | 189 | $attributes=[]; |
190 | 190 | } |
191 | 191 | $attributes["inputType"]="hidden"; |
192 | - return $this->fieldAsInput($index,$attributes); |
|
192 | + return $this->fieldAsInput($index, $attributes); |
|
193 | 193 | } |
194 | 194 | |
195 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
196 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($attributes){ |
|
197 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
195 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
196 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($attributes){ |
|
197 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
198 | 198 | $input->setChecked(JString::isBooleanTrue($value)); |
199 | 199 | return $this->_prepareFormFields($input, $name, $attributes); |
200 | - }, $index,$attributes,"ck"); |
|
200 | + }, $index, $attributes, "ck"); |
|
201 | 201 | } |
202 | 202 | |
203 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
204 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple,$attributes){ |
|
205 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
206 | - $dd->asSelect($name,$multiple); |
|
203 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
204 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple, $attributes){ |
|
205 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
206 | + $dd->asSelect($name, $multiple); |
|
207 | 207 | return $this->_prepareFormFields($dd, $name, $attributes); |
208 | - }, $index,$attributes,"dd"); |
|
208 | + }, $index, $attributes, "dd"); |
|
209 | 209 | } |
210 | 210 | |
211 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
212 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
213 | - $mess= new HtmlMessage("message-".$id,$caption); |
|
211 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
212 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
213 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
214 | 214 | $mess->addHeader($value); |
215 | 215 | return $mess; |
216 | - }, $index,$attributes,"message"); |
|
216 | + }, $index, $attributes, "message"); |
|
217 | 217 | } |
218 | 218 | |
219 | - public function fieldAsLink($index,$attributes=NULL){ |
|
220 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
221 | - $lnk= new HtmlLink("message-".$id,"#",$caption); |
|
219 | + public function fieldAsLink($index, $attributes=NULL) { |
|
220 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
221 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
222 | 222 | return $lnk; |
223 | - }, $index,$attributes,"link"); |
|
223 | + }, $index, $attributes, "link"); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /**Change fields type |
227 | 227 | * @param array $types an array or associative array $type=>$attributes |
228 | 228 | */ |
229 | - public function fieldsAs(array $types){ |
|
229 | + public function fieldsAs(array $types) { |
|
230 | 230 | $i=0; |
231 | - if(JArray::isAssociative($types)){ |
|
232 | - foreach ($types as $type=>$attributes){ |
|
233 | - if(\is_int($type)) |
|
234 | - $this->fieldAs($i++,$attributes,[]); |
|
235 | - else{ |
|
236 | - $type=preg_replace('/\d/', '', $type ); |
|
237 | - $this->fieldAs($i++,$type,$attributes); |
|
231 | + if (JArray::isAssociative($types)) { |
|
232 | + foreach ($types as $type=>$attributes) { |
|
233 | + if (\is_int($type)) |
|
234 | + $this->fieldAs($i++, $attributes, []); |
|
235 | + else { |
|
236 | + $type=preg_replace('/\d/', '', $type); |
|
237 | + $this->fieldAs($i++, $type, $attributes); |
|
238 | 238 | } |
239 | 239 | } |
240 | - }else{ |
|
241 | - foreach ($types as $type){ |
|
242 | - $this->fieldAs($i++,$type); |
|
240 | + } else { |
|
241 | + foreach ($types as $type) { |
|
242 | + $this->fieldAs($i++, $type); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
247 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
248 | 248 | $method="fieldAs".\ucfirst($type); |
249 | - if(\method_exists($this, $method)){ |
|
250 | - if(!\is_array($attributes)){ |
|
249 | + if (\method_exists($this, $method)) { |
|
250 | + if (!\is_array($attributes)) { |
|
251 | 251 | $attributes=[$index]; |
252 | - }else{ |
|
252 | + } else { |
|
253 | 253 | \array_unshift($attributes, $index); |
254 | 254 | } |
255 | - \call_user_func_array([$this,$method], $attributes); |
|
255 | + \call_user_func_array([$this, $method], $attributes); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
260 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
261 | - $button=new HtmlButton($id,$caption,$cssStyle); |
|
262 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
259 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
260 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
261 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
262 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
263 | 263 | return $button; |
264 | - }, $index,$attributes,"submit"); |
|
264 | + }, $index, $attributes, "submit"); |
|
265 | 265 | } |
266 | 266 | |
267 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
268 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
269 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
267 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
268 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
269 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
270 | 270 | return $button; |
271 | - }, $index,$attributes,"button"); |
|
271 | + }, $index, $attributes, "button"); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | \ No newline at end of file |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | $rules=$attributes["rules"]; |
65 | 65 | if(\is_array($rules)){ |
66 | 66 | $element->addRules($rules); |
67 | - } |
|
68 | - else{ |
|
67 | + } else{ |
|
69 | 68 | $element->addRule($rules); |
70 | 69 | } |
71 | 70 | unset($attributes["rules"]); |
@@ -117,8 +116,9 @@ discard block |
||
117 | 116 | public function fieldAsLabel($index,$icon=NULL,$attributes=NULL){ |
118 | 117 | return $this->_fieldAs(function($id,$name,$value) use($icon){ |
119 | 118 | $lbl=new HtmlLabel($id,$value); |
120 | - if(isset($icon)) |
|
121 | - $lbl->addIcon($icon); |
|
119 | + if(isset($icon)) { |
|
120 | + $lbl->addIcon($icon); |
|
121 | + } |
|
122 | 122 | return $lbl; |
123 | 123 | }, $index,$attributes,"label"); |
124 | 124 | } |
@@ -126,8 +126,9 @@ discard block |
||
126 | 126 | public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
127 | 127 | return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
128 | 128 | $header=new HtmlHeader($id,$niveau,$value); |
129 | - if(isset($icon)) |
|
130 | - $header->asIcon($icon, $value); |
|
129 | + if(isset($icon)) { |
|
130 | + $header->asIcon($icon, $value); |
|
131 | + } |
|
131 | 132 | return $header; |
132 | 133 | }, $index,$attributes,"header"); |
133 | 134 | } |
@@ -135,7 +136,9 @@ discard block |
||
135 | 136 | |
136 | 137 | public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
137 | 138 | $this->setValueFunction($index,function($img) use($size,$circular){ |
138 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
139 | + $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular) { |
|
140 | + $image->setCircular(); |
|
141 | + } |
|
139 | 142 | return $image; |
140 | 143 | }); |
141 | 144 | return $this; |
@@ -230,14 +233,14 @@ discard block |
||
230 | 233 | $i=0; |
231 | 234 | if(JArray::isAssociative($types)){ |
232 | 235 | foreach ($types as $type=>$attributes){ |
233 | - if(\is_int($type)) |
|
234 | - $this->fieldAs($i++,$attributes,[]); |
|
235 | - else{ |
|
236 | + if(\is_int($type)) { |
|
237 | + $this->fieldAs($i++,$attributes,[]); |
|
238 | + } else{ |
|
236 | 239 | $type=preg_replace('/\d/', '', $type ); |
237 | 240 | $this->fieldAs($i++,$type,$attributes); |
238 | 241 | } |
239 | 242 | } |
240 | - }else{ |
|
243 | + } else{ |
|
241 | 244 | foreach ($types as $type){ |
242 | 245 | $this->fieldAs($i++,$type); |
243 | 246 | } |
@@ -249,7 +252,7 @@ discard block |
||
249 | 252 | if(\method_exists($this, $method)){ |
250 | 253 | if(!\is_array($attributes)){ |
251 | 254 | $attributes=[$index]; |
252 | - }else{ |
|
255 | + } else{ |
|
253 | 256 | \array_unshift($attributes, $index); |
254 | 257 | } |
255 | 258 | \call_user_func_array([$this,$method], $attributes); |