@@ -15,29 +15,29 @@ discard block |
||
15 | 15 | use Ajax\common\html\HtmlDoubleElement; |
16 | 16 | |
17 | 17 | class HtmlDropdown extends HtmlSemDoubleElement { |
18 | - use FieldTrait,LabeledIconTrait { |
|
18 | + use FieldTrait, LabeledIconTrait { |
|
19 | 19 | addIcon as addIconP; |
20 | 20 | } |
21 | 21 | protected $mClass="menu"; |
22 | 22 | protected $mTagName="div"; |
23 | - protected $items=array (); |
|
24 | - protected $_params=array("action"=>"nothing","on"=>"hover","showOnFocus"=>false); |
|
23 | + protected $items=array(); |
|
24 | + protected $_params=array("action"=>"nothing", "on"=>"hover", "showOnFocus"=>false); |
|
25 | 25 | protected $input; |
26 | 26 | protected $value; |
27 | 27 | protected $_associative; |
28 | 28 | protected $_multiple; |
29 | 29 | |
30 | - public function __construct($identifier, $value="", $items=array(),$associative=true) { |
|
30 | + public function __construct($identifier, $value="", $items=array(), $associative=true) { |
|
31 | 31 | parent::__construct($identifier, "div"); |
32 | 32 | $this->_template=include dirname(__FILE__).'/../templates/tplDropdown.php'; |
33 | 33 | $this->setProperty("class", "ui dropdown"); |
34 | 34 | $this->_multiple=false; |
35 | 35 | $content=[]; |
36 | - if(isset($value)){ |
|
37 | - if($value instanceof HtmlSemDoubleElement){ |
|
36 | + if (isset($value)) { |
|
37 | + if ($value instanceof HtmlSemDoubleElement) { |
|
38 | 38 | $text=$value; |
39 | - }else{ |
|
40 | - $text=new HtmlSemDoubleElement("text-".$this->identifier,"div"); |
|
39 | + } else { |
|
40 | + $text=new HtmlSemDoubleElement("text-".$this->identifier, "div"); |
|
41 | 41 | $text->setClass("text"); |
42 | 42 | $this->setValue($value); |
43 | 43 | } |
@@ -50,29 +50,29 @@ discard block |
||
50 | 50 | $this->addItems($items); |
51 | 51 | } |
52 | 52 | |
53 | - public function getField(){ |
|
53 | + public function getField() { |
|
54 | 54 | return $this->input; |
55 | 55 | } |
56 | 56 | |
57 | - public function getDataField(){ |
|
57 | + public function getDataField() { |
|
58 | 58 | return $this->input; |
59 | 59 | } |
60 | 60 | |
61 | - public function addItem($item,$value=NULL,$image=NULL,$description=NULL){ |
|
62 | - $itemO=$this->beforeAddItem($item,$value,$image,$description); |
|
61 | + public function addItem($item, $value=NULL, $image=NULL, $description=NULL) { |
|
62 | + $itemO=$this->beforeAddItem($item, $value, $image, $description); |
|
63 | 63 | $this->items[]=$itemO; |
64 | 64 | return $itemO; |
65 | 65 | } |
66 | 66 | |
67 | - public function addIcon($icon,$before=true,$labeled=false){ |
|
67 | + public function addIcon($icon, $before=true, $labeled=false) { |
|
68 | 68 | $this->removeArrow(); |
69 | - $this->addIconP($icon,$before,$labeled); |
|
69 | + $this->addIconP($icon, $before, $labeled); |
|
70 | 70 | return $this->getElementById("text-".$this->identifier, $this->content)->setWrapAfter(""); |
71 | 71 | } |
72 | 72 | |
73 | - public function addIcons($icons){ |
|
73 | + public function addIcons($icons) { |
|
74 | 74 | $count=$this->count(); |
75 | - for ($i=0;$i<\sizeof($icons) && $i<$count;$i++){ |
|
75 | + for ($i=0; $i<\sizeof($icons) && $i<$count; $i++) { |
|
76 | 76 | $this->getItem($i)->addIcon($icons[$i]); |
77 | 77 | } |
78 | 78 | } |
@@ -83,33 +83,33 @@ discard block |
||
83 | 83 | * @param int $position |
84 | 84 | * @return HtmlDropdownItem |
85 | 85 | */ |
86 | - public function insertItem($item,$position=0){ |
|
86 | + public function insertItem($item, $position=0) { |
|
87 | 87 | $itemO=$this->beforeAddItem($item); |
88 | - $start = array_slice($this->items, 0, $position); |
|
89 | - $end = array_slice($this->items, $position); |
|
90 | - $start[] = $item; |
|
88 | + $start=array_slice($this->items, 0, $position); |
|
89 | + $end=array_slice($this->items, $position); |
|
90 | + $start[]=$item; |
|
91 | 91 | $this->items=array_merge($start, $end); |
92 | 92 | return $itemO; |
93 | 93 | } |
94 | 94 | |
95 | - protected function removeArrow(){ |
|
96 | - if(\sizeof($this->content)>1){ |
|
95 | + protected function removeArrow() { |
|
96 | + if (\sizeof($this->content)>1) { |
|
97 | 97 | unset($this->content["arrow"]); |
98 | 98 | $this->content=\array_values($this->content); |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - protected function beforeAddItem($item,$value=NULL,$image=NULL,$description=NULL){ |
|
102 | + protected function beforeAddItem($item, $value=NULL, $image=NULL, $description=NULL) { |
|
103 | 103 | $itemO=$item; |
104 | - if(\is_array($item)){ |
|
104 | + if (\is_array($item)) { |
|
105 | 105 | $description=JArray::getValue($item, "description", 3); |
106 | 106 | $value=JArray::getValue($item, "value", 1); |
107 | 107 | $image=JArray::getValue($item, "image", 2); |
108 | 108 | $item=JArray::getValue($item, "item", 0); |
109 | 109 | } |
110 | - if(!$item instanceof HtmlDropdownItem){ |
|
111 | - $itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items),$item,$value,$image,$description); |
|
112 | - }elseif($itemO instanceof HtmlDropdownItem){ |
|
110 | + if (!$item instanceof HtmlDropdownItem) { |
|
111 | + $itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items), $item, $value, $image, $description); |
|
112 | + }elseif ($itemO instanceof HtmlDropdownItem) { |
|
113 | 113 | $this->addToProperty("class", "vertical"); |
114 | 114 | } |
115 | 115 | return $itemO; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | $this->addItem($function($object)); |
123 | 123 | } |
124 | 124 | |
125 | - public function addInput($name){ |
|
126 | - if(!isset($name)) |
|
125 | + public function addInput($name) { |
|
126 | + if (!isset($name)) |
|
127 | 127 | $name="input-".$this->identifier; |
128 | 128 | $this->setAction("activate"); |
129 | - $this->input=new HtmlInput($name,"hidden"); |
|
129 | + $this->input=new HtmlInput($name, "hidden"); |
|
130 | 130 | $this->input->setIdentifier("input-".$this->identifier); |
131 | 131 | return $this->input; |
132 | 132 | } |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | * @param string $icon |
138 | 138 | * @return HtmlDropdownItem |
139 | 139 | */ |
140 | - public function addSearchInputItem($placeHolder=NULL,$icon=NULL){ |
|
141 | - return $this->addItem(HtmlDropdownItem::searchInput($placeHolder,$icon)); |
|
140 | + public function addSearchInputItem($placeHolder=NULL, $icon=NULL) { |
|
141 | + return $this->addItem(HtmlDropdownItem::searchInput($placeHolder, $icon)); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Adds a divider item |
146 | 146 | * @return HtmlDropdownItem |
147 | 147 | */ |
148 | - public function addDividerItem(){ |
|
148 | + public function addDividerItem() { |
|
149 | 149 | return $this->addItem(HtmlDropdownItem::divider()); |
150 | 150 | } |
151 | 151 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @param string $icon |
156 | 156 | * @return HtmlDropdownItem |
157 | 157 | */ |
158 | - public function addHeaderItem($caption=NULL,$icon=NULL){ |
|
159 | - return $this->addItem(HtmlDropdownItem::header($caption,$icon)); |
|
158 | + public function addHeaderItem($caption=NULL, $icon=NULL) { |
|
159 | + return $this->addItem(HtmlDropdownItem::header($caption, $icon)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param string $color |
166 | 166 | * @return HtmlDropdownItem |
167 | 167 | */ |
168 | - public function addCircularLabelItem($caption,$color){ |
|
168 | + public function addCircularLabelItem($caption, $color) { |
|
169 | 169 | return $this->addItem(HtmlDropdownItem::circular($caption, $color)); |
170 | 170 | } |
171 | 171 | |
@@ -174,17 +174,17 @@ discard block |
||
174 | 174 | * @param string $image |
175 | 175 | * @return \Ajax\semantic\html\content\HtmlDropdownItem |
176 | 176 | */ |
177 | - public function addMiniAvatarImageItem($caption,$image){ |
|
177 | + public function addMiniAvatarImageItem($caption, $image) { |
|
178 | 178 | return $this->addItem(HtmlDropdownItem::avatar($caption, $image)); |
179 | 179 | } |
180 | 180 | |
181 | - public function addItems($items){ |
|
182 | - if(\is_array($items) && $this->_associative){ |
|
183 | - foreach ($items as $k=>$v){ |
|
181 | + public function addItems($items) { |
|
182 | + if (\is_array($items) && $this->_associative) { |
|
183 | + foreach ($items as $k=>$v) { |
|
184 | 184 | $this->addItem($v)->setData($k); |
185 | 185 | } |
186 | - }else{ |
|
187 | - foreach ($items as $item){ |
|
186 | + } else { |
|
187 | + foreach ($items as $item) { |
|
188 | 188 | $this->addItem($item); |
189 | 189 | } |
190 | 190 | } |
@@ -196,98 +196,98 @@ discard block |
||
196 | 196 | * @param array|mixed $values |
197 | 197 | * @return $this |
198 | 198 | */ |
199 | - public function setPropertyValues($property,$values){ |
|
199 | + public function setPropertyValues($property, $values) { |
|
200 | 200 | $i=0; |
201 | - if(\is_array($values)===false){ |
|
202 | - $values=\array_fill(0, $this->count(),$values); |
|
201 | + if (\is_array($values)===false) { |
|
202 | + $values=\array_fill(0, $this->count(), $values); |
|
203 | 203 | } |
204 | - foreach ($values as $value){ |
|
204 | + foreach ($values as $value) { |
|
205 | 205 | $c=$this->items[$i++]; |
206 | - if(isset($c)){ |
|
207 | - $c->setProperty($property,$value); |
|
206 | + if (isset($c)) { |
|
207 | + $c->setProperty($property, $value); |
|
208 | 208 | } |
209 | - else{ |
|
209 | + else { |
|
210 | 210 | return $this; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | return $this; |
214 | 214 | } |
215 | 215 | |
216 | - public function each($callBack){ |
|
217 | - foreach ($this->items as $index=>$value){ |
|
218 | - $callBack($index,$value); |
|
216 | + public function each($callBack) { |
|
217 | + foreach ($this->items as $index=>$value) { |
|
218 | + $callBack($index, $value); |
|
219 | 219 | } |
220 | 220 | return $this; |
221 | 221 | } |
222 | 222 | |
223 | - public function getItem($index){ |
|
223 | + public function getItem($index) { |
|
224 | 224 | return $this->items[$index]; |
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
228 | 228 | * @return int |
229 | 229 | */ |
230 | - public function count(){ |
|
230 | + public function count() { |
|
231 | 231 | return \sizeof($this->items); |
232 | 232 | } |
233 | 233 | /** |
234 | 234 | * @param boolean $dropdown |
235 | 235 | */ |
236 | - public function asDropdown($dropdown){ |
|
237 | - if($dropdown===false){ |
|
236 | + public function asDropdown($dropdown) { |
|
237 | + if ($dropdown===false) { |
|
238 | 238 | $this->_template=include dirname(__FILE__).'/../templates/tplDropdownMenu.php'; |
239 | 239 | $dropdown="menu"; |
240 | - }else{ |
|
240 | + } else { |
|
241 | 241 | $dropdown="dropdown"; |
242 | 242 | $this->mClass="menu"; |
243 | 243 | } |
244 | - return $this->addToPropertyCtrl("class", $dropdown,array("menu","dropdown")); |
|
244 | + return $this->addToPropertyCtrl("class", $dropdown, array("menu", "dropdown")); |
|
245 | 245 | } |
246 | 246 | |
247 | - public function setVertical(){ |
|
248 | - return $this->addToPropertyCtrl("class", "vertical",array("vertical")); |
|
247 | + public function setVertical() { |
|
248 | + return $this->addToPropertyCtrl("class", "vertical", array("vertical")); |
|
249 | 249 | } |
250 | 250 | |
251 | - public function setInline(){ |
|
252 | - return $this->addToPropertyCtrl("class", "inline",["inline"]); |
|
251 | + public function setInline() { |
|
252 | + return $this->addToPropertyCtrl("class", "inline", ["inline"]); |
|
253 | 253 | } |
254 | 254 | |
255 | - public function setSimple(){ |
|
256 | - return $this->addToPropertyCtrl("class", "simple",array("simple")); |
|
255 | + public function setSimple() { |
|
256 | + return $this->addToPropertyCtrl("class", "simple", array("simple")); |
|
257 | 257 | } |
258 | 258 | |
259 | - public function asButton($floating=false){ |
|
259 | + public function asButton($floating=false) { |
|
260 | 260 | $this->removeArrow(); |
261 | - if($floating) |
|
261 | + if ($floating) |
|
262 | 262 | $this->addToProperty("class", "floating"); |
263 | 263 | $this->removePropertyValue("class", "selection"); |
264 | 264 | return $this->addToProperty("class", "button"); |
265 | 265 | } |
266 | 266 | |
267 | - public function asSelect($name=NULL,$multiple=false,$selection=true){ |
|
267 | + public function asSelect($name=NULL, $multiple=false, $selection=true) { |
|
268 | 268 | $this->_multiple=$multiple; |
269 | - if(isset($name)) |
|
269 | + if (isset($name)) |
|
270 | 270 | $this->addInput($name); |
271 | - if($multiple){ |
|
271 | + if ($multiple) { |
|
272 | 272 | $this->addToProperty("class", "multiple"); |
273 | 273 | } |
274 | - if ($selection){ |
|
275 | - if($this->propertyContains("class", "button")===false) |
|
276 | - $this->addToPropertyCtrl("class", "selection",array("selection")); |
|
274 | + if ($selection) { |
|
275 | + if ($this->propertyContains("class", "button")===false) |
|
276 | + $this->addToPropertyCtrl("class", "selection", array("selection")); |
|
277 | 277 | } |
278 | 278 | return $this; |
279 | 279 | } |
280 | 280 | |
281 | - public function asSearch($name=NULL,$multiple=false,$selection=true){ |
|
282 | - $this->asSelect($name,$multiple,$selection); |
|
281 | + public function asSearch($name=NULL, $multiple=false, $selection=true) { |
|
282 | + $this->asSelect($name, $multiple, $selection); |
|
283 | 283 | return $this->addToProperty("class", "search"); |
284 | 284 | } |
285 | 285 | |
286 | - public function setSelect($name=NULL,$multiple=false){ |
|
287 | - if(!isset($name)) |
|
286 | + public function setSelect($name=NULL, $multiple=false) { |
|
287 | + if (!isset($name)) |
|
288 | 288 | $name="select-".$this->identifier; |
289 | 289 | $this->input=null; |
290 | - if($multiple){ |
|
290 | + if ($multiple) { |
|
291 | 291 | $this->setProperty("multiple", true); |
292 | 292 | $this->addToProperty("class", "multiple"); |
293 | 293 | } |
@@ -295,37 +295,37 @@ discard block |
||
295 | 295 | $this->tagName="select"; |
296 | 296 | $this->setProperty("name", $name); |
297 | 297 | $this->content=null; |
298 | - foreach ($this->items as $item){ |
|
298 | + foreach ($this->items as $item) { |
|
299 | 299 | $item->asOption(); |
300 | 300 | } |
301 | 301 | return $this; |
302 | 302 | } |
303 | 303 | |
304 | - public function asSubmenu($pointing=NULL){ |
|
304 | + public function asSubmenu($pointing=NULL) { |
|
305 | 305 | $this->setClass("ui dropdown link item"); |
306 | - if(isset($pointing)){ |
|
306 | + if (isset($pointing)) { |
|
307 | 307 | $this->setPointing($pointing); |
308 | 308 | } |
309 | 309 | return $this; |
310 | 310 | } |
311 | 311 | |
312 | - public function setPointing($value=Direction::NONE){ |
|
313 | - return $this->addToPropertyCtrl("class", $value." pointing",Direction::getConstantValues("pointing")); |
|
312 | + public function setPointing($value=Direction::NONE) { |
|
313 | + return $this->addToPropertyCtrl("class", $value." pointing", Direction::getConstantValues("pointing")); |
|
314 | 314 | } |
315 | 315 | |
316 | - public function setValue($value){ |
|
316 | + public function setValue($value) { |
|
317 | 317 | $this->value=$value; |
318 | 318 | return $this; |
319 | 319 | } |
320 | - private function applyValue(){ |
|
320 | + private function applyValue() { |
|
321 | 321 | $value=$this->value; |
322 | - if(isset($this->input) && isset($value)){ |
|
322 | + if (isset($this->input) && isset($value)) { |
|
323 | 323 | $this->input->setProperty("value", $value); |
324 | - }else{ |
|
324 | + } else { |
|
325 | 325 | $this->setProperty("value", $value); |
326 | 326 | } |
327 | 327 | $textElement=$this->getElementById("text-".$this->identifier, $this->content); |
328 | - if(isset($textElement) && ($textElement instanceof HtmlDoubleElement) && !$this->_multiple) |
|
328 | + if (isset($textElement) && ($textElement instanceof HtmlDoubleElement) && !$this->_multiple) |
|
329 | 329 | $textElement->setContent($value); |
330 | 330 | return $this; |
331 | 331 | } |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | * @see BaseHtml::run() |
336 | 336 | */ |
337 | 337 | public function run(JsUtils $js) { |
338 | - if($this->propertyContains("class", "simple")===false){ |
|
339 | - if(isset($this->_bsComponent)===false){ |
|
340 | - $this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier,$this->_params); |
|
338 | + if ($this->propertyContains("class", "simple")===false) { |
|
339 | + if (isset($this->_bsComponent)===false) { |
|
340 | + $this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier, $this->_params); |
|
341 | 341 | $this->_bsComponent->setItemSelector(".item"); |
342 | 342 | } |
343 | 343 | $this->addEventsOnRun($js); |
@@ -345,41 +345,41 @@ discard block |
||
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | - public function setCompact(){ |
|
348 | + public function setCompact() { |
|
349 | 349 | return $this->addToPropertyCtrl("class", "compact", array("compact")); |
350 | 350 | } |
351 | 351 | |
352 | - public function setAction($action){ |
|
352 | + public function setAction($action) { |
|
353 | 353 | $this->_params["action"]=$action; |
354 | 354 | } |
355 | 355 | |
356 | - public function setOn($on){ |
|
356 | + public function setOn($on) { |
|
357 | 357 | $this->_params["on"]=$on; |
358 | 358 | } |
359 | 359 | |
360 | - public function setShowOnFocus($value){ |
|
360 | + public function setShowOnFocus($value) { |
|
361 | 361 | $this->_params["showOnFocus"]=$value; |
362 | 362 | } |
363 | 363 | |
364 | - public function setFullTextSearch($value){ |
|
364 | + public function setFullTextSearch($value) { |
|
365 | 365 | $this->_params["fullTextSearch"]=$value; |
366 | 366 | } |
367 | 367 | |
368 | 368 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
369 | 369 | $this->applyValue(); |
370 | - return parent::compile($js,$view); |
|
370 | + return parent::compile($js, $view); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | public function getInput() { |
374 | 374 | return $this->input; |
375 | 375 | } |
376 | 376 | |
377 | - public function setIcon($icon="dropdown"){ |
|
377 | + public function setIcon($icon="dropdown") { |
|
378 | 378 | $this->content["arrow"]=new HtmlIcon($this->identifier."-icon", $icon); |
379 | 379 | return $this; |
380 | 380 | } |
381 | 381 | |
382 | - public function jsAddItem($caption){ |
|
382 | + public function jsAddItem($caption) { |
|
383 | 383 | $js="var first=$('#{$this->identifier} .item').first();if(first!=undefined){var new =first.clone();first.parent().append(new);first.html('{$caption}};')"; |
384 | 384 | return $js; |
385 | 385 | } |
@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | * @property boolean $_visibleHover |
14 | 14 | * @property InstanceViewer $_instanceViewer |
15 | 15 | */ |
16 | -trait DataTableFieldAsTrait{ |
|
16 | +trait DataTableFieldAsTrait { |
|
17 | 17 | abstract public function addField($field); |
18 | - abstract public function insertField($index,$field); |
|
19 | - abstract public function insertInField($index,$field); |
|
20 | - abstract public function fieldAs($index,$type,$attributes=NULL); |
|
18 | + abstract public function insertField($index, $field); |
|
19 | + abstract public function insertInField($index, $field); |
|
20 | + abstract public function fieldAs($index, $type, $attributes=NULL); |
|
21 | 21 | abstract protected function cleanIdentifier($id); |
22 | - abstract protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null); |
|
22 | + abstract protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null); |
|
23 | 23 | /** |
24 | 24 | * @param string $caption |
25 | 25 | * @param callable $callback |
26 | 26 | * @param boolean $visibleHover |
27 | 27 | * @return callable |
28 | 28 | */ |
29 | - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
|
30 | - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
|
29 | + private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) { |
|
30 | + return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -36,20 +36,20 @@ discard block |
||
36 | 36 | * @param callable $callback |
37 | 37 | * @return callable |
38 | 38 | */ |
39 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
40 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
41 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
42 | - if(isset($callback)){ |
|
43 | - if(\is_callable($callback)){ |
|
44 | - $callback($object,$instance,$this->_instanceViewer->count()+1); |
|
39 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
40 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
41 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
42 | + if (isset($callback)) { |
|
43 | + if (\is_callable($callback)) { |
|
44 | + $callback($object, $instance, $this->_instanceViewer->count()+1); |
|
45 | 45 | } |
46 | 46 | } |
47 | - if($object instanceof HtmlSemDoubleElement){ |
|
47 | + if ($object instanceof HtmlSemDoubleElement) { |
|
48 | 48 | $id=$this->_instanceViewer->getIdentifier(); |
49 | - $object->setProperty("data-ajax",$id); |
|
50 | - if($object->propertyContains("class","visibleover")){ |
|
49 | + $object->setProperty("data-ajax", $id); |
|
50 | + if ($object->propertyContains("class", "visibleover")) { |
|
51 | 51 | $this->_visibleHover=true; |
52 | - $object->setProperty("style","visibility:hidden;"); |
|
52 | + $object->setProperty("style", "visibility:hidden;"); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | return $object; |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | * @param string $caption |
62 | 62 | * @return HtmlButton |
63 | 63 | */ |
64 | - private function getFieldButton($caption,$visibleHover=true){ |
|
65 | - $bt= new HtmlButton($this->cleanIdentifier($caption),$caption); |
|
66 | - if($visibleHover) |
|
64 | + private function getFieldButton($caption, $visibleHover=true) { |
|
65 | + $bt=new HtmlButton($this->cleanIdentifier($caption), $caption); |
|
66 | + if ($visibleHover) |
|
67 | 67 | $this->_visibleOver($bt); |
68 | 68 | return $bt; |
69 | 69 | } |
70 | 70 | |
71 | - private function getFieldButtons($buttons,$visibleHover=true){ |
|
72 | - $bts=new HtmlButtonGroups("",$buttons); |
|
73 | - if($visibleHover) |
|
71 | + private function getFieldButtons($buttons, $visibleHover=true) { |
|
72 | + $bts=new HtmlButtonGroups("", $buttons); |
|
73 | + if ($visibleHover) |
|
74 | 74 | $this->_visibleOver($bts); |
75 | 75 | return $bts; |
76 | 76 | } |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
85 | 85 | * @return DataTable |
86 | 86 | */ |
87 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
88 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
89 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
90 | - $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
|
91 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
87 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
88 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
89 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
90 | + $button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]); |
|
91 | + if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
92 | 92 | $this->_visibleOver($button); |
93 | 93 | return $button; |
94 | - }, $index,$attributes); |
|
94 | + }, $index, $attributes); |
|
95 | 95 | } |
96 | 96 | |
97 | - protected function _visibleOver(BaseHtml $element){ |
|
97 | + protected function _visibleOver(BaseHtml $element) { |
|
98 | 98 | $this->_visibleHover=true; |
99 | - return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
|
99 | + return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;"); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @param boolean $visibleHover |
107 | 107 | * @return DataTable |
108 | 108 | */ |
109 | - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
|
110 | - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
|
109 | + public function addFieldButton($caption, $visibleHover=true, $callback=null) { |
|
110 | + $this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback)); |
|
111 | 111 | return $this; |
112 | 112 | } |
113 | 113 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @param boolean $visibleHover |
119 | 119 | * @return DataTable |
120 | 120 | */ |
121 | - public function addFieldButtons($buttons,$visibleHover=true,$callback=null){ |
|
122 | - $this->addField($this->getCallable("getFieldButtons",[$buttons,$visibleHover],$callback)); |
|
121 | + public function addFieldButtons($buttons, $visibleHover=true, $callback=null) { |
|
122 | + $this->addField($this->getCallable("getFieldButtons", [$buttons, $visibleHover], $callback)); |
|
123 | 123 | return $this; |
124 | 124 | } |
125 | 125 | |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @param callable $callback |
131 | 131 | * @return DataTable |
132 | 132 | */ |
133 | - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
134 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
133 | + public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
134 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
135 | 135 | return $this; |
136 | 136 | } |
137 | 137 | |
@@ -142,25 +142,25 @@ discard block |
||
142 | 142 | * @param callable $callback |
143 | 143 | * @return DataTable |
144 | 144 | */ |
145 | - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
146 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
145 | + public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
146 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
147 | 147 | return $this; |
148 | 148 | } |
149 | 149 | |
150 | - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
|
151 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
150 | + private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) { |
|
151 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
152 | 152 | return $this; |
153 | 153 | } |
154 | 154 | |
155 | - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
|
156 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
155 | + private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) { |
|
156 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
157 | 157 | return $this; |
158 | 158 | } |
159 | 159 | |
160 | - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
161 | - $bt=$this->getFieldButton("",$visibleHover); |
|
160 | + private function getDefaultButton($icon, $class=null, $visibleHover=true) { |
|
161 | + $bt=$this->getFieldButton("", $visibleHover); |
|
162 | 162 | $bt->asIcon($icon); |
163 | - if(isset($class)) |
|
163 | + if (isset($class)) |
|
164 | 164 | $bt->addClass($class); |
165 | 165 | return $bt; |
166 | 166 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | * @param callable $callback this function takes the following arguments : $object=>the delete button, $instance : the active instance of the object |
173 | 173 | * @return DataTable |
174 | 174 | */ |
175 | - public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
175 | + public function addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
176 | 176 | $this->_deleteBehavior=$deleteBehavior; |
177 | - return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback); |
|
177 | + return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | * @param callable $callback this function takes the following arguments : $object=>the delete button, $instance : the active instance of the object |
185 | 185 | * @return DataTable |
186 | 186 | */ |
187 | - public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){ |
|
187 | + public function addEditButton($visibleHover=true, $editBehavior=[], $callback=null) { |
|
188 | 188 | $this->_editBehavior=$editBehavior; |
189 | - return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback); |
|
189 | + return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -197,20 +197,20 @@ discard block |
||
197 | 197 | * @param callable $callbackDelete this function takes the following arguments : $object=>the delete button, $instance : the active instance of the object |
198 | 198 | * @return DataTable |
199 | 199 | */ |
200 | - public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){ |
|
201 | - $this->addEditButton($visibleHover,$behavior,$callbackEdit); |
|
200 | + public function addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null) { |
|
201 | + $this->addEditButton($visibleHover, $behavior, $callbackEdit); |
|
202 | 202 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
203 | - $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete); |
|
203 | + $this->insertDeleteButtonIn($index, $visibleHover, $behavior, $callbackDelete); |
|
204 | 204 | return $this; |
205 | 205 | } |
206 | 206 | |
207 | - public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
207 | + public function insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
208 | 208 | $this->_deleteBehavior=$deleteBehavior; |
209 | - return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback); |
|
209 | + return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback); |
|
210 | 210 | } |
211 | 211 | |
212 | - public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){ |
|
212 | + public function insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null) { |
|
213 | 213 | $this->_editBehavior=$editBehavior; |
214 | - return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback); |
|
214 | + return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback); |
|
215 | 215 | } |
216 | 216 | } |
@@ -63,15 +63,17 @@ discard block |
||
63 | 63 | */ |
64 | 64 | private function getFieldButton($caption,$visibleHover=true){ |
65 | 65 | $bt= new HtmlButton($this->cleanIdentifier($caption),$caption); |
66 | - if($visibleHover) |
|
67 | - $this->_visibleOver($bt); |
|
66 | + if($visibleHover) { |
|
67 | + $this->_visibleOver($bt); |
|
68 | + } |
|
68 | 69 | return $bt; |
69 | 70 | } |
70 | 71 | |
71 | 72 | private function getFieldButtons($buttons,$visibleHover=true){ |
72 | 73 | $bts=new HtmlButtonGroups("",$buttons); |
73 | - if($visibleHover) |
|
74 | - $this->_visibleOver($bts); |
|
74 | + if($visibleHover) { |
|
75 | + $this->_visibleOver($bts); |
|
76 | + } |
|
75 | 77 | return $bts; |
76 | 78 | } |
77 | 79 | |
@@ -88,8 +90,9 @@ discard block |
||
88 | 90 | return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
89 | 91 | $button=new HtmlButton($id,$value,$cssStyle); |
90 | 92 | $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
91 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
92 | - $this->_visibleOver($button); |
|
93 | + if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) { |
|
94 | + $this->_visibleOver($button); |
|
95 | + } |
|
93 | 96 | return $button; |
94 | 97 | }, $index,$attributes); |
95 | 98 | } |
@@ -160,8 +163,9 @@ discard block |
||
160 | 163 | private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
161 | 164 | $bt=$this->getFieldButton("",$visibleHover); |
162 | 165 | $bt->asIcon($icon); |
163 | - if(isset($class)) |
|
164 | - $bt->addClass($class); |
|
166 | + if(isset($class)) { |
|
167 | + $bt->addClass($class); |
|
168 | + } |
|
165 | 169 | return $bt; |
166 | 170 | } |
167 | 171 |
@@ -19,220 +19,220 @@ 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){ |
|
91 | + protected function _getPropertyValue(\ReflectionProperty $property) { |
|
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); |
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,self::$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, self::$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,self::$index); |
|
124 | + if (isset($this->afterCompile[$index])) { |
|
125 | + if (\is_callable($this->afterCompile[$index])) { |
|
126 | + $this->afterCompile[$index]($value, $this->instance, self::$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 addFields($fields){ |
|
157 | - $this->visibleProperties=\array_merge($this->visibleProperties,$fields); |
|
156 | + public function addFields($fields) { |
|
157 | + $this->visibleProperties=\array_merge($this->visibleProperties, $fields); |
|
158 | 158 | return $this; |
159 | 159 | } |
160 | 160 | |
161 | - public function count(){ |
|
161 | + public function count() { |
|
162 | 162 | return \sizeof($this->properties); |
163 | 163 | } |
164 | 164 | |
165 | - public function visiblePropertiesCount(){ |
|
165 | + public function visiblePropertiesCount() { |
|
166 | 166 | return \sizeof($this->visibleProperties); |
167 | 167 | } |
168 | 168 | |
169 | - public function getProperty($index){ |
|
169 | + public function getProperty($index) { |
|
170 | 170 | return $this->properties[$index]; |
171 | 171 | } |
172 | 172 | |
173 | - public function getFieldName($index){ |
|
173 | + public function getFieldName($index) { |
|
174 | 174 | $property=$this->getProperty($index); |
175 | - if($property instanceof \ReflectionProperty){ |
|
175 | + if ($property instanceof \ReflectionProperty) { |
|
176 | 176 | $result=$property->getName(); |
177 | - }elseif(\is_callable($property)){ |
|
177 | + }elseif (\is_callable($property)) { |
|
178 | 178 | $result=$this->visibleProperties[$index]; |
179 | - }else{ |
|
179 | + } else { |
|
180 | 180 | $result=$property; |
181 | 181 | } |
182 | 182 | return $result; |
183 | 183 | } |
184 | 184 | |
185 | 185 | |
186 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
187 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
186 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
187 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | public function setInstance($instance) { |
191 | - if(\is_string($instance)){ |
|
191 | + if (\is_string($instance)) { |
|
192 | 192 | $instance=new $instance(); |
193 | 193 | } |
194 | 194 | $this->instance=$instance; |
195 | 195 | $this->properties=[]; |
196 | 196 | $this->reflect=new \ReflectionClass($instance); |
197 | - if(JArray::count($this->visibleProperties)===0){ |
|
197 | + if (JArray::count($this->visibleProperties)===0) { |
|
198 | 198 | $this->properties=$this->getDefaultProperties(); |
199 | - }else{ |
|
200 | - foreach ($this->visibleProperties as $property){ |
|
199 | + } else { |
|
200 | + foreach ($this->visibleProperties as $property) { |
|
201 | 201 | $this->setInstanceProperty($property); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | return $this; |
205 | 205 | } |
206 | 206 | |
207 | - private function setInstanceProperty($property){ |
|
208 | - if(\is_callable($property)){ |
|
207 | + private function setInstanceProperty($property) { |
|
208 | + if (\is_callable($property)) { |
|
209 | 209 | $this->properties[]=$property; |
210 | - }elseif(\is_string($property)){ |
|
211 | - try{ |
|
210 | + }elseif (\is_string($property)) { |
|
211 | + try { |
|
212 | 212 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
213 | 213 | $rProperty=$this->reflect->getProperty($property); |
214 | 214 | $this->properties[]=$rProperty; |
215 | - }catch(\Exception $e){ |
|
215 | + }catch (\Exception $e) { |
|
216 | 216 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
217 | 217 | $this->properties[]=$property; |
218 | 218 | } |
219 | - }elseif(\is_int($property)){ |
|
219 | + }elseif (\is_int($property)) { |
|
220 | 220 | $props=$this->getDefaultProperties(); |
221 | - if(isset($props[$property])) |
|
221 | + if (isset($props[$property])) |
|
222 | 222 | $this->properties[]=$props[$property]; |
223 | 223 | else |
224 | 224 | $this->properties[]=$property; |
225 | - }else{ |
|
225 | + } else { |
|
226 | 226 | $this->properties[]=$property; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | - protected function getDefaultProperties(){ |
|
230 | + protected function getDefaultProperties() { |
|
231 | 231 | $result=[]; |
232 | 232 | $properties=$this->reflect->getProperties(); |
233 | - foreach ($properties as $property){ |
|
233 | + foreach ($properties as $property) { |
|
234 | 234 | $showable=$this->showableProperty($property); |
235 | - if($showable!==false){ |
|
235 | + if ($showable!==false) { |
|
236 | 236 | $result[]=$property; |
237 | 237 | } |
238 | 238 | } |
@@ -244,12 +244,12 @@ discard block |
||
244 | 244 | return $this; |
245 | 245 | } |
246 | 246 | |
247 | - public function setValueFunction($index,$callback){ |
|
247 | + public function setValueFunction($index, $callback) { |
|
248 | 248 | $this->values[$index]=$callback; |
249 | 249 | return $this; |
250 | 250 | } |
251 | 251 | |
252 | - public function setIdentifierFunction($callback){ |
|
252 | + public function setIdentifierFunction($callback) { |
|
253 | 253 | $this->values["identifier"]=$callback; |
254 | 254 | return $this; |
255 | 255 | } |
@@ -262,42 +262,42 @@ discard block |
||
262 | 262 | return $this->properties; |
263 | 263 | } |
264 | 264 | |
265 | - public function getCaption($index){ |
|
266 | - if(isset($this->captions[$index])){ |
|
265 | + public function getCaption($index) { |
|
266 | + if (isset($this->captions[$index])) { |
|
267 | 267 | return $this->captions[$index]; |
268 | 268 | } |
269 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
269 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
270 | 270 | return $this->properties[$index]->getName(); |
271 | - elseif(\is_callable($this->properties[$index])) |
|
271 | + elseif (\is_callable($this->properties[$index])) |
|
272 | 272 | return ""; |
273 | 273 | else |
274 | 274 | return $this->properties[$index]; |
275 | 275 | } |
276 | 276 | |
277 | - public function getCaptions(){ |
|
277 | + public function getCaptions() { |
|
278 | 278 | $count=$this->count(); |
279 | - if(isset($this->captions)){ |
|
280 | - $captions= \array_values($this->captions); |
|
279 | + if (isset($this->captions)) { |
|
280 | + $captions=\array_values($this->captions); |
|
281 | 281 | $captionsSize=\sizeof($captions); |
282 | - for($i=$captionsSize;$i<$count;$i++){ |
|
282 | + for ($i=$captionsSize; $i<$count; $i++) { |
|
283 | 283 | $captions[]=""; |
284 | 284 | } |
285 | - }else{ |
|
285 | + } else { |
|
286 | 286 | $captions=[]; |
287 | 287 | $index=0; |
288 | - while($index<$count){ |
|
288 | + while ($index<$count) { |
|
289 | 289 | $captions[]=$this->getCaption($index++); |
290 | 290 | } |
291 | 291 | } |
292 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
292 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
293 | 293 | $callback=$this->captionCallback; |
294 | - $callback($captions,$this->instance); |
|
294 | + $callback($captions, $this->instance); |
|
295 | 295 | } |
296 | 296 | return $captions; |
297 | 297 | } |
298 | 298 | |
299 | - public function setCaption($index,$caption){ |
|
300 | - if(isset($this->captions)===false) |
|
299 | + public function setCaption($index, $caption) { |
|
300 | + if (isset($this->captions)===false) |
|
301 | 301 | $this->captions=[]; |
302 | 302 | $this->captions[$index]=$caption; |
303 | 303 | return $this; |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param callable $callback function called after the field compilation |
316 | 316 | * @return InstanceViewer |
317 | 317 | */ |
318 | - public function afterCompile($index,$callback){ |
|
318 | + public function afterCompile($index, $callback) { |
|
319 | 319 | $this->afterCompile[$index]=$callback; |
320 | 320 | return $this; |
321 | 321 | } |
@@ -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); |
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,self::$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; |
@@ -174,9 +177,9 @@ discard block |
||
174 | 177 | $property=$this->getProperty($index); |
175 | 178 | if($property instanceof \ReflectionProperty){ |
176 | 179 | $result=$property->getName(); |
177 | - }elseif(\is_callable($property)){ |
|
180 | + } elseif(\is_callable($property)){ |
|
178 | 181 | $result=$this->visibleProperties[$index]; |
179 | - }else{ |
|
182 | + } else{ |
|
180 | 183 | $result=$property; |
181 | 184 | } |
182 | 185 | return $result; |
@@ -196,7 +199,7 @@ discard block |
||
196 | 199 | $this->reflect=new \ReflectionClass($instance); |
197 | 200 | if(JArray::count($this->visibleProperties)===0){ |
198 | 201 | $this->properties=$this->getDefaultProperties(); |
199 | - }else{ |
|
202 | + } else{ |
|
200 | 203 | foreach ($this->visibleProperties as $property){ |
201 | 204 | $this->setInstanceProperty($property); |
202 | 205 | } |
@@ -207,22 +210,23 @@ discard block |
||
207 | 210 | private function setInstanceProperty($property){ |
208 | 211 | if(\is_callable($property)){ |
209 | 212 | $this->properties[]=$property; |
210 | - }elseif(\is_string($property)){ |
|
213 | + } elseif(\is_string($property)){ |
|
211 | 214 | try{ |
212 | 215 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
213 | 216 | $rProperty=$this->reflect->getProperty($property); |
214 | 217 | $this->properties[]=$rProperty; |
215 | - }catch(\Exception $e){ |
|
218 | + } catch(\Exception $e){ |
|
216 | 219 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
217 | 220 | $this->properties[]=$property; |
218 | 221 | } |
219 | - }elseif(\is_int($property)){ |
|
222 | + } elseif(\is_int($property)){ |
|
220 | 223 | $props=$this->getDefaultProperties(); |
221 | - if(isset($props[$property])) |
|
222 | - $this->properties[]=$props[$property]; |
|
223 | - else |
|
224 | - $this->properties[]=$property; |
|
225 | - }else{ |
|
224 | + if(isset($props[$property])) { |
|
225 | + $this->properties[]=$props[$property]; |
|
226 | + } else { |
|
227 | + $this->properties[]=$property; |
|
228 | + } |
|
229 | + } else{ |
|
226 | 230 | $this->properties[]=$property; |
227 | 231 | } |
228 | 232 | } |
@@ -266,12 +270,13 @@ discard block |
||
266 | 270 | if(isset($this->captions[$index])){ |
267 | 271 | return $this->captions[$index]; |
268 | 272 | } |
269 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
270 | - return $this->properties[$index]->getName(); |
|
271 | - elseif(\is_callable($this->properties[$index])) |
|
272 | - return ""; |
|
273 | - else |
|
274 | - return $this->properties[$index]; |
|
273 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
274 | + return $this->properties[$index]->getName(); |
|
275 | + } elseif(\is_callable($this->properties[$index])) { |
|
276 | + return ""; |
|
277 | + } else { |
|
278 | + return $this->properties[$index]; |
|
279 | + } |
|
275 | 280 | } |
276 | 281 | |
277 | 282 | public function getCaptions(){ |
@@ -282,7 +287,7 @@ discard block |
||
282 | 287 | for($i=$captionsSize;$i<$count;$i++){ |
283 | 288 | $captions[]=""; |
284 | 289 | } |
285 | - }else{ |
|
290 | + } else{ |
|
286 | 291 | $captions=[]; |
287 | 292 | $index=0; |
288 | 293 | while($index<$count){ |
@@ -297,8 +302,9 @@ discard block |
||
297 | 302 | } |
298 | 303 | |
299 | 304 | public function setCaption($index,$caption){ |
300 | - if(isset($this->captions)===false) |
|
301 | - $this->captions=[]; |
|
305 | + if(isset($this->captions)===false) { |
|
306 | + $this->captions=[]; |
|
307 | + } |
|
302 | 308 | $this->captions[$index]=$caption; |
303 | 309 | return $this; |
304 | 310 | } |
@@ -21,83 +21,83 @@ discard block |
||
21 | 21 | use BaseTrait; |
22 | 22 | |
23 | 23 | public function __construct($identifier, $modelInstance=NULL) { |
24 | - parent::__construct($identifier, null,$modelInstance); |
|
24 | + parent::__construct($identifier, null, $modelInstance); |
|
25 | 25 | $this->_form=new HtmlForm($identifier); |
26 | 26 | $this->_init(new FormInstanceViewer($identifier), "form", $this->_form, true); |
27 | 27 | } |
28 | 28 | |
29 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
29 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
30 | 30 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
31 | 31 | } |
32 | 32 | |
33 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
34 | - if(!$this->_generated){ |
|
33 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
34 | + if (!$this->_generated) { |
|
35 | 35 | $this->_instanceViewer->setInstance($this->_modelInstance); |
36 | 36 | |
37 | 37 | $form=$this->content["form"]; |
38 | 38 | $this->_generateContent($form); |
39 | 39 | |
40 | - if(isset($this->_toolbar)){ |
|
40 | + if (isset($this->_toolbar)) { |
|
41 | 41 | $this->_setToolbarPosition($form); |
42 | 42 | } |
43 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
43 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
44 | 44 | $this->_generated=true; |
45 | 45 | } |
46 | - return parent::compile($js,$view); |
|
46 | + return parent::compile($js, $view); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @param HtmlForm $form |
51 | 51 | */ |
52 | - protected function _generateContent($form){ |
|
53 | - $values= $this->_instanceViewer->getValues(); |
|
52 | + protected function _generateContent($form) { |
|
53 | + $values=$this->_instanceViewer->getValues(); |
|
54 | 54 | $count=$this->_instanceViewer->count(); |
55 | 55 | $separators=$this->_instanceViewer->getSeparators(); |
56 | 56 | $headers=$this->_instanceViewer->getHeaders(); |
57 | 57 | $wrappers=$this->_instanceViewer->getWrappers(); |
58 | 58 | \sort($separators); |
59 | 59 | $size=\sizeof($separators); |
60 | - if($size===1){ |
|
60 | + if ($size===1) { |
|
61 | 61 | $i=-1; |
62 | - foreach ($values as $v){ |
|
62 | + foreach ($values as $v) { |
|
63 | 63 | $this->_generateFields($form, [$v], $headers, $i, $wrappers); |
64 | 64 | $i++; |
65 | 65 | } |
66 | - }else{ |
|
66 | + } else { |
|
67 | 67 | $separators[]=$count; |
68 | - for($i=0;$i<$size;$i++){ |
|
69 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
68 | + for ($i=0; $i<$size; $i++) { |
|
69 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
70 | 70 | $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers); |
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - protected function _generateFields($form,$values,$headers,$sepFirst,$wrappers){ |
|
75 | + protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers) { |
|
76 | 76 | $wrapper=null; |
77 | - if(isset($headers[$sepFirst+1])) |
|
78 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
79 | - if(isset($wrappers[$sepFirst+1])){ |
|
77 | + if (isset($headers[$sepFirst+1])) |
|
78 | + $form->addHeader($headers[$sepFirst+1], 4, true); |
|
79 | + if (isset($wrappers[$sepFirst+1])) { |
|
80 | 80 | $wrapper=$wrappers[$sepFirst+1]; |
81 | 81 | } |
82 | - if(\sizeof($values)===1){ |
|
82 | + if (\sizeof($values)===1) { |
|
83 | 83 | $added=$form->addField($values[0]); |
84 | - }elseif(\sizeof($values)>1){ |
|
84 | + }elseif (\sizeof($values)>1) { |
|
85 | 85 | $added=$form->addFields($values); |
86 | - }else |
|
86 | + } else |
|
87 | 87 | return; |
88 | - if(isset($wrapper)){ |
|
89 | - $added->wrap($wrapper[0],$wrapper[1]); |
|
88 | + if (isset($wrapper)) { |
|
89 | + $added->wrap($wrapper[0], $wrapper[1]); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return HtmlForm |
95 | 95 | */ |
96 | - public function getForm(){ |
|
96 | + public function getForm() { |
|
97 | 97 | return $this->content["form"]; |
98 | 98 | } |
99 | 99 | |
100 | - public function addSeparatorAfter($fieldNum){ |
|
100 | + public function addSeparatorAfter($fieldNum) { |
|
101 | 101 | $fieldNum=$this->_getIndex($fieldNum); |
102 | 102 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
103 | 103 | return $this; |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | return $this; |
113 | 113 | } |
114 | 114 | |
115 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
116 | - return $this->_fieldAs(function($id,$name,$value) use ($cssStyle){ |
|
117 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
115 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
116 | + return $this->_fieldAs(function($id, $name, $value) use ($cssStyle){ |
|
117 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
118 | 118 | $button->setProperty("type", "reset"); |
119 | 119 | return $button; |
120 | - }, $index,$attributes); |
|
120 | + }, $index, $attributes); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -136,19 +136,19 @@ discard block |
||
136 | 136 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
137 | 137 | } |
138 | 138 | |
139 | - public function addDividerBefore($index,$title){ |
|
139 | + public function addDividerBefore($index, $title) { |
|
140 | 140 | $index=$this->_getIndex($index); |
141 | 141 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
142 | 142 | return $this; |
143 | 143 | } |
144 | 144 | |
145 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
145 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
146 | 146 | $index=$this->_getIndex($index); |
147 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
147 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
148 | 148 | return $this; |
149 | 149 | } |
150 | 150 | |
151 | - public function run(JsUtils $js){ |
|
151 | + public function run(JsUtils $js) { |
|
152 | 152 | parent::run($js); |
153 | 153 | } |
154 | 154 | } |