@@ -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 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | protected $_compileParts; |
29 | 29 | protected $_toolbarPosition; |
30 | 30 | |
31 | - public function run(JsUtils $js){ |
|
32 | - if($this->_hasCheckboxes && isset($js)){ |
|
31 | + public function run(JsUtils $js) { |
|
32 | + if ($this->_hasCheckboxes && isset($js)) { |
|
33 | 33 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
34 | 34 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
35 | 35 | \$checkbox.each(function() {if($(this).prop('checked')){allUnchecked = false;}else{allChecked = false;}}); |
@@ -38,21 +38,21 @@ discard block |
||
38 | 38 | parent::run($js); |
39 | 39 | } |
40 | 40 | |
41 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
42 | - parent::__construct($identifier, $model,$modelInstance); |
|
41 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
42 | + parent::__construct($identifier, $model, $modelInstance); |
|
43 | 43 | $this->_instanceViewer=new InstanceViewer(); |
44 | - $this->content=["table"=>new HtmlTable($identifier, 0,0)]; |
|
44 | + $this->content=["table"=>new HtmlTable($identifier, 0, 0)]; |
|
45 | 45 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
46 | 46 | } |
47 | 47 | |
48 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
48 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
49 | 49 | $this->_instanceViewer->setInstance($this->_model); |
50 | 50 | $captions=$this->_instanceViewer->getCaptions(); |
51 | 51 | |
52 | 52 | $table=$this->content["table"]; |
53 | 53 | |
54 | - if($this->_hasCheckboxes){ |
|
55 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
54 | + if ($this->_hasCheckboxes) { |
|
55 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
56 | 56 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);"); |
57 | 57 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);"); |
58 | 58 | \array_unshift($captions, $ck); |
@@ -60,43 +60,43 @@ discard block |
||
60 | 60 | |
61 | 61 | $table->setRowCount(0, \sizeof($captions)); |
62 | 62 | $table->setHeaderValues($captions); |
63 | - if(isset($this->_compileParts)) |
|
63 | + if (isset($this->_compileParts)) |
|
64 | 64 | $table->setCompileParts($this->_compileParts); |
65 | - if(isset($this->_searchField)){ |
|
66 | - if(isset($js)) |
|
67 | - $this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
65 | + if (isset($this->_searchField)) { |
|
66 | + if (isset($js)) |
|
67 | + $this->_searchField->postOn("change", $this->_urls, "{'s':$(this).val()}", "-#".$this->identifier." tbody", ["preventDefault"=>false]); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $this->_generateContent($table); |
71 | 71 | |
72 | - if($this->_hasCheckboxes){ |
|
73 | - if($table->hasPart("thead")) |
|
74 | - $table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort"); |
|
72 | + if ($this->_hasCheckboxes) { |
|
73 | + if ($table->hasPart("thead")) |
|
74 | + $table->getHeader()->getCell(0, 0)->addToProperty("class", "no-sort"); |
|
75 | 75 | } |
76 | 76 | |
77 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
77 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
78 | 78 | $this->_generatePagination($table); |
79 | 79 | } |
80 | - if(isset($this->_toolbar)){ |
|
80 | + if (isset($this->_toolbar)) { |
|
81 | 81 | $this->_setToolbarPosition($table, $captions); |
82 | 82 | } |
83 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
84 | - return parent::compile($js,$view); |
|
83 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
84 | + return parent::compile($js, $view); |
|
85 | 85 | } |
86 | 86 | |
87 | - private function _generateContent($table){ |
|
87 | + private function _generateContent($table) { |
|
88 | 88 | $objects=$this->_modelInstance; |
89 | - if(isset($this->_pagination)){ |
|
89 | + if (isset($this->_pagination)) { |
|
90 | 90 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
91 | 91 | } |
92 | 92 | InstanceViewer::setIndex(0); |
93 | - $table->fromDatabaseObjects($objects, function($instance){ |
|
93 | + $table->fromDatabaseObjects($objects, function($instance) { |
|
94 | 94 | $this->_instanceViewer->setInstance($instance); |
95 | - $result= $this->_instanceViewer->getValues(); |
|
96 | - if($this->_hasCheckboxes){ |
|
97 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
95 | + $result=$this->_instanceViewer->getValues(); |
|
96 | + if ($this->_hasCheckboxes) { |
|
97 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
98 | 98 | $field=$ck->getField(); |
99 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
99 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
100 | 100 | $field->setProperty("name", "selection[]"); |
101 | 101 | \array_unshift($result, $ck); |
102 | 102 | } |
@@ -104,25 +104,25 @@ discard block |
||
104 | 104 | }); |
105 | 105 | } |
106 | 106 | |
107 | - private function _generatePagination($table){ |
|
107 | + private function _generatePagination($table) { |
|
108 | 108 | $footer=$table->getFooter(); |
109 | 109 | $footer->mergeCol(); |
110 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
110 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
111 | 111 | $menu->floatRight(); |
112 | 112 | $menu->setActiveItem($this->_pagination->getPage()-1); |
113 | 113 | $footer->setValues($menu); |
114 | - $menu->postOnClick($this->_urls,"{'p':$(this).attr('data-page')}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
114 | + $menu->postOnClick($this->_urls, "{'p':$(this).attr('data-page')}", "-#".$this->identifier." tbody", ["preventDefault"=>false]); |
|
115 | 115 | } |
116 | 116 | |
117 | - private function _setToolbarPosition($table,$captions){ |
|
118 | - switch ($this->_toolbarPosition){ |
|
117 | + private function _setToolbarPosition($table, $captions) { |
|
118 | + switch ($this->_toolbarPosition) { |
|
119 | 119 | case PositionInTable::BEFORETABLE:case PositionInTable::AFTERTABLE: |
120 | - if(isset($this->_compileParts)===false){ |
|
120 | + if (isset($this->_compileParts)===false) { |
|
121 | 121 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
122 | 122 | } |
123 | 123 | break; |
124 | 124 | case PositionInTable::HEADER:case PositionInTable::FOOTER: case PositionInTable::BODY: |
125 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
125 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
126 | 126 | break; |
127 | 127 | } |
128 | 128 | } |
@@ -134,12 +134,12 @@ discard block |
||
134 | 134 | * @param callable $callback function called after the field compilation |
135 | 135 | * @return \Ajax\semantic\widgets\datatable\DataTable |
136 | 136 | */ |
137 | - public function afterCompile($index,$callback){ |
|
138 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
137 | + public function afterCompile($index, $callback) { |
|
138 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
139 | 139 | return $this; |
140 | 140 | } |
141 | 141 | |
142 | - private function addToolbarRow($part,$table,$captions){ |
|
142 | + private function addToolbarRow($part, $table, $captions) { |
|
143 | 143 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
144 | 144 | $row->mergeCol(); |
145 | 145 | $row->setValues([$this->_toolbar]); |
@@ -154,42 +154,42 @@ discard block |
||
154 | 154 | return $this; |
155 | 155 | } |
156 | 156 | |
157 | - public function setCaptions($captions){ |
|
157 | + public function setCaptions($captions) { |
|
158 | 158 | $this->_instanceViewer->setCaptions($captions); |
159 | 159 | return $this; |
160 | 160 | } |
161 | 161 | |
162 | - public function setFields($fields){ |
|
162 | + public function setFields($fields) { |
|
163 | 163 | $this->_instanceViewer->setVisibleProperties($fields); |
164 | 164 | return $this; |
165 | 165 | } |
166 | 166 | |
167 | - public function addField($field){ |
|
167 | + public function addField($field) { |
|
168 | 168 | $this->_instanceViewer->addField($field); |
169 | 169 | return $this; |
170 | 170 | } |
171 | 171 | |
172 | - public function insertField($index,$field){ |
|
172 | + public function insertField($index, $field) { |
|
173 | 173 | $this->_instanceViewer->insertField($index, $field); |
174 | 174 | return $this; |
175 | 175 | } |
176 | 176 | |
177 | - public function insertInField($index,$field){ |
|
177 | + public function insertInField($index, $field) { |
|
178 | 178 | $this->_instanceViewer->insertInField($index, $field); |
179 | 179 | return $this; |
180 | 180 | } |
181 | 181 | |
182 | - public function setValueFunction($index,$callback){ |
|
182 | + public function setValueFunction($index, $callback) { |
|
183 | 183 | $this->_instanceViewer->setValueFunction($index, $callback); |
184 | 184 | return $this; |
185 | 185 | } |
186 | 186 | |
187 | - public function setIdentifierFunction($callback){ |
|
187 | + public function setIdentifierFunction($callback) { |
|
188 | 188 | $this->_instanceViewer->setIdentifierFunction($callback); |
189 | 189 | return $this; |
190 | 190 | } |
191 | 191 | |
192 | - public function getHtmlComponent(){ |
|
192 | + public function getHtmlComponent() { |
|
193 | 193 | return $this->content["table"]; |
194 | 194 | } |
195 | 195 | |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | return $this; |
203 | 203 | } |
204 | 204 | |
205 | - public function paginate($items_per_page=10,$page=1){ |
|
206 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
205 | + public function paginate($items_per_page=10, $page=1) { |
|
206 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | public function getHasCheckboxes() { |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | return $this; |
216 | 216 | } |
217 | 217 | |
218 | - public function refresh($compileParts=["tbody"]){ |
|
218 | + public function refresh($compileParts=["tbody"]) { |
|
219 | 219 | $this->_compileParts=$compileParts; |
220 | 220 | return $this; |
221 | 221 | } |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param callable $callback |
225 | 225 | * @return callable |
226 | 226 | */ |
227 | - private function getFieldButtonCallable($caption,$callback=null){ |
|
228 | - return $this->getCallable($this->getFieldButton($caption),$callback); |
|
227 | + private function getFieldButtonCallable($caption, $callback=null) { |
|
228 | + return $this->getCallable($this->getFieldButton($caption), $callback); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | * @param callable $callback |
234 | 234 | * @return callable |
235 | 235 | */ |
236 | - private function getCallable($object,$callback=null){ |
|
237 | - $result=function($instance) use($object,$callback){ |
|
238 | - if(isset($callback)){ |
|
239 | - if(\is_callable($callback)){ |
|
240 | - $callback($object,$instance); |
|
236 | + private function getCallable($object, $callback=null) { |
|
237 | + $result=function($instance) use($object, $callback){ |
|
238 | + if (isset($callback)) { |
|
239 | + if (\is_callable($callback)) { |
|
240 | + $callback($object, $instance); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | return $object; |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @param string $caption |
250 | 250 | * @return HtmlButton |
251 | 251 | */ |
252 | - private function getFieldButton($caption){ |
|
253 | - $bt=new HtmlButton("",$caption); |
|
254 | - $bt->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
252 | + private function getFieldButton($caption) { |
|
253 | + $bt=new HtmlButton("", $caption); |
|
254 | + $bt->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
255 | 255 | return $bt; |
256 | 256 | } |
257 | 257 | |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * @param callable $callback |
262 | 262 | * @return \Ajax\semantic\widgets\datatable\DataTable |
263 | 263 | */ |
264 | - public function addFieldButton($caption,$callback=null){ |
|
265 | - $this->addField($this->getFieldButtonCallable($caption,$callback)); |
|
264 | + public function addFieldButton($caption, $callback=null) { |
|
265 | + $this->addField($this->getFieldButtonCallable($caption, $callback)); |
|
266 | 266 | return $this; |
267 | 267 | } |
268 | 268 | |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | * @param callable $callback |
274 | 274 | * @return \Ajax\semantic\widgets\datatable\DataTable |
275 | 275 | */ |
276 | - public function insertFieldButton($index,$caption,$callback=null){ |
|
277 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$callback)); |
|
276 | + public function insertFieldButton($index, $caption, $callback=null) { |
|
277 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $callback)); |
|
278 | 278 | return $this; |
279 | 279 | } |
280 | 280 | |
@@ -285,55 +285,55 @@ discard block |
||
285 | 285 | * @param callable $callback |
286 | 286 | * @return \Ajax\semantic\widgets\datatable\DataTable |
287 | 287 | */ |
288 | - public function insertInFieldButton($index,$caption,$callback=null){ |
|
289 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$callback)); |
|
288 | + public function insertInFieldButton($index, $caption, $callback=null) { |
|
289 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $callback)); |
|
290 | 290 | return $this; |
291 | 291 | } |
292 | 292 | |
293 | - private function addDefaultButton($icon,$class=null,$callback=null){ |
|
294 | - $bt=$this->getDefaultButton($icon,$class); |
|
295 | - $this->addField($this->getCallable($bt,$callback)); |
|
293 | + private function addDefaultButton($icon, $class=null, $callback=null) { |
|
294 | + $bt=$this->getDefaultButton($icon, $class); |
|
295 | + $this->addField($this->getCallable($bt, $callback)); |
|
296 | 296 | return $this; |
297 | 297 | } |
298 | 298 | |
299 | - private function insertDefaultButtonIn($index,$icon,$class=null,$callback=null){ |
|
300 | - $bt=$this->getDefaultButton($icon,$class); |
|
301 | - $this->insertInField($index,$this->getCallable($bt,$callback)); |
|
299 | + private function insertDefaultButtonIn($index, $icon, $class=null, $callback=null) { |
|
300 | + $bt=$this->getDefaultButton($icon, $class); |
|
301 | + $this->insertInField($index, $this->getCallable($bt, $callback)); |
|
302 | 302 | return $this; |
303 | 303 | } |
304 | 304 | |
305 | - private function getDefaultButton($icon,$class=null){ |
|
305 | + private function getDefaultButton($icon, $class=null) { |
|
306 | 306 | $bt=$this->getFieldButton(""); |
307 | 307 | $bt->asIcon($icon); |
308 | - if(isset($class)) |
|
308 | + if (isset($class)) |
|
309 | 309 | $bt->addToProperty("class", $class); |
310 | 310 | return $bt; |
311 | 311 | } |
312 | 312 | |
313 | - public function addDeleteButton($callback=null){ |
|
314 | - return $this->addDefaultButton("remove","delete red basic",$callback); |
|
313 | + public function addDeleteButton($callback=null) { |
|
314 | + return $this->addDefaultButton("remove", "delete red basic", $callback); |
|
315 | 315 | } |
316 | 316 | |
317 | - public function addEditButton($callback=null){ |
|
318 | - return $this->addDefaultButton("edit","edit basic",$callback); |
|
317 | + public function addEditButton($callback=null) { |
|
318 | + return $this->addDefaultButton("edit", "edit basic", $callback); |
|
319 | 319 | } |
320 | 320 | |
321 | - public function addEditDeleteButtons($callbackEdit=null,$callbackDelete=null){ |
|
321 | + public function addEditDeleteButtons($callbackEdit=null, $callbackDelete=null) { |
|
322 | 322 | $this->addEditButton($callbackEdit); |
323 | 323 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
324 | - $this->insertDeleteButtonIn($index,$callbackDelete); |
|
324 | + $this->insertDeleteButtonIn($index, $callbackDelete); |
|
325 | 325 | return $this; |
326 | 326 | } |
327 | 327 | |
328 | - public function insertDeleteButtonIn($index,$callback=null){ |
|
329 | - return $this->insertDefaultButtonIn($index,"remove","delete red basic",$callback); |
|
328 | + public function insertDeleteButtonIn($index, $callback=null) { |
|
329 | + return $this->insertDefaultButtonIn($index, "remove", "delete red basic", $callback); |
|
330 | 330 | } |
331 | 331 | |
332 | - public function insertEditButtonIn($index,$callback=null){ |
|
333 | - return $this->insertDefaultButtonIn($index,"edit","edit basic",$callback); |
|
332 | + public function insertEditButtonIn($index, $callback=null) { |
|
333 | + return $this->insertDefaultButtonIn($index, "edit", "edit basic", $callback); |
|
334 | 334 | } |
335 | 335 | |
336 | - public function setSelectable(){ |
|
336 | + public function setSelectable() { |
|
337 | 337 | $this->content["table"]->setSelectable(); |
338 | 338 | return $this; |
339 | 339 | } |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | /** |
342 | 342 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
343 | 343 | */ |
344 | - public function getToolbar(){ |
|
345 | - if(isset($this->_toolbar)===false){ |
|
344 | + public function getToolbar() { |
|
345 | + if (isset($this->_toolbar)===false) { |
|
346 | 346 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
347 | 347 | $this->_toolbar->setSecondary(); |
348 | 348 | } |
@@ -353,37 +353,37 @@ discard block |
||
353 | 353 | * @param unknown $element |
354 | 354 | * @return \Ajax\common\html\HtmlDoubleElement |
355 | 355 | */ |
356 | - public function addInToolbar($element){ |
|
356 | + public function addInToolbar($element) { |
|
357 | 357 | $tb=$this->getToolbar(); |
358 | 358 | return $tb->addItem($element); |
359 | 359 | } |
360 | 360 | |
361 | - public function addItemInToolbar($caption,$icon=NULL){ |
|
361 | + public function addItemInToolbar($caption, $icon=NULL) { |
|
362 | 362 | $result=$this->addInToolbar($caption); |
363 | 363 | $result->addIcon($icon); |
364 | 364 | return $result; |
365 | 365 | } |
366 | 366 | |
367 | - public function addButtonInToolbar($caption){ |
|
368 | - $bt=new HtmlButton("",$caption); |
|
367 | + public function addButtonInToolbar($caption) { |
|
368 | + $bt=new HtmlButton("", $caption); |
|
369 | 369 | return $this->addInToolbar($bt); |
370 | 370 | } |
371 | 371 | |
372 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
373 | - $bt=new HtmlButton("",$caption); |
|
374 | - $bt->addIcon($icon,$before,$labeled); |
|
372 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
373 | + $bt=new HtmlButton("", $caption); |
|
374 | + $bt->addIcon($icon, $before, $labeled); |
|
375 | 375 | return $this->addInToolbar($bt); |
376 | 376 | } |
377 | 377 | |
378 | 378 | |
379 | - public function addSearchInToolbar(){ |
|
379 | + public function addSearchInToolbar() { |
|
380 | 380 | return $this->addInToolbar($this->getSearchField())->setPosition("right"); |
381 | 381 | } |
382 | 382 | |
383 | - public function getSearchField(){ |
|
384 | - if(isset($this->_searchField)===false){ |
|
385 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
386 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
383 | + public function getSearchField() { |
|
384 | + if (isset($this->_searchField)===false) { |
|
385 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
386 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
387 | 387 | } |
388 | 388 | return $this->_searchField; |
389 | 389 | } |
@@ -393,36 +393,36 @@ discard block |
||
393 | 393 | return $this; |
394 | 394 | } |
395 | 395 | |
396 | - public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
|
397 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
398 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
396 | + public function fieldAsImage($index, $size=Size::SMALL, $circular=false) { |
|
397 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
398 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
399 | 399 | return $image; |
400 | 400 | } |
401 | 401 | ); |
402 | 402 | return $this; |
403 | 403 | } |
404 | 404 | |
405 | - public function fieldAsAvatar($index){ |
|
406 | - $this->setValueFunction($index,function($img){return (new HtmlImage("",$img))->asAvatar();}); |
|
405 | + public function fieldAsAvatar($index) { |
|
406 | + $this->setValueFunction($index, function($img) {return (new HtmlImage("", $img))->asAvatar(); }); |
|
407 | 407 | return $this; |
408 | 408 | } |
409 | 409 | |
410 | - public function fieldAsRadio($index,$name=NULL){ |
|
411 | - $this->setValueFunction($index,function($value)use ($index,$name){ |
|
412 | - if(isset($name)===false){ |
|
410 | + public function fieldAsRadio($index, $name=NULL) { |
|
411 | + $this->setValueFunction($index, function($value)use ($index, $name){ |
|
412 | + if (isset($name)===false) { |
|
413 | 413 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
414 | 414 | } |
415 | - $radio=new HtmlRadio($this->_getFieldIdentifier("radio"),$name,$value,$value); |
|
415 | + $radio=new HtmlRadio($this->_getFieldIdentifier("radio"), $name, $value, $value); |
|
416 | 416 | return $radio; |
417 | 417 | } |
418 | 418 | ); |
419 | 419 | return $this; |
420 | 420 | } |
421 | 421 | |
422 | - public function fieldAsInput($index,$name=NULL,$type="text",$placeholder=""){ |
|
423 | - $this->setValueFunction($index,function($value) use($index,$name,$type,$placeholder){ |
|
424 | - $input=new HtmlInput($this->_getFieldIdentifier("input"),$type,$value,$placeholder); |
|
425 | - if(isset($name)===false){ |
|
422 | + public function fieldAsInput($index, $name=NULL, $type="text", $placeholder="") { |
|
423 | + $this->setValueFunction($index, function($value) use($index, $name, $type, $placeholder){ |
|
424 | + $input=new HtmlInput($this->_getFieldIdentifier("input"), $type, $value, $placeholder); |
|
425 | + if (isset($name)===false) { |
|
426 | 426 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
427 | 427 | } |
428 | 428 | $input->getField()->setProperty("name", $name); |
@@ -433,32 +433,32 @@ discard block |
||
433 | 433 | return $this; |
434 | 434 | } |
435 | 435 | |
436 | - public function fieldAsCheckbox($index,$name=NULL){ |
|
437 | - $this->setValueFunction($index,function($value) use($index,$name){ |
|
438 | - $checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"),"",$value); |
|
436 | + public function fieldAsCheckbox($index, $name=NULL) { |
|
437 | + $this->setValueFunction($index, function($value) use($index, $name){ |
|
438 | + $checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"), "", $value); |
|
439 | 439 | $checkbox->setChecked(JString::isBooleanTrue($value)); |
440 | - if(isset($name)===false){ |
|
440 | + if (isset($name)===false) { |
|
441 | 441 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
442 | 442 | } |
443 | 443 | $checkbox->getField()->setProperty("name", $name); |
444 | - return $checkbox;} |
|
444 | + return $checkbox; } |
|
445 | 445 | ); |
446 | 446 | return $this; |
447 | 447 | } |
448 | 448 | |
449 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$name=NULL){ |
|
450 | - $this->setValueFunction($index,function($value) use($index,$elements,$multiple,$name){ |
|
451 | - $dd=new HtmlDropdown($this->_getFieldIdentifier("dd"),$value,$elements); |
|
452 | - if(isset($name)===false){ |
|
449 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $name=NULL) { |
|
450 | + $this->setValueFunction($index, function($value) use($index, $elements, $multiple, $name){ |
|
451 | + $dd=new HtmlDropdown($this->_getFieldIdentifier("dd"), $value, $elements); |
|
452 | + if (isset($name)===false) { |
|
453 | 453 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
454 | 454 | } |
455 | - $dd->asSelect($name,$multiple); |
|
456 | - return $dd;} |
|
455 | + $dd->asSelect($name, $multiple); |
|
456 | + return $dd; } |
|
457 | 457 | ); |
458 | 458 | return $this; |
459 | 459 | } |
460 | 460 | |
461 | - private function _getFieldIdentifier($prefix){ |
|
461 | + private function _getFieldIdentifier($prefix) { |
|
462 | 462 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
463 | 463 | } |
464 | 464 | } |
465 | 465 | \ No newline at end of file |
@@ -2,33 +2,33 @@ |
||
2 | 2 | namespace Ajax\service; |
3 | 3 | class JString { |
4 | 4 | |
5 | - public static function contains($hay,$needle){ |
|
6 | - return strpos($hay, $needle) !== false; |
|
5 | + public static function contains($hay, $needle) { |
|
6 | + return strpos($hay, $needle)!==false; |
|
7 | 7 | } |
8 | 8 | public static function startswith($hay, $needle) { |
9 | - return substr($hay, 0, strlen($needle)) === $needle; |
|
9 | + return substr($hay, 0, strlen($needle))===$needle; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public static function endswith($hay, $needle) { |
13 | - return substr($hay, -strlen($needle)) === $needle; |
|
13 | + return substr($hay, -strlen($needle))===$needle; |
|
14 | 14 | } |
15 | 15 | |
16 | - public static function isNull($s){ |
|
16 | + public static function isNull($s) { |
|
17 | 17 | return (!isset($s) || NULL===$s || ""===$s); |
18 | 18 | } |
19 | - public static function isNotNull($s){ |
|
19 | + public static function isNotNull($s) { |
|
20 | 20 | return (isset($s) && NULL!==$s && ""!==$s); |
21 | 21 | } |
22 | 22 | |
23 | - public static function isBoolean($value){ |
|
23 | + public static function isBoolean($value) { |
|
24 | 24 | return \is_bool($value) || $value==1 || $value==0; |
25 | 25 | } |
26 | 26 | |
27 | - public static function isBooleanTrue($value){ |
|
27 | + public static function isBooleanTrue($value) { |
|
28 | 28 | return $value==1 || $value; |
29 | 29 | } |
30 | 30 | |
31 | - public static function isBooleanFalse($value){ |
|
31 | + public static function isBooleanFalse($value) { |
|
32 | 32 | return $value==0 || !$value; |
33 | 33 | } |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -12,25 +12,25 @@ discard block |
||
12 | 12 | private $afterCompile; |
13 | 13 | private static $index=0; |
14 | 14 | |
15 | - public function __construct($instance=NULL,$captions=NULL){ |
|
15 | + public function __construct($instance=NULL, $captions=NULL) { |
|
16 | 16 | $this->values=[]; |
17 | 17 | $this->afterCompile=[]; |
18 | - if(isset($instance)) |
|
18 | + if (isset($instance)) |
|
19 | 19 | $this->setInstance($instance); |
20 | 20 | $this->setCaptions($captions); |
21 | 21 | } |
22 | 22 | |
23 | - public function getCaption($index){ |
|
24 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
23 | + public function getCaption($index) { |
|
24 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
25 | 25 | return $this->properties[$index]->getName(); |
26 | 26 | else |
27 | 27 | return $this->properties[$index]; |
28 | 28 | } |
29 | 29 | |
30 | - public function getCaptions(){ |
|
31 | - if(isset($this->captions)){ |
|
32 | - $result= $this->captions; |
|
33 | - for($i=\sizeof($result);$i<$this->count();$i++){ |
|
30 | + public function getCaptions() { |
|
31 | + if (isset($this->captions)) { |
|
32 | + $result=$this->captions; |
|
33 | + for ($i=\sizeof($result); $i<$this->count(); $i++) { |
|
34 | 34 | $result[]=""; |
35 | 35 | } |
36 | 36 | return $result; |
@@ -38,122 +38,122 @@ discard block |
||
38 | 38 | $captions=[]; |
39 | 39 | $index=0; |
40 | 40 | $count=$this->count(); |
41 | - while($index<$count){ |
|
41 | + while ($index<$count) { |
|
42 | 42 | $captions[]=$this->getCaption($index++); |
43 | 43 | } |
44 | 44 | return $captions; |
45 | 45 | } |
46 | 46 | |
47 | - public function getValues(){ |
|
47 | + public function getValues() { |
|
48 | 48 | $values=[]; |
49 | 49 | $index=0; |
50 | 50 | $count=$this->count(); |
51 | - while($index<$count){ |
|
51 | + while ($index<$count) { |
|
52 | 52 | $values[]=$this->getValue($index++); |
53 | 53 | } |
54 | 54 | return $values; |
55 | 55 | } |
56 | 56 | |
57 | - public function getIdentifier(){ |
|
57 | + public function getIdentifier() { |
|
58 | 58 | $value=self::$index; |
59 | - if(isset($this->values["identifier"])) |
|
60 | - $value=$this->values["identifier"](self::$index,$this->instance); |
|
59 | + if (isset($this->values["identifier"])) |
|
60 | + $value=$this->values["identifier"](self::$index, $this->instance); |
|
61 | 61 | self::$index++; |
62 | 62 | return $value; |
63 | 63 | } |
64 | 64 | |
65 | - public function getValue($index){ |
|
65 | + public function getValue($index) { |
|
66 | 66 | $property=$this->properties[$index]; |
67 | 67 | return $this->_getValue($property, $index); |
68 | 68 | } |
69 | 69 | |
70 | - private function _getValue($property,$index){ |
|
71 | - if($property instanceof \ReflectionProperty){ |
|
70 | + private function _getValue($property, $index) { |
|
71 | + if ($property instanceof \ReflectionProperty) { |
|
72 | 72 | $property->setAccessible(true); |
73 | 73 | $value=$property->getValue($this->instance); |
74 | - if(isset($this->values[$index])){ |
|
75 | - $value= $this->values[$index]($value); |
|
74 | + if (isset($this->values[$index])) { |
|
75 | + $value=$this->values[$index]($value); |
|
76 | 76 | } |
77 | - }else{ |
|
78 | - if(\is_callable($property)) |
|
77 | + } else { |
|
78 | + if (\is_callable($property)) |
|
79 | 79 | $value=$property($this->instance); |
80 | - elseif(\is_array($property)){ |
|
81 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
80 | + elseif (\is_array($property)) { |
|
81 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
82 | 82 | $value=\implode("", $values); |
83 | - }else |
|
83 | + } else |
|
84 | 84 | $value=$property; |
85 | 85 | } |
86 | - if(isset($this->afterCompile[$index])){ |
|
87 | - if(\is_callable($this->afterCompile[$index])){ |
|
88 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
86 | + if (isset($this->afterCompile[$index])) { |
|
87 | + if (\is_callable($this->afterCompile[$index])) { |
|
88 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | return $value; |
92 | 92 | } |
93 | 93 | |
94 | - public function insertField($index,$field){ |
|
95 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
94 | + public function insertField($index, $field) { |
|
95 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
96 | 96 | return $this; |
97 | 97 | } |
98 | 98 | |
99 | - public function insertInField($index,$field){ |
|
99 | + public function insertInField($index, $field) { |
|
100 | 100 | $vb=$this->visibleProperties; |
101 | - if(isset($vb[$index])){ |
|
102 | - if(\is_array($vb[$index])){ |
|
101 | + if (isset($vb[$index])) { |
|
102 | + if (\is_array($vb[$index])) { |
|
103 | 103 | $this->visibleProperties[$index][]=$field; |
104 | - }else{ |
|
105 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
104 | + } else { |
|
105 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
106 | 106 | } |
107 | - }else{ |
|
107 | + } else { |
|
108 | 108 | return $this->insertField($index, $field); |
109 | 109 | } |
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - public function addField($field){ |
|
113 | + public function addField($field) { |
|
114 | 114 | $this->visibleProperties[]=$field; |
115 | 115 | return $this; |
116 | 116 | } |
117 | 117 | |
118 | - public function count(){ |
|
118 | + public function count() { |
|
119 | 119 | return \sizeof($this->properties); |
120 | 120 | } |
121 | 121 | |
122 | - public function visiblePropertiesCount(){ |
|
122 | + public function visiblePropertiesCount() { |
|
123 | 123 | return \sizeof($this->visibleProperties); |
124 | 124 | } |
125 | 125 | |
126 | - private function showableProperty(\ReflectionProperty $rProperty){ |
|
127 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
126 | + private function showableProperty(\ReflectionProperty $rProperty) { |
|
127 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | public function setInstance($instance) { |
131 | - if(\is_string($instance)){ |
|
131 | + if (\is_string($instance)) { |
|
132 | 132 | $instance=new $instance(); |
133 | 133 | } |
134 | 134 | $this->instance=$instance; |
135 | 135 | $this->properties=[]; |
136 | 136 | $this->reflect=new \ReflectionClass($instance); |
137 | - if(\sizeof($this->visibleProperties)===0){ |
|
137 | + if (\sizeof($this->visibleProperties)===0) { |
|
138 | 138 | $this->properties=$this->getDefaultProperties(); |
139 | - }else{ |
|
140 | - foreach ($this->visibleProperties as $property){ |
|
141 | - if(\is_callable($property)){ |
|
139 | + } else { |
|
140 | + foreach ($this->visibleProperties as $property) { |
|
141 | + if (\is_callable($property)) { |
|
142 | 142 | $this->properties[]=$property; |
143 | - }elseif(\is_string($property)){ |
|
144 | - try{ |
|
143 | + }elseif (\is_string($property)) { |
|
144 | + try { |
|
145 | 145 | $rProperty=$this->reflect->getProperty($property); |
146 | 146 | $this->properties[]=$rProperty; |
147 | - }catch(\Exception $e){ |
|
147 | + }catch (\Exception $e) { |
|
148 | 148 | $this->properties[]=$property; |
149 | 149 | } |
150 | - }elseif(\is_int($property)){ |
|
150 | + }elseif (\is_int($property)) { |
|
151 | 151 | $props=$this->getDefaultProperties(); |
152 | - if(isset($props[$property])) |
|
152 | + if (isset($props[$property])) |
|
153 | 153 | $this->properties[]=$props[$property]; |
154 | 154 | else |
155 | 155 | $this->properties[]=$property; |
156 | - }else{ |
|
156 | + } else { |
|
157 | 157 | $this->properties[]=$property; |
158 | 158 | } |
159 | 159 | } |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | return $this; |
162 | 162 | } |
163 | 163 | |
164 | - private function getDefaultProperties(){ |
|
164 | + private function getDefaultProperties() { |
|
165 | 165 | $result=[]; |
166 | 166 | $properties=$this->reflect->getProperties(); |
167 | - foreach ($properties as $property){ |
|
167 | + foreach ($properties as $property) { |
|
168 | 168 | $showable=$this->showableProperty($property); |
169 | - if($showable!==false){ |
|
169 | + if ($showable!==false) { |
|
170 | 170 | $result[]=$property; |
171 | 171 | } |
172 | 172 | } |
@@ -183,12 +183,12 @@ discard block |
||
183 | 183 | return $this; |
184 | 184 | } |
185 | 185 | |
186 | - public function setValueFunction($index,$callback){ |
|
186 | + public function setValueFunction($index, $callback) { |
|
187 | 187 | $this->values[$index]=$callback; |
188 | 188 | return $this; |
189 | 189 | } |
190 | 190 | |
191 | - public function setIdentifierFunction($callback){ |
|
191 | + public function setIdentifierFunction($callback) { |
|
192 | 192 | $this->values["identifier"]=$callback; |
193 | 193 | return $this; |
194 | 194 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param callable $callback function called after the field compilation |
209 | 209 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
210 | 210 | */ |
211 | - public function afterCompile($index,$callback){ |
|
211 | + public function afterCompile($index, $callback) { |
|
212 | 212 | $this->afterCompile[$index]=$callback; |
213 | 213 | return $this; |
214 | 214 | } |
@@ -3,5 +3,5 @@ |
||
3 | 3 | use Ajax\common\BaseEnum; |
4 | 4 | |
5 | 5 | abstract class PositionInTable extends BaseEnum { |
6 | - const BEFORETABLE="beforeTable",AFTERTABLE="afterTable",HEADER="thead",FOOTER="tfoot",BODY="tbody"; |
|
6 | + const BEFORETABLE="beforeTable", AFTERTABLE="afterTable", HEADER="thead", FOOTER="tfoot", BODY="tbody"; |
|
7 | 7 | } |
8 | 8 | \ No newline at end of file |