@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | use Ajax\common\html\traits\BaseHooksTrait; |
| 22 | 22 | |
| 23 | 23 | abstract class Widget extends HtmlDoubleElement { |
| 24 | - use FieldAsTrait,FormTrait,BaseHooksTrait; |
|
| 24 | + use FieldAsTrait, FormTrait, BaseHooksTrait; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * @var string classname |
@@ -53,17 +53,17 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | protected $_generated; |
| 55 | 55 | |
| 56 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 56 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 57 | 57 | parent::__construct($identifier); |
| 58 | 58 | $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
| 59 | 59 | $this->setModel($model); |
| 60 | - if(isset($modelInstance)){ |
|
| 60 | + if (isset($modelInstance)) { |
|
| 61 | 61 | $this->show($modelInstance); |
| 62 | 62 | } |
| 63 | 63 | $this->_generated=false; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - protected function _init($instanceViewer,$contentKey,$content,$edition){ |
|
| 66 | + protected function _init($instanceViewer, $contentKey, $content, $edition) { |
|
| 67 | 67 | $this->_instanceViewer=$instanceViewer; |
| 68 | 68 | $this->content=[$contentKey=>$content]; |
| 69 | 69 | $this->_self=$content; |
@@ -75,31 +75,31 @@ discard block |
||
| 75 | 75 | * @param int|string $fieldName |
| 76 | 76 | * @return int|string|boolean |
| 77 | 77 | */ |
| 78 | - protected function _getIndex($fieldName){ |
|
| 78 | + protected function _getIndex($fieldName) { |
|
| 79 | 79 | $index=$fieldName; |
| 80 | - if(\is_string($fieldName)){ |
|
| 80 | + if (\is_string($fieldName)) { |
|
| 81 | 81 | $fields=$this->_instanceViewer->getVisibleProperties(); |
| 82 | 82 | $index=\array_search($fieldName, $fields); |
| 83 | 83 | } |
| 84 | 84 | return $index; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
| 87 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
| 88 | 88 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - protected function _getFieldName($index){ |
|
| 91 | + protected function _getFieldName($index) { |
|
| 92 | 92 | return $this->_instanceViewer->getFieldName($index); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - protected function _getFieldCaption($index){ |
|
| 95 | + protected function _getFieldCaption($index) { |
|
| 96 | 96 | return $this->_instanceViewer->getCaption($index); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
| 99 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
| 100 | 100 | |
| 101 | - public function show($modelInstance){ |
|
| 102 | - if(\is_array($modelInstance)){ |
|
| 101 | + public function show($modelInstance) { |
|
| 102 | + if (\is_array($modelInstance)) { |
|
| 103 | 103 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
| 104 | 104 | } |
| 105 | 105 | $this->_modelInstance=$modelInstance; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | abstract public function getHtmlComponent(); |
| 127 | 127 | |
| 128 | - public function setAttached($value=true){ |
|
| 128 | + public function setAttached($value=true) { |
|
| 129 | 129 | return $this->getHtmlComponent()->setAttached($value); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -136,65 +136,65 @@ discard block |
||
| 136 | 136 | * @param callable $callback function called after the field compilation |
| 137 | 137 | * @return Widget |
| 138 | 138 | */ |
| 139 | - public function afterCompile($index,$callback){ |
|
| 139 | + public function afterCompile($index, $callback) { |
|
| 140 | 140 | $index=$this->_getIndex($index); |
| 141 | 141 | $this->_instanceViewer->afterCompile($index, $callback); |
| 142 | 142 | return $this; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - public function setColor($color){ |
|
| 145 | + public function setColor($color) { |
|
| 146 | 146 | return $this->getHtmlComponent()->setColor($color); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
| 150 | - public function setCaptions($captions){ |
|
| 150 | + public function setCaptions($captions) { |
|
| 151 | 151 | $this->_instanceViewer->setCaptions($captions); |
| 152 | 152 | return $this; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public function setCaption($index,$caption){ |
|
| 155 | + public function setCaption($index, $caption) { |
|
| 156 | 156 | $this->_instanceViewer->setCaption($this->_getIndex($index), $caption); |
| 157 | 157 | return $this; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function setFields($fields){ |
|
| 160 | + public function setFields($fields) { |
|
| 161 | 161 | $this->_instanceViewer->setVisibleProperties($fields); |
| 162 | 162 | return $this; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public function addField($field,$key=null){ |
|
| 166 | - $this->_instanceViewer->addField($field,$key); |
|
| 165 | + public function addField($field, $key=null) { |
|
| 166 | + $this->_instanceViewer->addField($field, $key); |
|
| 167 | 167 | return $this; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - public function addFields($fields){ |
|
| 170 | + public function addFields($fields) { |
|
| 171 | 171 | $this->_instanceViewer->addFields($fields); |
| 172 | 172 | return $this; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - public function countFields(){ |
|
| 175 | + public function countFields() { |
|
| 176 | 176 | return $this->_instanceViewer->visiblePropertiesCount(); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - public function addMessage($attributes=NULL,$fieldName="message"){ |
|
| 179 | + public function addMessage($attributes=NULL, $fieldName="message") { |
|
| 180 | 180 | $this->_instanceViewer->addField($fieldName); |
| 181 | 181 | $count=$this->_instanceViewer->visiblePropertiesCount(); |
| 182 | - return $this->fieldAsMessage($count-1,$attributes); |
|
| 182 | + return $this->fieldAsMessage($count-1, $attributes); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - public function addErrorMessage(){ |
|
| 186 | - return $this->addMessage(["error"=>true],"message"); |
|
| 185 | + public function addErrorMessage() { |
|
| 186 | + return $this->addMessage(["error"=>true], "message"); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - public function insertField($index,$field,$key=null){ |
|
| 189 | + public function insertField($index, $field, $key=null) { |
|
| 190 | 190 | $index=$this->_getIndex($index); |
| 191 | - $this->_instanceViewer->insertField($index, $field,$key); |
|
| 191 | + $this->_instanceViewer->insertField($index, $field, $key); |
|
| 192 | 192 | return $this; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - public function insertInField($index,$field,$key=null){ |
|
| 195 | + public function insertInField($index, $field, $key=null) { |
|
| 196 | 196 | $index=$this->_getIndex($index); |
| 197 | - $this->_instanceViewer->insertInField($index, $field,$key); |
|
| 197 | + $this->_instanceViewer->insertInField($index, $field, $key); |
|
| 198 | 198 | return $this; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | * @param callable $callback function parameters are : $value : the field value, $instance : the active instance of model, $fieldIndex : the field index, $rowIndex : the row index |
| 205 | 205 | * @return Widget |
| 206 | 206 | */ |
| 207 | - public function setValueFunction($index,$callback){ |
|
| 207 | + public function setValueFunction($index, $callback) { |
|
| 208 | 208 | $index=$this->_getIndex($index); |
| 209 | 209 | $this->_instanceViewer->setValueFunction($index, $callback); |
| 210 | 210 | return $this; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - public function setIdentifierFunction($callback){ |
|
| 213 | + public function setIdentifierFunction($callback) { |
|
| 214 | 214 | $this->_instanceViewer->setIdentifierFunction($callback); |
| 215 | 215 | return $this; |
| 216 | 216 | } |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | /** |
| 219 | 219 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
| 220 | 220 | */ |
| 221 | - public function getToolbar(){ |
|
| 222 | - if(isset($this->_toolbar)===false){ |
|
| 221 | + public function getToolbar() { |
|
| 222 | + if (isset($this->_toolbar)===false) { |
|
| 223 | 223 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
| 224 | 224 | } |
| 225 | 225 | return $this->_toolbar; |
@@ -231,15 +231,15 @@ discard block |
||
| 231 | 231 | * @param callable $callback function to call on $element |
| 232 | 232 | * @return \Ajax\common\html\HtmlDoubleElement |
| 233 | 233 | */ |
| 234 | - public function addInToolbar($element,$callback=NULL){ |
|
| 234 | + public function addInToolbar($element, $callback=NULL) { |
|
| 235 | 235 | $tb=$this->getToolbar(); |
| 236 | - if($element instanceof BaseWidget){ |
|
| 237 | - if($element->getIdentifier()===""){ |
|
| 236 | + if ($element instanceof BaseWidget) { |
|
| 237 | + if ($element->getIdentifier()==="") { |
|
| 238 | 238 | $element->setIdentifier("tb-item-".$this->identifier."-".$tb->count()); |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | - if(isset($callback)){ |
|
| 242 | - if(\is_callable($callback)){ |
|
| 241 | + if (isset($callback)) { |
|
| 242 | + if (\is_callable($callback)) { |
|
| 243 | 243 | $callback($element); |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | * @param callable $callback function($element) |
| 253 | 253 | * @return \Ajax\common\html\HtmlDoubleElement |
| 254 | 254 | */ |
| 255 | - public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
| 256 | - $result=$this->addInToolbar($caption,$callback); |
|
| 257 | - if(isset($icon) && method_exists($result, "addIcon")) |
|
| 255 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
| 256 | + $result=$this->addInToolbar($caption, $callback); |
|
| 257 | + if (isset($icon) && method_exists($result, "addIcon")) |
|
| 258 | 258 | $result->addIcon($icon); |
| 259 | 259 | return $result; |
| 260 | 260 | } |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | * @param callable $callback function($element) |
| 265 | 265 | * @return \Ajax\common\Widget |
| 266 | 266 | */ |
| 267 | - public function addItemsInToolbar(array $items,$callback=NULL){ |
|
| 268 | - if(JArray::isAssociative($items)){ |
|
| 269 | - foreach ($items as $icon=>$item){ |
|
| 270 | - $this->addItemInToolbar($item,$icon,$callback); |
|
| 267 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
| 268 | + if (JArray::isAssociative($items)) { |
|
| 269 | + foreach ($items as $icon=>$item) { |
|
| 270 | + $this->addItemInToolbar($item, $icon, $callback); |
|
| 271 | 271 | } |
| 272 | - }else{ |
|
| 273 | - foreach ($items as $item){ |
|
| 274 | - $this->addItemInToolbar($item,null,$callback); |
|
| 272 | + } else { |
|
| 273 | + foreach ($items as $item) { |
|
| 274 | + $this->addItemInToolbar($item, null, $callback); |
|
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | return $this; |
@@ -283,12 +283,12 @@ discard block |
||
| 283 | 283 | * @param callable $callback function($element) |
| 284 | 284 | * @return \Ajax\common\html\HtmlDoubleElement |
| 285 | 285 | */ |
| 286 | - public function addDropdownInToolbar($value,$items,$callback=NULL){ |
|
| 286 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
| 287 | 287 | $dd=$value; |
| 288 | 288 | if (\is_string($value)) { |
| 289 | - $dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
| 289 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
| 290 | 290 | } |
| 291 | - return $this->addInToolbar($dd,$callback); |
|
| 291 | + return $this->addInToolbar($dd, $callback); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | * @param callable $callback function($element) |
| 298 | 298 | * @return \Ajax\common\html\HtmlDoubleElement |
| 299 | 299 | */ |
| 300 | - public function addButtonInToolbar($caption,$cssStyle=null,$callback=NULL){ |
|
| 301 | - $bt=new HtmlButton("bt-".$caption,$caption,$cssStyle); |
|
| 302 | - return $this->addInToolbar($bt,$callback); |
|
| 300 | + public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) { |
|
| 301 | + $bt=new HtmlButton("bt-".$caption, $caption, $cssStyle); |
|
| 302 | + return $this->addInToolbar($bt, $callback); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -308,9 +308,9 @@ discard block |
||
| 308 | 308 | * @param callable $callback function($element) |
| 309 | 309 | * @return \Ajax\common\html\HtmlDoubleElement |
| 310 | 310 | */ |
| 311 | - public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
| 312 | - $bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
| 313 | - return $this->addInToolbar($bts,$callback); |
|
| 311 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
| 312 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
| 313 | + return $this->addInToolbar($bts, $callback); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -320,15 +320,15 @@ discard block |
||
| 320 | 320 | * @param boolean $labeled |
| 321 | 321 | * @return \Ajax\common\html\HtmlDoubleElement |
| 322 | 322 | */ |
| 323 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
| 324 | - $bt=new HtmlButton("",$caption); |
|
| 325 | - $bt->addIcon($icon,$before,$labeled); |
|
| 323 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
| 324 | + $bt=new HtmlButton("", $caption); |
|
| 325 | + $bt->addIcon($icon, $before, $labeled); |
|
| 326 | 326 | return $this->addInToolbar($bt); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
| 330 | - $button=new HtmlButton($identifier,$value,$cssStyle); |
|
| 331 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters); |
|
| 329 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
| 330 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
| 331 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters); |
|
| 332 | 332 | return $this->addInToolbar($button); |
| 333 | 333 | } |
| 334 | 334 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model |
| 359 | 359 | * @return \Ajax\common\Widget |
| 360 | 360 | */ |
| 361 | - public function setDefaultValueFunction($defaultValueFunction){ |
|
| 361 | + public function setDefaultValueFunction($defaultValueFunction) { |
|
| 362 | 362 | $this->_instanceViewer->setDefaultValueFunction($defaultValueFunction); |
| 363 | 363 | return $this; |
| 364 | 364 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | /** |
| 367 | 367 | * @return callable |
| 368 | 368 | */ |
| 369 | - public function getDefaultValueFunction(){ |
|
| 369 | + public function getDefaultValueFunction() { |
|
| 370 | 370 | return $this->_instanceViewer->getDefaultValueFunction(); |
| 371 | 371 | } |
| 372 | 372 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @param string|boolean $disable |
| 375 | 375 | * @return string |
| 376 | 376 | */ |
| 377 | - public function jsDisabled($disable=true){ |
|
| 377 | + public function jsDisabled($disable=true) { |
|
| 378 | 378 | return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
| 379 | 379 | } |
| 380 | 380 | |
@@ -383,12 +383,12 @@ discard block |
||
| 383 | 383 | * @param callable $callback function($element) |
| 384 | 384 | * @return \Ajax\common\html\HtmlDoubleElement |
| 385 | 385 | */ |
| 386 | - public function addEditButtonInToolbar($caption,$callback=NULL){ |
|
| 387 | - $bt=new HtmlButton($this->identifier."-editBtn",$caption); |
|
| 386 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
| 387 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
| 388 | 388 | $bt->setToggle(); |
| 389 | 389 | $bt->setActive($this->_edition); |
| 390 | 390 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
| 391 | - return $this->addInToolbar($bt,$callback); |
|
| 391 | + return $this->addInToolbar($bt, $callback); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | public function setToolbar(HtmlMenu $_toolbar) { |
@@ -402,34 +402,34 @@ discard block |
||
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | public function getForm() { |
| 405 | - if(!isset($this->_form)){ |
|
| 405 | + if (!isset($this->_form)) { |
|
| 406 | 406 | $this->_form=new HtmlForm("frm-".$this->identifier); |
| 407 | 407 | $this->setEdition(true); |
| 408 | 408 | } |
| 409 | 409 | return $this->_form; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - public function run(JsUtils $js){ |
|
| 412 | + public function run(JsUtils $js) { |
|
| 413 | 413 | parent::run($js); |
| 414 | - if(isset($this->_form)){ |
|
| 414 | + if (isset($this->_form)) { |
|
| 415 | 415 | $this->runForm($js); |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - protected function runForm(JsUtils $js){ |
|
| 419 | + protected function runForm(JsUtils $js) { |
|
| 420 | 420 | $fields=$this->getContentInstances(HtmlFormField::class); |
| 421 | - foreach ($fields as $field){ |
|
| 421 | + foreach ($fields as $field) { |
|
| 422 | 422 | $this->_form->addField($field); |
| 423 | 423 | } |
| 424 | 424 | return $this->_form->run($js); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - protected function _compileForm(){ |
|
| 428 | - if(isset($this->_form)){ |
|
| 427 | + protected function _compileForm() { |
|
| 428 | + if (isset($this->_form)) { |
|
| 429 | 429 | $noValidate=""; |
| 430 | - if(\sizeof($this->_form->getValidationParams())>0) |
|
| 430 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
| 431 | 431 | $noValidate="novalidate"; |
| 432 | - $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>"); |
|
| 432 | + $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | |
@@ -444,33 +444,33 @@ discard block |
||
| 444 | 444 | return $this; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - public function moveFieldTo($from,$to){ |
|
| 447 | + public function moveFieldTo($from, $to) { |
|
| 448 | 448 | return $this->_instanceViewer->moveFieldTo($from, $to); |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - public function swapFields($index1,$index2){ |
|
| 451 | + public function swapFields($index1, $index2) { |
|
| 452 | 452 | $index1=$this->_getIndex($index1); |
| 453 | 453 | $index2=$this->_getIndex($index2); |
| 454 | 454 | return $this->_instanceViewer->swapFields($index1, $index2); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - public function removeField($index){ |
|
| 457 | + public function removeField($index) { |
|
| 458 | 458 | $index=$this->_getIndex($index); |
| 459 | 459 | $this->_instanceViewer->removeField($index); |
| 460 | 460 | return $this; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - public function asModal($header=null){ |
|
| 464 | - $modal=new HtmlModal("modal-".$this->identifier,$header); |
|
| 463 | + public function asModal($header=null) { |
|
| 464 | + $modal=new HtmlModal("modal-".$this->identifier, $header); |
|
| 465 | 465 | $modal->setContent($this); |
| 466 | - if(isset($this->_form)){ |
|
| 466 | + if (isset($this->_form)) { |
|
| 467 | 467 | $this->_form->onSuccess($modal->jsHide()); |
| 468 | 468 | } |
| 469 | 469 | return $modal; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | public function addToProperty($name, $value, $separator=" ") { |
| 473 | - return $this->getHtmlComponent()->addToProperty($name,$value,$separator); |
|
| 473 | + return $this->getHtmlComponent()->addToProperty($name, $value, $separator); |
|
| 474 | 474 | } |
| 475 | 475 | /** |
| 476 | 476 | * @return mixed |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @param string $hookKey |
| 10 | 10 | * @return boolean |
| 11 | 11 | */ |
| 12 | - public function hookExists($hookKey){ |
|
| 12 | + public function hookExists($hookKey) { |
|
| 13 | 13 | return isset($this->_hooks[$hookKey]); |
| 14 | 14 | } |
| 15 | 15 | |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | * @param string $hookKey |
| 18 | 18 | * @return callable|NULL |
| 19 | 19 | */ |
| 20 | - public function getHook($hookKey){ |
|
| 21 | - if(isset($this->_hooks[$hookKey])){ |
|
| 20 | + public function getHook($hookKey) { |
|
| 21 | + if (isset($this->_hooks[$hookKey])) { |
|
| 22 | 22 | return $this->_hooks[$hookKey]; |
| 23 | 23 | } |
| 24 | 24 | return null; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param String $hookKey |
| 30 | 30 | * @param callable $callable |
| 31 | 31 | */ |
| 32 | - public function addHook($hookKey,$callable){ |
|
| 32 | + public function addHook($hookKey, $callable) { |
|
| 33 | 33 | $this->_hooks[$hookKey]=$callable; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | * @param mixed|null $variable |
| 40 | 40 | * @return void|mixed |
| 41 | 41 | */ |
| 42 | - public function execHook($hookKey,$variable=null){ |
|
| 43 | - if(($hook=$this->getHook($hookKey))!=null){ |
|
| 42 | + public function execHook($hookKey, $variable=null) { |
|
| 43 | + if (($hook=$this->getHook($hookKey))!=null) { |
|
| 44 | 44 | return $hook($variable); |
| 45 | 45 | } |
| 46 | 46 | return; |
@@ -21,74 +21,74 @@ 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 | - $this->execHook("onGenerateFields",$added); |
|
| 91 | + $this->execHook("onGenerateFields", $added); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -96,18 +96,18 @@ discard block |
||
| 96 | 96 | * the generated field is the first parameter |
| 97 | 97 | * @param callable $callback the fonction to call when a field is generated |
| 98 | 98 | */ |
| 99 | - public function onGenerateField($callback){ |
|
| 100 | - $this->addHook("onGenerateFields",$callback); |
|
| 99 | + public function onGenerateField($callback) { |
|
| 100 | + $this->addHook("onGenerateFields", $callback); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * @return HtmlForm |
| 105 | 105 | */ |
| 106 | - public function getForm(){ |
|
| 106 | + public function getForm() { |
|
| 107 | 107 | return $this->content["form"]; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function addSeparatorAfter($fieldNum){ |
|
| 110 | + public function addSeparatorAfter($fieldNum) { |
|
| 111 | 111 | $fieldNum=$this->_getIndex($fieldNum); |
| 112 | 112 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
| 113 | 113 | return $this; |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | return $this; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 126 | - return $this->_fieldAs(function($id,$name,$value) use ($cssStyle){ |
|
| 127 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 125 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 126 | + return $this->_fieldAs(function($id, $name, $value) use ($cssStyle){ |
|
| 127 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 128 | 128 | $button->setProperty("type", "reset"); |
| 129 | 129 | return $button; |
| 130 | - }, $index,$attributes); |
|
| 130 | + }, $index, $attributes); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -146,19 +146,19 @@ discard block |
||
| 146 | 146 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - public function addDividerBefore($index,$title){ |
|
| 149 | + public function addDividerBefore($index, $title) { |
|
| 150 | 150 | $index=$this->_getIndex($index); |
| 151 | 151 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
| 152 | 152 | return $this; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
| 155 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
| 156 | 156 | $index=$this->_getIndex($index); |
| 157 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
| 157 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
| 158 | 158 | return $this; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public function run(JsUtils $js){ |
|
| 161 | + public function run(JsUtils $js) { |
|
| 162 | 162 | parent::run($js); |
| 163 | 163 | } |
| 164 | 164 | } |