@@ -13,7 +13,6 @@ |
||
13 | 13 | use Ajax\service\JArray; |
14 | 14 | use Ajax\semantic\widgets\base\FieldAsTrait; |
15 | 15 | use Ajax\semantic\html\base\HtmlSemDoubleElement; |
16 | -use Ajax\semantic\widgets\base\InstanceViewerCaption; |
|
17 | 16 | use Ajax\semantic\widgets\base\InstanceViewer; |
18 | 17 | |
19 | 18 | /** |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | protected $_hasCheckboxes; |
33 | 33 | protected $_compileParts; |
34 | 34 | |
35 | - public function run(JsUtils $js){ |
|
36 | - if($this->_hasCheckboxes && isset($js)){ |
|
35 | + public function run(JsUtils $js) { |
|
36 | + if ($this->_hasCheckboxes && isset($js)) { |
|
37 | 37 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
38 | 38 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
39 | 39 | \$checkbox.each(function() {if($(this).prop('checked')){allUnchecked = false;}else{allChecked = false;}}); |
@@ -42,21 +42,21 @@ discard block |
||
42 | 42 | parent::run($js); |
43 | 43 | } |
44 | 44 | |
45 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
46 | - parent::__construct($identifier, $model,$modelInstance); |
|
45 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
46 | + parent::__construct($identifier, $model, $modelInstance); |
|
47 | 47 | $this->_instanceViewer=new InstanceViewer(); |
48 | - $this->content=["table"=>new HtmlTable($identifier, 0,0)]; |
|
48 | + $this->content=["table"=>new HtmlTable($identifier, 0, 0)]; |
|
49 | 49 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
50 | 50 | } |
51 | 51 | |
52 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
52 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
53 | 53 | $this->_instanceViewer->setInstance($this->_model); |
54 | 54 | $captions=$this->_instanceViewer->getCaptions(); |
55 | 55 | |
56 | 56 | $table=$this->content["table"]; |
57 | 57 | |
58 | - if($this->_hasCheckboxes){ |
|
59 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
58 | + if ($this->_hasCheckboxes) { |
|
59 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
60 | 60 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);"); |
61 | 61 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);"); |
62 | 62 | \array_unshift($captions, $ck); |
@@ -64,44 +64,44 @@ discard block |
||
64 | 64 | |
65 | 65 | $table->setRowCount(0, \sizeof($captions)); |
66 | 66 | $table->setHeaderValues($captions); |
67 | - if(isset($this->_compileParts)) |
|
67 | + if (isset($this->_compileParts)) |
|
68 | 68 | $table->setCompileParts($this->_compileParts); |
69 | - if(isset($this->_searchField)){ |
|
70 | - if(isset($js)) |
|
71 | - $this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
69 | + if (isset($this->_searchField)) { |
|
70 | + if (isset($js)) |
|
71 | + $this->_searchField->postOn("change", $this->_urls, "{'s':$(this).val()}", "-#".$this->identifier." tbody", ["preventDefault"=>false]); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $this->_generateContent($table); |
75 | 75 | |
76 | - if($this->_hasCheckboxes){ |
|
77 | - if($table->hasPart("thead")) |
|
78 | - $table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort"); |
|
76 | + if ($this->_hasCheckboxes) { |
|
77 | + if ($table->hasPart("thead")) |
|
78 | + $table->getHeader()->getCell(0, 0)->addToProperty("class", "no-sort"); |
|
79 | 79 | } |
80 | 80 | |
81 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
81 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
82 | 82 | $this->_generatePagination($table); |
83 | 83 | } |
84 | - if(isset($this->_toolbar)){ |
|
84 | + if (isset($this->_toolbar)) { |
|
85 | 85 | $this->_setToolbarPosition($table, $captions); |
86 | 86 | } |
87 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
88 | - return parent::compile($js,$view); |
|
87 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
88 | + return parent::compile($js, $view); |
|
89 | 89 | } |
90 | 90 | |
91 | - protected function _generateContent($table){ |
|
91 | + protected function _generateContent($table) { |
|
92 | 92 | $objects=$this->_modelInstance; |
93 | - if(isset($this->_pagination)){ |
|
93 | + if (isset($this->_pagination)) { |
|
94 | 94 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
95 | 95 | } |
96 | 96 | InstanceViewer::setIndex(0); |
97 | - $table->fromDatabaseObjects($objects, function($instance){ |
|
97 | + $table->fromDatabaseObjects($objects, function($instance) { |
|
98 | 98 | $this->_instanceViewer->setInstance($instance); |
99 | 99 | InstanceViewer::$index++; |
100 | - $result= $this->_instanceViewer->getValues(); |
|
101 | - if($this->_hasCheckboxes){ |
|
102 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
100 | + $result=$this->_instanceViewer->getValues(); |
|
101 | + if ($this->_hasCheckboxes) { |
|
102 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
103 | 103 | $field=$ck->getField(); |
104 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
104 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
105 | 105 | $field->setProperty("name", "selection[]"); |
106 | 106 | \array_unshift($result, $ck); |
107 | 107 | } |
@@ -109,25 +109,25 @@ discard block |
||
109 | 109 | }); |
110 | 110 | } |
111 | 111 | |
112 | - private function _generatePagination($table){ |
|
112 | + private function _generatePagination($table) { |
|
113 | 113 | $footer=$table->getFooter(); |
114 | 114 | $footer->mergeCol(); |
115 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
115 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
116 | 116 | $menu->floatRight(); |
117 | 117 | $menu->setActiveItem($this->_pagination->getPage()-1); |
118 | 118 | $footer->setValues($menu); |
119 | - $menu->postOnClick($this->_urls,"{'p':$(this).attr('data-page')}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
119 | + $menu->postOnClick($this->_urls, "{'p':$(this).attr('data-page')}", "-#".$this->identifier." tbody", ["preventDefault"=>false]); |
|
120 | 120 | } |
121 | 121 | |
122 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
123 | - switch ($this->_toolbarPosition){ |
|
122 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
123 | + switch ($this->_toolbarPosition) { |
|
124 | 124 | case PositionInTable::BEFORETABLE:case PositionInTable::AFTERTABLE: |
125 | - if(isset($this->_compileParts)===false){ |
|
125 | + if (isset($this->_compileParts)===false) { |
|
126 | 126 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
127 | 127 | } |
128 | 128 | break; |
129 | 129 | case PositionInTable::HEADER:case PositionInTable::FOOTER: case PositionInTable::BODY: |
130 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
130 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
131 | 131 | break; |
132 | 132 | } |
133 | 133 | } |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | * @param callable $callback function called after the field compilation |
140 | 140 | * @return \Ajax\semantic\widgets\datatable\DataTable |
141 | 141 | */ |
142 | - public function afterCompile($index,$callback){ |
|
143 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
142 | + public function afterCompile($index, $callback) { |
|
143 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
144 | 144 | return $this; |
145 | 145 | } |
146 | 146 | |
147 | - private function addToolbarRow($part,$table,$captions){ |
|
147 | + private function addToolbarRow($part, $table, $captions) { |
|
148 | 148 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
149 | 149 | $row->mergeCol(); |
150 | 150 | $row->setValues([$this->_toolbar]); |
@@ -159,42 +159,42 @@ discard block |
||
159 | 159 | return $this; |
160 | 160 | } |
161 | 161 | |
162 | - public function setCaptions($captions){ |
|
162 | + public function setCaptions($captions) { |
|
163 | 163 | $this->_instanceViewer->setCaptions($captions); |
164 | 164 | return $this; |
165 | 165 | } |
166 | 166 | |
167 | - public function setFields($fields){ |
|
167 | + public function setFields($fields) { |
|
168 | 168 | $this->_instanceViewer->setVisibleProperties($fields); |
169 | 169 | return $this; |
170 | 170 | } |
171 | 171 | |
172 | - public function addField($field){ |
|
172 | + public function addField($field) { |
|
173 | 173 | $this->_instanceViewer->addField($field); |
174 | 174 | return $this; |
175 | 175 | } |
176 | 176 | |
177 | - public function insertField($index,$field){ |
|
177 | + public function insertField($index, $field) { |
|
178 | 178 | $this->_instanceViewer->insertField($index, $field); |
179 | 179 | return $this; |
180 | 180 | } |
181 | 181 | |
182 | - public function insertInField($index,$field){ |
|
182 | + public function insertInField($index, $field) { |
|
183 | 183 | $this->_instanceViewer->insertInField($index, $field); |
184 | 184 | return $this; |
185 | 185 | } |
186 | 186 | |
187 | - public function setValueFunction($index,$callback){ |
|
187 | + public function setValueFunction($index, $callback) { |
|
188 | 188 | $this->_instanceViewer->setValueFunction($index, $callback); |
189 | 189 | return $this; |
190 | 190 | } |
191 | 191 | |
192 | - public function setIdentifierFunction($callback){ |
|
192 | + public function setIdentifierFunction($callback) { |
|
193 | 193 | $this->_instanceViewer->setIdentifierFunction($callback); |
194 | 194 | return $this; |
195 | 195 | } |
196 | 196 | |
197 | - public function getHtmlComponent(){ |
|
197 | + public function getHtmlComponent() { |
|
198 | 198 | return $this->content["table"]; |
199 | 199 | } |
200 | 200 | |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | return $this; |
208 | 208 | } |
209 | 209 | |
210 | - public function paginate($items_per_page=10,$page=1){ |
|
211 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
210 | + public function paginate($items_per_page=10, $page=1) { |
|
211 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | public function getHasCheckboxes() { |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | return $this; |
221 | 221 | } |
222 | 222 | |
223 | - public function refresh($compileParts=["tbody"]){ |
|
223 | + public function refresh($compileParts=["tbody"]) { |
|
224 | 224 | $this->_compileParts=$compileParts; |
225 | 225 | return $this; |
226 | 226 | } |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | * @param callable $callback |
230 | 230 | * @return callable |
231 | 231 | */ |
232 | - private function getFieldButtonCallable($caption,$callback=null){ |
|
233 | - return $this->getCallable("getFieldButton",[$caption],$callback); |
|
232 | + private function getFieldButtonCallable($caption, $callback=null) { |
|
233 | + return $this->getCallable("getFieldButton", [$caption], $callback); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,16 +238,16 @@ discard block |
||
238 | 238 | * @param callable $callback |
239 | 239 | * @return callable |
240 | 240 | */ |
241 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
242 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
243 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
244 | - if(isset($callback)){ |
|
245 | - if(\is_callable($callback)){ |
|
246 | - $callback($object,$instance); |
|
241 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
242 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
243 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
244 | + if (isset($callback)) { |
|
245 | + if (\is_callable($callback)) { |
|
246 | + $callback($object, $instance); |
|
247 | 247 | } |
248 | 248 | } |
249 | - if($object instanceof HtmlSemDoubleElement){ |
|
250 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
249 | + if ($object instanceof HtmlSemDoubleElement) { |
|
250 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
251 | 251 | } |
252 | 252 | return $object; |
253 | 253 | }; |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | * @param string $caption |
259 | 259 | * @return HtmlButton |
260 | 260 | */ |
261 | - private function getFieldButton($caption){ |
|
262 | - return new HtmlButton("",$caption); |
|
261 | + private function getFieldButton($caption) { |
|
262 | + return new HtmlButton("", $caption); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | * @param callable $callback |
269 | 269 | * @return \Ajax\semantic\widgets\datatable\DataTable |
270 | 270 | */ |
271 | - public function addFieldButton($caption,$callback=null){ |
|
272 | - $this->addField($this->getCallable("getFieldButton",[$caption],$callback)); |
|
271 | + public function addFieldButton($caption, $callback=null) { |
|
272 | + $this->addField($this->getCallable("getFieldButton", [$caption], $callback)); |
|
273 | 273 | return $this; |
274 | 274 | } |
275 | 275 | |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * @param callable $callback |
281 | 281 | * @return \Ajax\semantic\widgets\datatable\DataTable |
282 | 282 | */ |
283 | - public function insertFieldButton($index,$caption,$callback=null){ |
|
284 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$callback)); |
|
283 | + public function insertFieldButton($index, $caption, $callback=null) { |
|
284 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $callback)); |
|
285 | 285 | return $this; |
286 | 286 | } |
287 | 287 | |
@@ -292,65 +292,65 @@ discard block |
||
292 | 292 | * @param callable $callback |
293 | 293 | * @return \Ajax\semantic\widgets\datatable\DataTable |
294 | 294 | */ |
295 | - public function insertInFieldButton($index,$caption,$callback=null){ |
|
296 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$callback)); |
|
295 | + public function insertInFieldButton($index, $caption, $callback=null) { |
|
296 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $callback)); |
|
297 | 297 | return $this; |
298 | 298 | } |
299 | 299 | |
300 | - private function addDefaultButton($icon,$class=null,$callback=null){ |
|
301 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class],$callback)); |
|
300 | + private function addDefaultButton($icon, $class=null, $callback=null) { |
|
301 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class], $callback)); |
|
302 | 302 | return $this; |
303 | 303 | } |
304 | 304 | |
305 | - private function insertDefaultButtonIn($index,$icon,$class=null,$callback=null){ |
|
306 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class],$callback)); |
|
305 | + private function insertDefaultButtonIn($index, $icon, $class=null, $callback=null) { |
|
306 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class], $callback)); |
|
307 | 307 | return $this; |
308 | 308 | } |
309 | 309 | |
310 | - private function getDefaultButton($icon,$class=null){ |
|
310 | + private function getDefaultButton($icon, $class=null) { |
|
311 | 311 | $bt=$this->getFieldButton(""); |
312 | 312 | $bt->asIcon($icon); |
313 | - if(isset($class)) |
|
313 | + if (isset($class)) |
|
314 | 314 | $bt->addToProperty("class", $class); |
315 | 315 | return $bt; |
316 | 316 | } |
317 | 317 | |
318 | - public function addDeleteButton($callback=null){ |
|
319 | - return $this->addDefaultButton("remove","delete red basic",$callback); |
|
318 | + public function addDeleteButton($callback=null) { |
|
319 | + return $this->addDefaultButton("remove", "delete red basic", $callback); |
|
320 | 320 | } |
321 | 321 | |
322 | - public function addEditButton($callback=null){ |
|
323 | - return $this->addDefaultButton("edit","edit basic",$callback); |
|
322 | + public function addEditButton($callback=null) { |
|
323 | + return $this->addDefaultButton("edit", "edit basic", $callback); |
|
324 | 324 | } |
325 | 325 | |
326 | - public function addEditDeleteButtons($callbackEdit=null,$callbackDelete=null){ |
|
326 | + public function addEditDeleteButtons($callbackEdit=null, $callbackDelete=null) { |
|
327 | 327 | $this->addEditButton($callbackEdit); |
328 | 328 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
329 | - $this->insertDeleteButtonIn($index,$callbackDelete); |
|
329 | + $this->insertDeleteButtonIn($index, $callbackDelete); |
|
330 | 330 | return $this; |
331 | 331 | } |
332 | 332 | |
333 | - public function insertDeleteButtonIn($index,$callback=null){ |
|
334 | - return $this->insertDefaultButtonIn($index,"remove","delete red basic",$callback); |
|
333 | + public function insertDeleteButtonIn($index, $callback=null) { |
|
334 | + return $this->insertDefaultButtonIn($index, "remove", "delete red basic", $callback); |
|
335 | 335 | } |
336 | 336 | |
337 | - public function insertEditButtonIn($index,$callback=null){ |
|
338 | - return $this->insertDefaultButtonIn($index,"edit","edit basic",$callback); |
|
337 | + public function insertEditButtonIn($index, $callback=null) { |
|
338 | + return $this->insertDefaultButtonIn($index, "edit", "edit basic", $callback); |
|
339 | 339 | } |
340 | 340 | |
341 | - public function setSelectable(){ |
|
341 | + public function setSelectable() { |
|
342 | 342 | $this->content["table"]->setSelectable(); |
343 | 343 | return $this; |
344 | 344 | } |
345 | 345 | |
346 | - public function addSearchInToolbar(){ |
|
346 | + public function addSearchInToolbar() { |
|
347 | 347 | return $this->addInToolbar($this->getSearchField())->setPosition("right"); |
348 | 348 | } |
349 | 349 | |
350 | - public function getSearchField(){ |
|
351 | - if(isset($this->_searchField)===false){ |
|
352 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
353 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
350 | + public function getSearchField() { |
|
351 | + if (isset($this->_searchField)===false) { |
|
352 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
353 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
354 | 354 | } |
355 | 355 | return $this->_searchField; |
356 | 356 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | return $this; |
361 | 361 | } |
362 | 362 | |
363 | - protected function _getFieldIdentifier($prefix){ |
|
363 | + protected function _getFieldIdentifier($prefix) { |
|
364 | 364 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
365 | 365 | } |
366 | 366 |
@@ -14,123 +14,123 @@ discard block |
||
14 | 14 | |
15 | 15 | public static $index=0; |
16 | 16 | |
17 | - public function __construct($instance=NULL,$captions=NULL){ |
|
17 | + public function __construct($instance=NULL, $captions=NULL) { |
|
18 | 18 | $this->values=[]; |
19 | 19 | $this->afterCompile=[]; |
20 | - if(isset($instance)) |
|
20 | + if (isset($instance)) |
|
21 | 21 | $this->setInstance($instance); |
22 | 22 | $this->setCaptions($captions); |
23 | 23 | } |
24 | 24 | |
25 | - public function getValues(){ |
|
25 | + public function getValues() { |
|
26 | 26 | $values=[]; |
27 | 27 | $index=0; |
28 | 28 | $count=$this->count(); |
29 | - while($index<$count){ |
|
29 | + while ($index<$count) { |
|
30 | 30 | $values[]=$this->getValue($index++); |
31 | 31 | } |
32 | 32 | return $values; |
33 | 33 | } |
34 | 34 | |
35 | - public function getIdentifier(){ |
|
35 | + public function getIdentifier() { |
|
36 | 36 | $value=self::$index; |
37 | - if(isset($this->values["identifier"])) |
|
38 | - $value=$this->values["identifier"](self::$index,$this->instance); |
|
37 | + if (isset($this->values["identifier"])) |
|
38 | + $value=$this->values["identifier"](self::$index, $this->instance); |
|
39 | 39 | return $value; |
40 | 40 | } |
41 | 41 | |
42 | - public function getValue($index){ |
|
42 | + public function getValue($index) { |
|
43 | 43 | $property=$this->properties[$index]; |
44 | 44 | return $this->_getValue($property, $index); |
45 | 45 | } |
46 | 46 | |
47 | - private function _getValue($property,$index){ |
|
48 | - if($property instanceof \ReflectionProperty){ |
|
47 | + private function _getValue($property, $index) { |
|
48 | + if ($property instanceof \ReflectionProperty) { |
|
49 | 49 | $property->setAccessible(true); |
50 | 50 | $value=$property->getValue($this->instance); |
51 | - if(isset($this->values[$index])){ |
|
52 | - $value= $this->values[$index]($value); |
|
51 | + if (isset($this->values[$index])) { |
|
52 | + $value=$this->values[$index]($value); |
|
53 | 53 | } |
54 | - }else{ |
|
55 | - if(\is_callable($property)) |
|
54 | + } else { |
|
55 | + if (\is_callable($property)) |
|
56 | 56 | $value=$property($this->instance); |
57 | - elseif(\is_array($property)){ |
|
58 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
57 | + elseif (\is_array($property)) { |
|
58 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
59 | 59 | $value=\implode("", $values); |
60 | - }else |
|
60 | + } else |
|
61 | 61 | $value=$property; |
62 | 62 | } |
63 | - if(isset($this->afterCompile[$index])){ |
|
64 | - if(\is_callable($this->afterCompile[$index])){ |
|
65 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
63 | + if (isset($this->afterCompile[$index])) { |
|
64 | + if (\is_callable($this->afterCompile[$index])) { |
|
65 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | return $value; |
69 | 69 | } |
70 | 70 | |
71 | - public function insertField($index,$field){ |
|
72 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
71 | + public function insertField($index, $field) { |
|
72 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
73 | 73 | return $this; |
74 | 74 | } |
75 | 75 | |
76 | - public function insertInField($index,$field){ |
|
76 | + public function insertInField($index, $field) { |
|
77 | 77 | $vb=$this->visibleProperties; |
78 | - if(isset($vb[$index])){ |
|
79 | - if(\is_array($vb[$index])){ |
|
78 | + if (isset($vb[$index])) { |
|
79 | + if (\is_array($vb[$index])) { |
|
80 | 80 | $this->visibleProperties[$index][]=$field; |
81 | - }else{ |
|
82 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
81 | + } else { |
|
82 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
83 | 83 | } |
84 | - }else{ |
|
84 | + } else { |
|
85 | 85 | return $this->insertField($index, $field); |
86 | 86 | } |
87 | 87 | return $this; |
88 | 88 | } |
89 | 89 | |
90 | - public function addField($field){ |
|
90 | + public function addField($field) { |
|
91 | 91 | $this->visibleProperties[]=$field; |
92 | 92 | return $this; |
93 | 93 | } |
94 | 94 | |
95 | - public function count(){ |
|
95 | + public function count() { |
|
96 | 96 | return \sizeof($this->properties); |
97 | 97 | } |
98 | 98 | |
99 | - public function visiblePropertiesCount(){ |
|
99 | + public function visiblePropertiesCount() { |
|
100 | 100 | return \sizeof($this->visibleProperties); |
101 | 101 | } |
102 | 102 | |
103 | - private function showableProperty(\ReflectionProperty $rProperty){ |
|
104 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
103 | + private function showableProperty(\ReflectionProperty $rProperty) { |
|
104 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | public function setInstance($instance) { |
108 | - if(\is_string($instance)){ |
|
108 | + if (\is_string($instance)) { |
|
109 | 109 | $instance=new $instance(); |
110 | 110 | } |
111 | 111 | $this->instance=$instance; |
112 | 112 | $this->properties=[]; |
113 | 113 | $this->reflect=new \ReflectionClass($instance); |
114 | - if(\sizeof($this->visibleProperties)===0){ |
|
114 | + if (\sizeof($this->visibleProperties)===0) { |
|
115 | 115 | $this->properties=$this->getDefaultProperties(); |
116 | - }else{ |
|
117 | - foreach ($this->visibleProperties as $property){ |
|
118 | - if(\is_callable($property)){ |
|
116 | + } else { |
|
117 | + foreach ($this->visibleProperties as $property) { |
|
118 | + if (\is_callable($property)) { |
|
119 | 119 | $this->properties[]=$property; |
120 | - }elseif(\is_string($property)){ |
|
121 | - try{ |
|
120 | + }elseif (\is_string($property)) { |
|
121 | + try { |
|
122 | 122 | $rProperty=$this->reflect->getProperty($property); |
123 | 123 | $this->properties[]=$rProperty; |
124 | - }catch(\Exception $e){ |
|
124 | + }catch (\Exception $e) { |
|
125 | 125 | $this->properties[]=$property; |
126 | 126 | } |
127 | - }elseif(\is_int($property)){ |
|
127 | + }elseif (\is_int($property)) { |
|
128 | 128 | $props=$this->getDefaultProperties(); |
129 | - if(isset($props[$property])) |
|
129 | + if (isset($props[$property])) |
|
130 | 130 | $this->properties[]=$props[$property]; |
131 | 131 | else |
132 | 132 | $this->properties[]=$property; |
133 | - }else{ |
|
133 | + } else { |
|
134 | 134 | $this->properties[]=$property; |
135 | 135 | } |
136 | 136 | } |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | return $this; |
139 | 139 | } |
140 | 140 | |
141 | - private function getDefaultProperties(){ |
|
141 | + private function getDefaultProperties() { |
|
142 | 142 | $result=[]; |
143 | 143 | $properties=$this->reflect->getProperties(); |
144 | - foreach ($properties as $property){ |
|
144 | + foreach ($properties as $property) { |
|
145 | 145 | $showable=$this->showableProperty($property); |
146 | - if($showable!==false){ |
|
146 | + if ($showable!==false) { |
|
147 | 147 | $result[]=$property; |
148 | 148 | } |
149 | 149 | } |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | return $this; |
156 | 156 | } |
157 | 157 | |
158 | - public function setValueFunction($index,$callback){ |
|
158 | + public function setValueFunction($index, $callback) { |
|
159 | 159 | $this->values[$index]=$callback; |
160 | 160 | return $this; |
161 | 161 | } |
162 | 162 | |
163 | - public function setIdentifierFunction($callback){ |
|
163 | + public function setIdentifierFunction($callback) { |
|
164 | 164 | $this->values["identifier"]=$callback; |
165 | 165 | return $this; |
166 | 166 | } |
@@ -173,19 +173,19 @@ discard block |
||
173 | 173 | return $this->properties; |
174 | 174 | } |
175 | 175 | |
176 | - public function getCaption($index){ |
|
177 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
176 | + public function getCaption($index) { |
|
177 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
178 | 178 | return $this->properties[$index]->getName(); |
179 | - elseif(\is_callable($this->properties[$index])) |
|
179 | + elseif (\is_callable($this->properties[$index])) |
|
180 | 180 | return ""; |
181 | 181 | else |
182 | 182 | return $this->properties[$index]; |
183 | 183 | } |
184 | 184 | |
185 | - public function getCaptions(){ |
|
186 | - if(isset($this->captions)){ |
|
187 | - $result= $this->captions; |
|
188 | - for($i=\sizeof($result);$i<$this->count();$i++){ |
|
185 | + public function getCaptions() { |
|
186 | + if (isset($this->captions)) { |
|
187 | + $result=$this->captions; |
|
188 | + for ($i=\sizeof($result); $i<$this->count(); $i++) { |
|
189 | 189 | $result[]=""; |
190 | 190 | } |
191 | 191 | return $result; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $captions=[]; |
194 | 194 | $index=0; |
195 | 195 | $count=$this->count(); |
196 | - while($index<$count){ |
|
196 | + while ($index<$count) { |
|
197 | 197 | $captions[]=$this->getCaption($index++); |
198 | 198 | } |
199 | 199 | return $captions; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param callable $callback function called after the field compilation |
212 | 212 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
213 | 213 | */ |
214 | - public function afterCompile($index,$callback){ |
|
214 | + public function afterCompile($index, $callback) { |
|
215 | 215 | $this->afterCompile[$index]=$callback; |
216 | 216 | return $this; |
217 | 217 | } |
@@ -19,35 +19,35 @@ |
||
19 | 19 | class DataElement extends Widget { |
20 | 20 | |
21 | 21 | public function __construct($identifier, $modelInstance=NULL) { |
22 | - parent::__construct($identifier, null,$modelInstance); |
|
22 | + parent::__construct($identifier, null, $modelInstance); |
|
23 | 23 | $this->_instanceViewer=new InstanceViewer(); |
24 | - $this->content=["table"=>new HtmlTable($identifier, 0,2)]; |
|
24 | + $this->content=["table"=>new HtmlTable($identifier, 0, 2)]; |
|
25 | 25 | $this->content["table"]->setDefinition(); |
26 | 26 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
27 | 27 | } |
28 | 28 | |
29 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
29 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
30 | 30 | $this->_instanceViewer->setInstance($this->_modelInstance); |
31 | 31 | |
32 | 32 | $table=$this->content["table"]; |
33 | 33 | $this->_generateContent($table); |
34 | 34 | |
35 | - if(isset($this->_toolbar)){ |
|
35 | + if (isset($this->_toolbar)) { |
|
36 | 36 | $this->_setToolbarPosition($table); |
37 | 37 | } |
38 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
39 | - return parent::compile($js,$view); |
|
38 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
39 | + return parent::compile($js, $view); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @param HtmlTable $table |
44 | 44 | */ |
45 | - protected function _generateContent($table){ |
|
45 | + protected function _generateContent($table) { |
|
46 | 46 | $captions=$this->_instanceViewer->getCaptions(); |
47 | - $values= $this->_instanceViewer->getValues(); |
|
47 | + $values=$this->_instanceViewer->getValues(); |
|
48 | 48 | $count=$this->_instanceViewer->count(); |
49 | - for($i=0;$i<$count;$i++){ |
|
50 | - $table->addRow([$captions[$i],$values[$i]]); |
|
49 | + for ($i=0; $i<$count; $i++) { |
|
50 | + $table->addRow([$captions[$i], $values[$i]]); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | * @param array $instances |
15 | 15 | * @return DataTable |
16 | 16 | */ |
17 | - public function dataTable($identifier,$model, $instances){ |
|
18 | - return $this->addHtmlComponent(new DataTable($identifier,$model,$instances)); |
|
17 | + public function dataTable($identifier, $model, $instances) { |
|
18 | + return $this->addHtmlComponent(new DataTable($identifier, $model, $instances)); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param object $instance |
24 | 24 | * @return DataElement |
25 | 25 | */ |
26 | - public function dataElement($identifier, $instance){ |
|
27 | - return $this->addHtmlComponent(new DataElement($identifier,$instance)); |
|
26 | + public function dataElement($identifier, $instance) { |
|
27 | + return $this->addHtmlComponent(new DataElement($identifier, $instance)); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | \ No newline at end of file |