@@ -38,6 +38,10 @@ discard block |
||
38 | 38 | parent::run($js); |
39 | 39 | } |
40 | 40 | |
41 | + /** |
|
42 | + * @param string $identifier |
|
43 | + * @param string $model |
|
44 | + */ |
|
41 | 45 | public function __construct($identifier,$model,$modelInstance=NULL) { |
42 | 46 | parent::__construct($identifier, $model,$modelInstance); |
43 | 47 | $this->_instanceViewer=new InstanceViewer(); |
@@ -164,21 +168,34 @@ discard block |
||
164 | 168 | return $this; |
165 | 169 | } |
166 | 170 | |
171 | + /** |
|
172 | + * @param \Closure $field |
|
173 | + */ |
|
167 | 174 | public function addField($field){ |
168 | 175 | $this->_instanceViewer->addField($field); |
169 | 176 | return $this; |
170 | 177 | } |
171 | 178 | |
179 | + /** |
|
180 | + * @param integer $index |
|
181 | + * @param \Closure $field |
|
182 | + */ |
|
172 | 183 | public function insertField($index,$field){ |
173 | 184 | $this->_instanceViewer->insertField($index, $field); |
174 | 185 | return $this; |
175 | 186 | } |
176 | 187 | |
188 | + /** |
|
189 | + * @param \Closure $field |
|
190 | + */ |
|
177 | 191 | public function insertInField($index,$field){ |
178 | 192 | $this->_instanceViewer->insertInField($index, $field); |
179 | 193 | return $this; |
180 | 194 | } |
181 | 195 | |
196 | + /** |
|
197 | + * @param \Closure $callback |
|
198 | + */ |
|
182 | 199 | public function setValueFunction($index,$callback){ |
183 | 200 | $this->_instanceViewer->setValueFunction($index, $callback); |
184 | 201 | return $this; |
@@ -222,16 +239,16 @@ discard block |
||
222 | 239 | /** |
223 | 240 | * @param string $caption |
224 | 241 | * @param callable $callback |
225 | - * @return callable |
|
242 | + * @return \Closure |
|
226 | 243 | */ |
227 | 244 | private function getFieldButtonCallable($caption,$callback=null){ |
228 | 245 | return $this->getCallable($this->getFieldButton($caption),$callback); |
229 | 246 | } |
230 | 247 | |
231 | 248 | /** |
232 | - * @param mixed $object |
|
249 | + * @param HtmlButton $object |
|
233 | 250 | * @param callable $callback |
234 | - * @return callable |
|
251 | + * @return \Closure |
|
235 | 252 | */ |
236 | 253 | private function getCallable($object,$callback=null){ |
237 | 254 | $result=function($instance) use($object,$callback){ |
@@ -290,12 +307,20 @@ discard block |
||
290 | 307 | return $this; |
291 | 308 | } |
292 | 309 | |
310 | + /** |
|
311 | + * @param string $icon |
|
312 | + * @param string $class |
|
313 | + */ |
|
293 | 314 | private function addDefaultButton($icon,$class=null,$callback=null){ |
294 | 315 | $bt=$this->getDefaultButton($icon,$class); |
295 | 316 | $this->addField($this->getCallable($bt,$callback)); |
296 | 317 | return $this; |
297 | 318 | } |
298 | 319 | |
320 | + /** |
|
321 | + * @param string $icon |
|
322 | + * @param string $class |
|
323 | + */ |
|
299 | 324 | private function insertDefaultButtonIn($index,$icon,$class=null,$callback=null){ |
300 | 325 | $bt=$this->getDefaultButton($icon,$class); |
301 | 326 | $this->insertInField($index,$this->getCallable($bt,$callback)); |
@@ -458,6 +483,9 @@ discard block |
||
458 | 483 | return $this; |
459 | 484 | } |
460 | 485 | |
486 | + /** |
|
487 | + * @param string $prefix |
|
488 | + */ |
|
461 | 489 | private function _getFieldIdentifier($prefix){ |
462 | 490 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
463 | 491 | } |
@@ -60,18 +60,21 @@ discard block |
||
60 | 60 | |
61 | 61 | $table->setRowCount(0, \sizeof($captions)); |
62 | 62 | $table->setHeaderValues($captions); |
63 | - if(isset($this->_compileParts)) |
|
64 | - $table->setCompileParts($this->_compileParts); |
|
63 | + if(isset($this->_compileParts)) { |
|
64 | + $table->setCompileParts($this->_compileParts); |
|
65 | + } |
|
65 | 66 | if(isset($this->_searchField)){ |
66 | - if(isset($js)) |
|
67 | - $this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
67 | + if(isset($js)) { |
|
68 | + $this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
69 | + } |
|
68 | 70 | } |
69 | 71 | |
70 | 72 | $this->_generateContent($table); |
71 | 73 | |
72 | 74 | if($this->_hasCheckboxes){ |
73 | - if($table->hasPart("thead")) |
|
74 | - $table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort"); |
|
75 | + if($table->hasPart("thead")) { |
|
76 | + $table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort"); |
|
77 | + } |
|
75 | 78 | } |
76 | 79 | |
77 | 80 | if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
@@ -305,8 +308,9 @@ discard block |
||
305 | 308 | private function getDefaultButton($icon,$class=null){ |
306 | 309 | $bt=$this->getFieldButton(""); |
307 | 310 | $bt->asIcon($icon); |
308 | - if(isset($class)) |
|
309 | - $bt->addToProperty("class", $class); |
|
311 | + if(isset($class)) { |
|
312 | + $bt->addToProperty("class", $class); |
|
313 | + } |
|
310 | 314 | return $bt; |
311 | 315 | } |
312 | 316 | |
@@ -395,7 +399,9 @@ discard block |
||
395 | 399 | |
396 | 400 | public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
397 | 401 | $this->setValueFunction($index,function($img) use($size,$circular){ |
398 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
402 | + $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular) { |
|
403 | + $image->setCircular(); |
|
404 | + } |
|
399 | 405 | return $image; |
400 | 406 | } |
401 | 407 | ); |
@@ -15,16 +15,18 @@ discard block |
||
15 | 15 | public function __construct($instance=NULL,$captions=NULL){ |
16 | 16 | $this->values=[]; |
17 | 17 | $this->afterCompile=[]; |
18 | - if(isset($instance)) |
|
19 | - $this->setInstance($instance); |
|
18 | + if(isset($instance)) { |
|
19 | + $this->setInstance($instance); |
|
20 | + } |
|
20 | 21 | $this->setCaptions($captions); |
21 | 22 | } |
22 | 23 | |
23 | 24 | public function getCaption($index){ |
24 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
25 | - return $this->properties[$index]->getName(); |
|
26 | - else |
|
27 | - return $this->properties[$index]; |
|
25 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
26 | + return $this->properties[$index]->getName(); |
|
27 | + } else { |
|
28 | + return $this->properties[$index]; |
|
29 | + } |
|
28 | 30 | } |
29 | 31 | |
30 | 32 | public function getCaptions(){ |
@@ -56,8 +58,9 @@ discard block |
||
56 | 58 | |
57 | 59 | public function getIdentifier(){ |
58 | 60 | $value=self::$index; |
59 | - if(isset($this->values["identifier"])) |
|
60 | - $value=$this->values["identifier"](self::$index,$this->instance); |
|
61 | + if(isset($this->values["identifier"])) { |
|
62 | + $value=$this->values["identifier"](self::$index,$this->instance); |
|
63 | + } |
|
61 | 64 | self::$index++; |
62 | 65 | return $value; |
63 | 66 | } |
@@ -74,14 +77,15 @@ discard block |
||
74 | 77 | if(isset($this->values[$index])){ |
75 | 78 | $value= $this->values[$index]($value); |
76 | 79 | } |
77 | - }else{ |
|
78 | - if(\is_callable($property)) |
|
79 | - $value=$property($this->instance); |
|
80 | - elseif(\is_array($property)){ |
|
80 | + } else{ |
|
81 | + if(\is_callable($property)) { |
|
82 | + $value=$property($this->instance); |
|
83 | + } elseif(\is_array($property)){ |
|
81 | 84 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
82 | 85 | $value=\implode("", $values); |
83 | - }else |
|
84 | - $value=$property; |
|
86 | + } else { |
|
87 | + $value=$property; |
|
88 | + } |
|
85 | 89 | } |
86 | 90 | if(isset($this->afterCompile[$index])){ |
87 | 91 | if(\is_callable($this->afterCompile[$index])){ |
@@ -101,10 +105,10 @@ discard block |
||
101 | 105 | if(isset($vb[$index])){ |
102 | 106 | if(\is_array($vb[$index])){ |
103 | 107 | $this->visibleProperties[$index][]=$field; |
104 | - }else{ |
|
108 | + } else{ |
|
105 | 109 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
106 | 110 | } |
107 | - }else{ |
|
111 | + } else{ |
|
108 | 112 | return $this->insertField($index, $field); |
109 | 113 | } |
110 | 114 | return $this; |
@@ -136,24 +140,25 @@ discard block |
||
136 | 140 | $this->reflect=new \ReflectionClass($instance); |
137 | 141 | if(\sizeof($this->visibleProperties)===0){ |
138 | 142 | $this->properties=$this->getDefaultProperties(); |
139 | - }else{ |
|
143 | + } else{ |
|
140 | 144 | foreach ($this->visibleProperties as $property){ |
141 | 145 | if(\is_callable($property)){ |
142 | 146 | $this->properties[]=$property; |
143 | - }elseif(\is_string($property)){ |
|
147 | + } elseif(\is_string($property)){ |
|
144 | 148 | try{ |
145 | 149 | $rProperty=$this->reflect->getProperty($property); |
146 | 150 | $this->properties[]=$rProperty; |
147 | - }catch(\Exception $e){ |
|
151 | + } catch(\Exception $e){ |
|
148 | 152 | $this->properties[]=$property; |
149 | 153 | } |
150 | - }elseif(\is_int($property)){ |
|
154 | + } elseif(\is_int($property)){ |
|
151 | 155 | $props=$this->getDefaultProperties(); |
152 | - if(isset($props[$property])) |
|
153 | - $this->properties[]=$props[$property]; |
|
154 | - else |
|
155 | - $this->properties[]=$property; |
|
156 | - }else{ |
|
156 | + if(isset($props[$property])) { |
|
157 | + $this->properties[]=$props[$property]; |
|
158 | + } else { |
|
159 | + $this->properties[]=$property; |
|
160 | + } |
|
161 | + } else{ |
|
157 | 162 | $this->properties[]=$property; |
158 | 163 | } |
159 | 164 | } |