@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | protected $_hasCheckboxes; |
| 31 | 31 | protected $_compileParts; |
| 32 | 32 | |
| 33 | - public function run(JsUtils $js){ |
|
| 34 | - if($this->_hasCheckboxes && isset($js)){ |
|
| 33 | + public function run(JsUtils $js) { |
|
| 34 | + if ($this->_hasCheckboxes && isset($js)) { |
|
| 35 | 35 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
| 36 | 36 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
| 37 | 37 | \$checkbox.each(function() {if($(this).prop('checked')){allUnchecked = false;}else{allChecked = false;}}); |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | parent::run($js); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 44 | - parent::__construct($identifier, $model,$modelInstance); |
|
| 45 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
| 43 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 44 | + parent::__construct($identifier, $model, $modelInstance); |
|
| 45 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,61 +54,61 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 57 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 58 | 58 | $this->_instanceViewer->setInstance($this->_model); |
| 59 | 59 | $captions=$this->_instanceViewer->getCaptions(); |
| 60 | 60 | |
| 61 | 61 | $table=$this->content["table"]; |
| 62 | 62 | |
| 63 | - if($this->_hasCheckboxes){ |
|
| 63 | + if ($this->_hasCheckboxes) { |
|
| 64 | 64 | $this->_generateMainCheckbox($captions); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $table->setRowCount(0, \sizeof($captions)); |
| 68 | 68 | $table->setHeaderValues($captions); |
| 69 | - if(isset($this->_compileParts)) |
|
| 69 | + if (isset($this->_compileParts)) |
|
| 70 | 70 | $table->setCompileParts($this->_compileParts); |
| 71 | - if(isset($this->_searchField) && isset($js)){ |
|
| 72 | - $this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
| 71 | + if (isset($this->_searchField) && isset($js)) { |
|
| 72 | + $this->_searchField->postOn("change", $this->_urls, "{'s':$(this).val()}", "-#".$this->identifier." tbody", ["preventDefault"=>false]); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $this->_generateContent($table); |
| 76 | 76 | |
| 77 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
| 78 | - $table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort"); |
|
| 77 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
| 78 | + $table->getHeader()->getCell(0, 0)->addToProperty("class", "no-sort"); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
| 81 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
| 82 | 82 | $this->_generatePagination($table); |
| 83 | 83 | } |
| 84 | - if(isset($this->_toolbar)){ |
|
| 84 | + if (isset($this->_toolbar)) { |
|
| 85 | 85 | $this->_setToolbarPosition($table, $captions); |
| 86 | 86 | } |
| 87 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
| 88 | - return parent::compile($js,$view); |
|
| 87 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
| 88 | + return parent::compile($js, $view); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - private function _generateMainCheckbox(&$captions){ |
|
| 92 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
| 91 | + private function _generateMainCheckbox(&$captions) { |
|
| 92 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
| 93 | 93 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);"); |
| 94 | 94 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);"); |
| 95 | 95 | \array_unshift($captions, $ck); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - protected function _generateContent($table){ |
|
| 98 | + protected function _generateContent($table) { |
|
| 99 | 99 | $objects=$this->_modelInstance; |
| 100 | - if(isset($this->_pagination)){ |
|
| 100 | + if (isset($this->_pagination)) { |
|
| 101 | 101 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
| 102 | 102 | } |
| 103 | 103 | InstanceViewer::setIndex(0); |
| 104 | - $table->fromDatabaseObjects($objects, function($instance){ |
|
| 104 | + $table->fromDatabaseObjects($objects, function($instance) { |
|
| 105 | 105 | $this->_instanceViewer->setInstance($instance); |
| 106 | 106 | InstanceViewer::$index++; |
| 107 | - $result= $this->_instanceViewer->getValues(); |
|
| 108 | - if($this->_hasCheckboxes){ |
|
| 109 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
| 107 | + $result=$this->_instanceViewer->getValues(); |
|
| 108 | + if ($this->_hasCheckboxes) { |
|
| 109 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
| 110 | 110 | $field=$ck->getField(); |
| 111 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
| 111 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
| 112 | 112 | $field->setProperty("name", "selection[]"); |
| 113 | 113 | \array_unshift($result, $ck); |
| 114 | 114 | } |
@@ -116,25 +116,25 @@ discard block |
||
| 116 | 116 | }); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - private function _generatePagination($table){ |
|
| 119 | + private function _generatePagination($table) { |
|
| 120 | 120 | $footer=$table->getFooter(); |
| 121 | 121 | $footer->mergeCol(); |
| 122 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
| 122 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
| 123 | 123 | $menu->floatRight(); |
| 124 | 124 | $menu->setActiveItem($this->_pagination->getPage()-1); |
| 125 | 125 | $footer->setValues($menu); |
| 126 | - $menu->postOnClick($this->_urls,"{'p':$(this).attr('data-page')}","-#".$this->identifier." tbody",["preventDefault"=>false]); |
|
| 126 | + $menu->postOnClick($this->_urls, "{'p':$(this).attr('data-page')}", "-#".$this->identifier." tbody", ["preventDefault"=>false]); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
| 130 | - switch ($this->_toolbarPosition){ |
|
| 129 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 130 | + switch ($this->_toolbarPosition) { |
|
| 131 | 131 | case PositionInTable::BEFORETABLE:case PositionInTable::AFTERTABLE: |
| 132 | - if(isset($this->_compileParts)===false){ |
|
| 132 | + if (isset($this->_compileParts)===false) { |
|
| 133 | 133 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 134 | 134 | } |
| 135 | 135 | break; |
| 136 | 136 | case PositionInTable::HEADER:case PositionInTable::FOOTER: case PositionInTable::BODY: |
| 137 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
| 137 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -146,18 +146,18 @@ discard block |
||
| 146 | 146 | * @param callable $callback function called after the field compilation |
| 147 | 147 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 148 | 148 | */ |
| 149 | - public function afterCompile($index,$callback){ |
|
| 150 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
| 149 | + public function afterCompile($index, $callback) { |
|
| 150 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
| 151 | 151 | return $this; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - private function addToolbarRow($part,$table,$captions){ |
|
| 154 | + private function addToolbarRow($part, $table, $captions) { |
|
| 155 | 155 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 156 | 156 | $row->mergeCol(); |
| 157 | 157 | $row->setValues([$this->_toolbar]); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function getHtmlComponent(){ |
|
| 160 | + public function getHtmlComponent() { |
|
| 161 | 161 | return $this->content["table"]; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | return $this; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - public function paginate($items_per_page=10,$page=1){ |
|
| 174 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
| 173 | + public function paginate($items_per_page=10, $page=1) { |
|
| 174 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function getHasCheckboxes() { |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | return $this; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - public function refresh($compileParts=["tbody"]){ |
|
| 186 | + public function refresh($compileParts=["tbody"]) { |
|
| 187 | 187 | $this->_compileParts=$compileParts; |
| 188 | 188 | return $this; |
| 189 | 189 | } |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | * @param callable $callback |
| 193 | 193 | * @return callable |
| 194 | 194 | */ |
| 195 | - private function getFieldButtonCallable($caption,$callback=null){ |
|
| 196 | - return $this->getCallable("getFieldButton",[$caption],$callback); |
|
| 195 | + private function getFieldButtonCallable($caption, $callback=null) { |
|
| 196 | + return $this->getCallable("getFieldButton", [$caption], $callback); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -201,16 +201,16 @@ discard block |
||
| 201 | 201 | * @param callable $callback |
| 202 | 202 | * @return callable |
| 203 | 203 | */ |
| 204 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
| 205 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
| 206 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
| 207 | - if(isset($callback)){ |
|
| 208 | - if(\is_callable($callback)){ |
|
| 209 | - $callback($object,$instance); |
|
| 204 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
| 205 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
| 206 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
| 207 | + if (isset($callback)) { |
|
| 208 | + if (\is_callable($callback)) { |
|
| 209 | + $callback($object, $instance); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | - if($object instanceof HtmlSemDoubleElement){ |
|
| 213 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
| 212 | + if ($object instanceof HtmlSemDoubleElement) { |
|
| 213 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
| 214 | 214 | } |
| 215 | 215 | return $object; |
| 216 | 216 | }; |
@@ -221,8 +221,8 @@ discard block |
||
| 221 | 221 | * @param string $caption |
| 222 | 222 | * @return HtmlButton |
| 223 | 223 | */ |
| 224 | - private function getFieldButton($caption){ |
|
| 225 | - return new HtmlButton("",$caption); |
|
| 224 | + private function getFieldButton($caption) { |
|
| 225 | + return new HtmlButton("", $caption); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * @param callable $callback |
| 232 | 232 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 233 | 233 | */ |
| 234 | - public function addFieldButton($caption,$callback=null){ |
|
| 235 | - $this->addField($this->getCallable("getFieldButton",[$caption],$callback)); |
|
| 234 | + public function addFieldButton($caption, $callback=null) { |
|
| 235 | + $this->addField($this->getCallable("getFieldButton", [$caption], $callback)); |
|
| 236 | 236 | return $this; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -243,8 +243,8 @@ discard block |
||
| 243 | 243 | * @param callable $callback |
| 244 | 244 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 245 | 245 | */ |
| 246 | - public function insertFieldButton($index,$caption,$callback=null){ |
|
| 247 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$callback)); |
|
| 246 | + public function insertFieldButton($index, $caption, $callback=null) { |
|
| 247 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $callback)); |
|
| 248 | 248 | return $this; |
| 249 | 249 | } |
| 250 | 250 | |
@@ -255,60 +255,60 @@ discard block |
||
| 255 | 255 | * @param callable $callback |
| 256 | 256 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 257 | 257 | */ |
| 258 | - public function insertInFieldButton($index,$caption,$callback=null){ |
|
| 259 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$callback)); |
|
| 258 | + public function insertInFieldButton($index, $caption, $callback=null) { |
|
| 259 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $callback)); |
|
| 260 | 260 | return $this; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - private function addDefaultButton($icon,$class=null,$callback=null){ |
|
| 264 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class],$callback)); |
|
| 263 | + private function addDefaultButton($icon, $class=null, $callback=null) { |
|
| 264 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class], $callback)); |
|
| 265 | 265 | return $this; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - private function insertDefaultButtonIn($index,$icon,$class=null,$callback=null){ |
|
| 269 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class],$callback)); |
|
| 268 | + private function insertDefaultButtonIn($index, $icon, $class=null, $callback=null) { |
|
| 269 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class], $callback)); |
|
| 270 | 270 | return $this; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - private function getDefaultButton($icon,$class=null){ |
|
| 273 | + private function getDefaultButton($icon, $class=null) { |
|
| 274 | 274 | $bt=$this->getFieldButton(""); |
| 275 | 275 | $bt->asIcon($icon); |
| 276 | - if(isset($class)) |
|
| 276 | + if (isset($class)) |
|
| 277 | 277 | $bt->addToProperty("class", $class); |
| 278 | 278 | return $bt; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - public function addDeleteButton($callback=null){ |
|
| 282 | - return $this->addDefaultButton("remove","delete red basic",$callback); |
|
| 281 | + public function addDeleteButton($callback=null) { |
|
| 282 | + return $this->addDefaultButton("remove", "delete red basic", $callback); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - public function addEditButton($callback=null){ |
|
| 286 | - return $this->addDefaultButton("edit","edit basic",$callback); |
|
| 285 | + public function addEditButton($callback=null) { |
|
| 286 | + return $this->addDefaultButton("edit", "edit basic", $callback); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - public function addEditDeleteButtons($callbackEdit=null,$callbackDelete=null){ |
|
| 289 | + public function addEditDeleteButtons($callbackEdit=null, $callbackDelete=null) { |
|
| 290 | 290 | $this->addEditButton($callbackEdit); |
| 291 | 291 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
| 292 | - $this->insertDeleteButtonIn($index,$callbackDelete); |
|
| 292 | + $this->insertDeleteButtonIn($index, $callbackDelete); |
|
| 293 | 293 | return $this; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - public function insertDeleteButtonIn($index,$callback=null){ |
|
| 297 | - return $this->insertDefaultButtonIn($index,"remove","delete red basic",$callback); |
|
| 296 | + public function insertDeleteButtonIn($index, $callback=null) { |
|
| 297 | + return $this->insertDefaultButtonIn($index, "remove", "delete red basic", $callback); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - public function insertEditButtonIn($index,$callback=null){ |
|
| 301 | - return $this->insertDefaultButtonIn($index,"edit","edit basic",$callback); |
|
| 300 | + public function insertEditButtonIn($index, $callback=null) { |
|
| 301 | + return $this->insertDefaultButtonIn($index, "edit", "edit basic", $callback); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
| 304 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 305 | 305 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - public function getSearchField(){ |
|
| 309 | - if(isset($this->_searchField)===false){ |
|
| 310 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
| 311 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
| 308 | + public function getSearchField() { |
|
| 309 | + if (isset($this->_searchField)===false) { |
|
| 310 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 311 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
| 312 | 312 | } |
| 313 | 313 | return $this->_searchField; |
| 314 | 314 | } |
@@ -36,28 +36,28 @@ discard block |
||
| 36 | 36 | protected $_edition; |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 39 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 40 | 40 | parent::__construct($identifier); |
| 41 | 41 | $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
| 42 | 42 | $this->setModel($model); |
| 43 | - if(isset($modelInstance)); |
|
| 43 | + if (isset($modelInstance)); |
|
| 44 | 44 | $this->show($modelInstance); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - protected function _init($instanceViewer,$contentKey,$content,$edition){ |
|
| 47 | + protected function _init($instanceViewer, $contentKey, $content, $edition) { |
|
| 48 | 48 | $this->_instanceViewer=$instanceViewer; |
| 49 | 49 | $this->content=[$contentKey=>$content]; |
| 50 | 50 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
| 51 | 51 | $this->_edition=$edition; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - protected function _getFieldIdentifier($prefix){ |
|
| 54 | + protected function _getFieldIdentifier($prefix) { |
|
| 55 | 55 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
| 58 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
| 59 | 59 | |
| 60 | - public function show($modelInstance){ |
|
| 60 | + public function show($modelInstance) { |
|
| 61 | 61 | $this->_modelInstance=$modelInstance; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -81,42 +81,42 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | abstract public function getHtmlComponent(); |
| 83 | 83 | |
| 84 | - public function setColor($color){ |
|
| 84 | + public function setColor($color) { |
|
| 85 | 85 | return $this->getHtmlComponent()->setColor($color); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
| 89 | - public function setCaptions($captions){ |
|
| 89 | + public function setCaptions($captions) { |
|
| 90 | 90 | $this->_instanceViewer->setCaptions($captions); |
| 91 | 91 | return $this; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public function setFields($fields){ |
|
| 94 | + public function setFields($fields) { |
|
| 95 | 95 | $this->_instanceViewer->setVisibleProperties($fields); |
| 96 | 96 | return $this; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - public function addField($field){ |
|
| 99 | + public function addField($field) { |
|
| 100 | 100 | $this->_instanceViewer->addField($field); |
| 101 | 101 | return $this; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function insertField($index,$field){ |
|
| 104 | + public function insertField($index, $field) { |
|
| 105 | 105 | $this->_instanceViewer->insertField($index, $field); |
| 106 | 106 | return $this; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function insertInField($index,$field){ |
|
| 109 | + public function insertInField($index, $field) { |
|
| 110 | 110 | $this->_instanceViewer->insertInField($index, $field); |
| 111 | 111 | return $this; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function setValueFunction($index,$callback){ |
|
| 114 | + public function setValueFunction($index, $callback) { |
|
| 115 | 115 | $this->_instanceViewer->setValueFunction($index, $callback); |
| 116 | 116 | return $this; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - public function setIdentifierFunction($callback){ |
|
| 119 | + public function setIdentifierFunction($callback) { |
|
| 120 | 120 | $this->_instanceViewer->setIdentifierFunction($callback); |
| 121 | 121 | return $this; |
| 122 | 122 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | /** |
| 125 | 125 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
| 126 | 126 | */ |
| 127 | - public function getToolbar(){ |
|
| 128 | - if(isset($this->_toolbar)===false){ |
|
| 127 | + public function getToolbar() { |
|
| 128 | + if (isset($this->_toolbar)===false) { |
|
| 129 | 129 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
| 130 | 130 | //$this->_toolbar->setSecondary(); |
| 131 | 131 | } |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | * @param callable $callback function to call on $element |
| 139 | 139 | * @return \Ajax\common\html\HtmlDoubleElement |
| 140 | 140 | */ |
| 141 | - public function addInToolbar($element,$callback=NULL){ |
|
| 141 | + public function addInToolbar($element, $callback=NULL) { |
|
| 142 | 142 | $tb=$this->getToolbar(); |
| 143 | - if(isset($callback)){ |
|
| 144 | - if(\is_callable($callback)){ |
|
| 143 | + if (isset($callback)) { |
|
| 144 | + if (\is_callable($callback)) { |
|
| 145 | 145 | $callback($element); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | * @param callable $callback function($element) |
| 155 | 155 | * @return \Ajax\common\html\HtmlDoubleElement |
| 156 | 156 | */ |
| 157 | - public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
| 158 | - $result=$this->addInToolbar($caption,$callback); |
|
| 159 | - if(isset($icon)) |
|
| 157 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
| 158 | + $result=$this->addInToolbar($caption, $callback); |
|
| 159 | + if (isset($icon)) |
|
| 160 | 160 | $result->addIcon($icon); |
| 161 | 161 | return $result; |
| 162 | 162 | } |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | * @param callable $callback function($element) |
| 167 | 167 | * @return \Ajax\common\Widget |
| 168 | 168 | */ |
| 169 | - public function addItemsInToolbar(array $items,$callback=NULL){ |
|
| 170 | - if(JArray::isAssociative($items)){ |
|
| 171 | - foreach ($items as $icon=>$item){ |
|
| 172 | - $this->addItemInToolbar($item,$icon,$callback); |
|
| 169 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
| 170 | + if (JArray::isAssociative($items)) { |
|
| 171 | + foreach ($items as $icon=>$item) { |
|
| 172 | + $this->addItemInToolbar($item, $icon, $callback); |
|
| 173 | 173 | } |
| 174 | - }else{ |
|
| 175 | - foreach ($items as $item){ |
|
| 176 | - $this->addItemInToolbar($item,null,$callback); |
|
| 174 | + } else { |
|
| 175 | + foreach ($items as $item) { |
|
| 176 | + $this->addItemInToolbar($item, null, $callback); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | return $this; |
@@ -185,12 +185,12 @@ discard block |
||
| 185 | 185 | * @param callable $callback function($element) |
| 186 | 186 | * @return \Ajax\common\html\HtmlDoubleElement |
| 187 | 187 | */ |
| 188 | - public function addDropdownInToolbar($value,$items=NULL,$callback=NULL){ |
|
| 188 | + public function addDropdownInToolbar($value, $items=NULL, $callback=NULL) { |
|
| 189 | 189 | $dd=$value; |
| 190 | 190 | if (\is_string($value)) { |
| 191 | - $dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
| 191 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
| 192 | 192 | } |
| 193 | - return $this->addInToolbar($dd,$callback); |
|
| 193 | + return $this->addInToolbar($dd, $callback); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -198,9 +198,9 @@ discard block |
||
| 198 | 198 | * @param callable $callback function($element) |
| 199 | 199 | * @return \Ajax\common\html\HtmlDoubleElement |
| 200 | 200 | */ |
| 201 | - public function addButtonInToolbar($caption,$callback=NULL){ |
|
| 202 | - $bt=new HtmlButton("",$caption); |
|
| 203 | - return $this->addInToolbar($bt,$callback); |
|
| 201 | + public function addButtonInToolbar($caption, $callback=NULL) { |
|
| 202 | + $bt=new HtmlButton("", $caption); |
|
| 203 | + return $this->addInToolbar($bt, $callback); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | * @param callable $callback function($element) |
| 210 | 210 | * @return \Ajax\common\html\HtmlDoubleElement |
| 211 | 211 | */ |
| 212 | - public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
| 213 | - $bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
| 214 | - return $this->addInToolbar($bts,$callback); |
|
| 212 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
| 213 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
| 214 | + return $this->addInToolbar($bts, $callback); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -221,9 +221,9 @@ discard block |
||
| 221 | 221 | * @param boolean $labeled |
| 222 | 222 | * @return \Ajax\common\html\HtmlDoubleElement |
| 223 | 223 | */ |
| 224 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
| 225 | - $bt=new HtmlButton("",$caption); |
|
| 226 | - $bt->addIcon($icon,$before,$labeled); |
|
| 224 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
| 225 | + $bt=new HtmlButton("", $caption); |
|
| 226 | + $bt->addIcon($icon, $before, $labeled); |
|
| 227 | 227 | return $this->addInToolbar($bt); |
| 228 | 228 | } |
| 229 | 229 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * @param callable $defaultValueFunction |
| 254 | 254 | * @return \Ajax\common\Widget |
| 255 | 255 | */ |
| 256 | - public function setDefaultValueFunction($defaultValueFunction){ |
|
| 256 | + public function setDefaultValueFunction($defaultValueFunction) { |
|
| 257 | 257 | $this->_instanceViewer->setDefaultValueFunction($defaultValueFunction); |
| 258 | 258 | return $this; |
| 259 | 259 | } |
@@ -15,21 +15,21 @@ discard block |
||
| 15 | 15 | * @property object $_modelInstance |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -trait FormFieldAsTrait{ |
|
| 18 | +trait FormFieldAsTrait { |
|
| 19 | 19 | |
| 20 | 20 | abstract protected function _getFieldIdentifier($prefix); |
| 21 | - abstract public function setValueFunction($index,$callback); |
|
| 22 | - abstract protected function _applyAttributes($element,&$attributes,$index); |
|
| 21 | + abstract public function setValueFunction($index, $callback); |
|
| 22 | + abstract protected function _applyAttributes($element, &$attributes, $index); |
|
| 23 | 23 | |
| 24 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 25 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 24 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 25 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 26 | 26 | return $label; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - protected function _addRules($element,&$attributes){ |
|
| 30 | - if(isset($attributes["rules"])){ |
|
| 29 | + protected function _addRules($element, &$attributes) { |
|
| 30 | + if (isset($attributes["rules"])) { |
|
| 31 | 31 | $rules=$attributes["rules"]; |
| 32 | - if(\is_array($rules)){ |
|
| 32 | + if (\is_array($rules)) { |
|
| 33 | 33 | $element->addRules($rules); |
| 34 | 34 | } |
| 35 | 35 | else |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - protected function _fieldAs($elementCallback,$index,$attributes=NULL,$identifier=null){ |
|
| 42 | - $this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback){ |
|
| 41 | + protected function _fieldAs($elementCallback, $index, $attributes=NULL, $identifier=null) { |
|
| 42 | + $this->setValueFunction($index, function($value) use ($index, &$attributes, $elementCallback){ |
|
| 43 | 43 | $caption=$this->_instanceViewer->getCaption($index); |
| 44 | 44 | $name=$this->_instanceViewer->getFieldName($index); |
| 45 | - $element=$elementCallback($this->getIdentifier()."-".$name,$name,$value,$caption); |
|
| 46 | - if(\is_array($attributes)){ |
|
| 47 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 45 | + $element=$elementCallback($this->getIdentifier()."-".$name, $name, $value, $caption); |
|
| 46 | + if (\is_array($attributes)) { |
|
| 47 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 48 | 48 | } |
| 49 | 49 | return $element; |
| 50 | 50 | }); |
@@ -52,53 +52,53 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
| 55 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 56 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 57 | - return new HtmlFormRadio($id,$name,$caption,$value); |
|
| 58 | - }, $index,$attributes); |
|
| 55 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 56 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 57 | + return new HtmlFormRadio($id, $name, $caption, $value); |
|
| 58 | + }, $index, $attributes); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
| 62 | - return $this->_fieldAs(function($id,$name,$value,$caption,$elements){ |
|
| 63 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
| 64 | - }, $index,$attributes); |
|
| 61 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
| 62 | + return $this->_fieldAs(function($id, $name, $value, $caption, $elements) { |
|
| 63 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
| 64 | + }, $index, $attributes); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
| 68 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 69 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
| 67 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 68 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 69 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
| 70 | 70 | $textarea->setName($name); |
| 71 | 71 | return $textarea; |
| 72 | - }, $index,$attributes); |
|
| 72 | + }, $index, $attributes); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 76 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 77 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
| 75 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 76 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 77 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 78 | 78 | $input->setName($name); |
| 79 | 79 | return $input; |
| 80 | - }, $index,$attributes); |
|
| 80 | + }, $index, $attributes); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 84 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 85 | - return new HtmlFormCheckbox($id,$caption,$value); |
|
| 86 | - }, $index,$attributes); |
|
| 83 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 84 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 85 | + return new HtmlFormCheckbox($id, $caption, $value); |
|
| 86 | + }, $index, $attributes); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 90 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements,$multiple){ |
|
| 91 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value,$multiple); |
|
| 89 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 90 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements, $multiple){ |
|
| 91 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value, $multiple); |
|
| 92 | 92 | $dd->setName($name); |
| 93 | 93 | return $dd; |
| 94 | - }, $index,$attributes); |
|
| 94 | + }, $index, $attributes); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
| 98 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 99 | - $mess= new HtmlMessage("message-".$id,$value); |
|
| 97 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
| 98 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 99 | + $mess=new HtmlMessage("message-".$id, $value); |
|
| 100 | 100 | $mess->addHeader($caption); |
| 101 | 101 | return $mess; |
| 102 | - }, $index,$attributes,"message"); |
|
| 102 | + }, $index, $attributes, "message"); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | \ No newline at end of file |
@@ -9,41 +9,41 @@ |
||
| 9 | 9 | class FormInstanceViewer extends InstanceViewer { |
| 10 | 10 | protected $separators; |
| 11 | 11 | |
| 12 | - public function __construct($identifier,$instance=NULL, $captions=NULL) { |
|
| 13 | - parent::__construct($identifier,$instance=NULL, $captions=NULL); |
|
| 12 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
| 13 | + parent::__construct($identifier, $instance=NULL, $captions=NULL); |
|
| 14 | 14 | $this->separators=[-1]; |
| 15 | - $this->defaultValueFunction=function($name,$value,$index){ |
|
| 15 | + $this->defaultValueFunction=function($name, $value, $index) { |
|
| 16 | 16 | $caption=$this->getCaption($index); |
| 17 | - $input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value); |
|
| 17 | + $input=new HtmlFormInput($this->widgetIdentifier."-".$name, $caption, "text", $value); |
|
| 18 | 18 | $input->setName($name); |
| 19 | 19 | return $input; |
| 20 | 20 | }; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - protected function _beforeAddProperty($index,&$field){ |
|
| 24 | - if(JString::endswith($field, "\n")===true){ |
|
| 23 | + protected function _beforeAddProperty($index, &$field) { |
|
| 24 | + if (JString::endswith($field, "\n")===true) { |
|
| 25 | 25 | $this->addSeparatorAfter($index); |
| 26 | 26 | } |
| 27 | - if($index>1 && JString::startswith($field, "\n")===true){ |
|
| 27 | + if ($index>1 && JString::startswith($field, "\n")===true) { |
|
| 28 | 28 | $this->addSeparatorAfter($index-1); |
| 29 | 29 | } |
| 30 | 30 | $field=\str_replace("\n", "", $field); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function getFieldName($index){ |
|
| 33 | + public function getFieldName($index) { |
|
| 34 | 34 | $property=$this->getProperty($index); |
| 35 | - if($property instanceof \ReflectionProperty){ |
|
| 35 | + if ($property instanceof \ReflectionProperty) { |
|
| 36 | 36 | $result=$property->getName(); |
| 37 | - }elseif(\is_callable($property)){ |
|
| 37 | + }elseif (\is_callable($property)) { |
|
| 38 | 38 | $result=$this->visibleProperties[$index]; |
| 39 | - }else{ |
|
| 39 | + } else { |
|
| 40 | 40 | $result=$property; |
| 41 | 41 | } |
| 42 | 42 | return $result; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function addSeparatorAfter($fieldNum){ |
|
| 46 | - if(\array_search($fieldNum, $this->separators)===false) |
|
| 45 | + public function addSeparatorAfter($fieldNum) { |
|
| 46 | + if (\array_search($fieldNum, $this->separators)===false) |
|
| 47 | 47 | $this->separators[]=$fieldNum; |
| 48 | 48 | return $this; |
| 49 | 49 | } |
@@ -17,165 +17,165 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public static $index=0; |
| 19 | 19 | |
| 20 | - public function __construct($identifier,$instance=NULL,$captions=NULL){ |
|
| 20 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
| 21 | 21 | $this->widgetIdentifier=$identifier; |
| 22 | 22 | $this->values=[]; |
| 23 | 23 | $this->afterCompile=[]; |
| 24 | - if(isset($instance)) |
|
| 24 | + if (isset($instance)) |
|
| 25 | 25 | $this->setInstance($instance); |
| 26 | 26 | $this->setCaptions($captions); |
| 27 | 27 | $this->captionCallback=NULL; |
| 28 | - $this->defaultValueFunction=function($name,$value,$index){return $value;}; |
|
| 28 | + $this->defaultValueFunction=function($name, $value, $index) {return $value; }; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function getValues(){ |
|
| 31 | + public function getValues() { |
|
| 32 | 32 | $values=[]; |
| 33 | 33 | $index=0; |
| 34 | 34 | $count=$this->count(); |
| 35 | - while($index<$count){ |
|
| 35 | + while ($index<$count) { |
|
| 36 | 36 | $values[]=$this->getValue($index++); |
| 37 | 37 | } |
| 38 | 38 | return $values; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function getIdentifier(){ |
|
| 41 | + public function getIdentifier() { |
|
| 42 | 42 | $value=self::$index; |
| 43 | - if(isset($this->values["identifier"])) |
|
| 44 | - $value=$this->values["identifier"](self::$index,$this->instance); |
|
| 43 | + if (isset($this->values["identifier"])) |
|
| 44 | + $value=$this->values["identifier"](self::$index, $this->instance); |
|
| 45 | 45 | return $value; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function getValue($index){ |
|
| 48 | + public function getValue($index) { |
|
| 49 | 49 | $property=$this->properties[$index]; |
| 50 | 50 | return $this->_getValue($property, $index); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - protected function _beforeAddProperty($index,&$field){ |
|
| 53 | + protected function _beforeAddProperty($index, &$field) { |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - protected function _getDefaultValue($name,$value,$index){ |
|
| 57 | + protected function _getDefaultValue($name, $value, $index) { |
|
| 58 | 58 | $func=$this->defaultValueFunction; |
| 59 | - return $func($name,$value,$index); |
|
| 59 | + return $func($name, $value, $index); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - protected function _getValue($property,$index){ |
|
| 63 | - if($property instanceof \ReflectionProperty){ |
|
| 62 | + protected function _getValue($property, $index) { |
|
| 63 | + if ($property instanceof \ReflectionProperty) { |
|
| 64 | 64 | $property->setAccessible(true); |
| 65 | 65 | $value=$property->getValue($this->instance); |
| 66 | - if(isset($this->values[$index])){ |
|
| 67 | - $value= $this->values[$index]($value,$this->instance,$index); |
|
| 68 | - }else{ |
|
| 69 | - $value=$this->_getDefaultValue($property->getName(),$value, $index); |
|
| 66 | + if (isset($this->values[$index])) { |
|
| 67 | + $value=$this->values[$index]($value, $this->instance, $index); |
|
| 68 | + } else { |
|
| 69 | + $value=$this->_getDefaultValue($property->getName(), $value, $index); |
|
| 70 | 70 | } |
| 71 | - }else{ |
|
| 72 | - if(\is_callable($property)) |
|
| 71 | + } else { |
|
| 72 | + if (\is_callable($property)) |
|
| 73 | 73 | $value=$property($this->instance); |
| 74 | - elseif(\is_array($property)){ |
|
| 75 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
| 74 | + elseif (\is_array($property)) { |
|
| 75 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
| 76 | 76 | $value=\implode("", $values); |
| 77 | - }else{ |
|
| 78 | - if(isset($this->values[$index])){ |
|
| 79 | - $value= $this->values[$index]($property,$this->instance,$index); |
|
| 80 | - }else{ |
|
| 77 | + } else { |
|
| 78 | + if (isset($this->values[$index])) { |
|
| 79 | + $value=$this->values[$index]($property, $this->instance, $index); |
|
| 80 | + } else { |
|
| 81 | 81 | $value=$property; |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | - if(isset($this->afterCompile[$index])){ |
|
| 86 | - if(\is_callable($this->afterCompile[$index])){ |
|
| 87 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
| 85 | + if (isset($this->afterCompile[$index])) { |
|
| 86 | + if (\is_callable($this->afterCompile[$index])) { |
|
| 87 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | return $value; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public function insertField($index,$field){ |
|
| 94 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
| 93 | + public function insertField($index, $field) { |
|
| 94 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function insertInField($index,$field){ |
|
| 98 | + public function insertInField($index, $field) { |
|
| 99 | 99 | $vb=$this->visibleProperties; |
| 100 | - if(isset($vb[$index])){ |
|
| 101 | - if(\is_array($vb[$index])){ |
|
| 100 | + if (isset($vb[$index])) { |
|
| 101 | + if (\is_array($vb[$index])) { |
|
| 102 | 102 | $this->visibleProperties[$index][]=$field; |
| 103 | - }else{ |
|
| 104 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
| 103 | + } else { |
|
| 104 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
| 105 | 105 | } |
| 106 | - }else{ |
|
| 106 | + } else { |
|
| 107 | 107 | return $this->insertField($index, $field); |
| 108 | 108 | } |
| 109 | 109 | return $this; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public function addField($field){ |
|
| 112 | + public function addField($field) { |
|
| 113 | 113 | $this->visibleProperties[]=$field; |
| 114 | 114 | return $this; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - public function count(){ |
|
| 117 | + public function count() { |
|
| 118 | 118 | return \sizeof($this->properties); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public function visiblePropertiesCount(){ |
|
| 121 | + public function visiblePropertiesCount() { |
|
| 122 | 122 | return \sizeof($this->visibleProperties); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function getProperty($index){ |
|
| 125 | + public function getProperty($index) { |
|
| 126 | 126 | return $this->properties[$index]; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
| 130 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
| 129 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
| 130 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | public function setInstance($instance) { |
| 134 | - if(\is_string($instance)){ |
|
| 134 | + if (\is_string($instance)) { |
|
| 135 | 135 | $instance=new $instance(); |
| 136 | 136 | } |
| 137 | 137 | $this->instance=$instance; |
| 138 | 138 | $this->properties=[]; |
| 139 | 139 | $this->reflect=new \ReflectionClass($instance); |
| 140 | - if(\sizeof($this->visibleProperties)===0){ |
|
| 140 | + if (\sizeof($this->visibleProperties)===0) { |
|
| 141 | 141 | $this->properties=$this->getDefaultProperties(); |
| 142 | - }else{ |
|
| 143 | - foreach ($this->visibleProperties as $property){ |
|
| 142 | + } else { |
|
| 143 | + foreach ($this->visibleProperties as $property) { |
|
| 144 | 144 | $this->setInstanceProperty($property); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | return $this; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - private function setInstanceProperty($property){ |
|
| 151 | - if(\is_callable($property)){ |
|
| 150 | + private function setInstanceProperty($property) { |
|
| 151 | + if (\is_callable($property)) { |
|
| 152 | 152 | $this->properties[]=$property; |
| 153 | - }elseif(\is_string($property)){ |
|
| 154 | - try{ |
|
| 153 | + }elseif (\is_string($property)) { |
|
| 154 | + try { |
|
| 155 | 155 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 156 | 156 | $rProperty=$this->reflect->getProperty($property); |
| 157 | 157 | $this->properties[]=$rProperty; |
| 158 | - }catch(\Exception $e){ |
|
| 158 | + }catch (\Exception $e) { |
|
| 159 | 159 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 160 | 160 | $this->properties[]=$property; |
| 161 | 161 | } |
| 162 | - }elseif(\is_int($property)){ |
|
| 162 | + }elseif (\is_int($property)) { |
|
| 163 | 163 | $props=$this->getDefaultProperties(); |
| 164 | - if(isset($props[$property])) |
|
| 164 | + if (isset($props[$property])) |
|
| 165 | 165 | $this->properties[]=$props[$property]; |
| 166 | 166 | else |
| 167 | 167 | $this->properties[]=$property; |
| 168 | - }else{ |
|
| 168 | + } else { |
|
| 169 | 169 | $this->properties[]=$property; |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - protected function getDefaultProperties(){ |
|
| 173 | + protected function getDefaultProperties() { |
|
| 174 | 174 | $result=[]; |
| 175 | 175 | $properties=$this->reflect->getProperties(); |
| 176 | - foreach ($properties as $property){ |
|
| 176 | + foreach ($properties as $property) { |
|
| 177 | 177 | $showable=$this->showableProperty($property); |
| 178 | - if($showable!==false){ |
|
| 178 | + if ($showable!==false) { |
|
| 179 | 179 | $result[]=$property; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -187,12 +187,12 @@ discard block |
||
| 187 | 187 | return $this; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - public function setValueFunction($index,$callback){ |
|
| 190 | + public function setValueFunction($index, $callback) { |
|
| 191 | 191 | $this->values[$index]=$callback; |
| 192 | 192 | return $this; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - public function setIdentifierFunction($callback){ |
|
| 195 | + public function setIdentifierFunction($callback) { |
|
| 196 | 196 | $this->values["identifier"]=$callback; |
| 197 | 197 | return $this; |
| 198 | 198 | } |
@@ -205,41 +205,41 @@ discard block |
||
| 205 | 205 | return $this->properties; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - public function getCaption($index){ |
|
| 209 | - if(isset($this->captions[$index])){ |
|
| 208 | + public function getCaption($index) { |
|
| 209 | + if (isset($this->captions[$index])) { |
|
| 210 | 210 | return $this->captions[$index]; |
| 211 | 211 | } |
| 212 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 212 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
| 213 | 213 | return $this->properties[$index]->getName(); |
| 214 | - elseif(\is_callable($this->properties[$index])) |
|
| 214 | + elseif (\is_callable($this->properties[$index])) |
|
| 215 | 215 | return ""; |
| 216 | 216 | else |
| 217 | 217 | return $this->properties[$index]; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - public function getCaptions(){ |
|
| 221 | - if(isset($this->captions)){ |
|
| 222 | - $captions= $this->captions; |
|
| 223 | - for($i=\sizeof($captions);$i<$this->count();$i++){ |
|
| 220 | + public function getCaptions() { |
|
| 221 | + if (isset($this->captions)) { |
|
| 222 | + $captions=$this->captions; |
|
| 223 | + for ($i=\sizeof($captions); $i<$this->count(); $i++) { |
|
| 224 | 224 | $captions[]=""; |
| 225 | 225 | } |
| 226 | - }else{ |
|
| 226 | + } else { |
|
| 227 | 227 | $captions=[]; |
| 228 | 228 | $index=0; |
| 229 | 229 | $count=$this->count(); |
| 230 | - while($index<$count){ |
|
| 230 | + while ($index<$count) { |
|
| 231 | 231 | $captions[]=$this->getCaption($index++); |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
| 234 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
| 235 | 235 | $callback=$this->captionCallback; |
| 236 | - $callback($captions,$this->instance); |
|
| 236 | + $callback($captions, $this->instance); |
|
| 237 | 237 | } |
| 238 | 238 | return $captions; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - public function setCaption($index,$caption){ |
|
| 242 | - if(isset($this->captions)===false) |
|
| 241 | + public function setCaption($index, $caption) { |
|
| 242 | + if (isset($this->captions)===false) |
|
| 243 | 243 | $this->captions=[]; |
| 244 | 244 | $this->captions[$index]=$caption; |
| 245 | 245 | return $this; |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @param callable $callback function called after the field compilation |
| 258 | 258 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
| 259 | 259 | */ |
| 260 | - public function afterCompile($index,$callback){ |
|
| 260 | + public function afterCompile($index, $callback) { |
|
| 261 | 261 | $this->afterCompile[$index]=$callback; |
| 262 | 262 | return $this; |
| 263 | 263 | } |
@@ -17,43 +17,43 @@ discard block |
||
| 17 | 17 | * @property boolean $_edition |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -trait FieldAsTrait{ |
|
| 20 | +trait FieldAsTrait { |
|
| 21 | 21 | |
| 22 | 22 | abstract protected function _getFieldIdentifier($prefix); |
| 23 | - abstract public function setValueFunction($index,$callback); |
|
| 23 | + abstract public function setValueFunction($index, $callback); |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @param HtmlFormField $element |
| 27 | 27 | * @param array $attributes |
| 28 | 28 | */ |
| 29 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
| 29 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
| 30 | 30 | $this->_addRules($element, $attributes); |
| 31 | - if(isset($attributes["callback"])){ |
|
| 31 | + if (isset($attributes["callback"])) { |
|
| 32 | 32 | $callback=$attributes["callback"]; |
| 33 | - if(\is_callable($callback)){ |
|
| 34 | - $callback($element,$this->_modelInstance,$index); |
|
| 33 | + if (\is_callable($callback)) { |
|
| 34 | + $callback($element, $this->_modelInstance, $index); |
|
| 35 | 35 | unset($attributes["callback"]); |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | $element->fromArray($attributes); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 42 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 41 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 42 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 43 | 43 | return $label; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - protected function _addRules($element,&$attributes){} |
|
| 46 | + protected function _addRules($element, &$attributes) {} |
|
| 47 | 47 | |
| 48 | - protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
|
| 49 | - $this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback,$prefix){ |
|
| 48 | + protected function _fieldAs($elementCallback, $index, $attributes=NULL, $prefix=null) { |
|
| 49 | + $this->setValueFunction($index, function($value) use ($index, &$attributes, $elementCallback, $prefix){ |
|
| 50 | 50 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
| 51 | - if(isset($attributes["name"])){ |
|
| 51 | + if (isset($attributes["name"])) { |
|
| 52 | 52 | $name=$attributes["name"]; |
| 53 | 53 | } |
| 54 | - $element=$elementCallback($this->_getFieldIdentifier($prefix),$name,$value,""); |
|
| 55 | - if(\is_array($attributes)) |
|
| 56 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 54 | + $element=$elementCallback($this->_getFieldIdentifier($prefix), $name, $value, ""); |
|
| 55 | + if (\is_array($attributes)) |
|
| 56 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 57 | 57 | $element->setDisabled(!$this->_edition); |
| 58 | 58 | return $element; |
| 59 | 59 | }); |
@@ -61,94 +61,94 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
| 64 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
| 65 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
| 66 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
| 64 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 65 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
| 66 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 67 | 67 | return $pb; |
| 68 | 68 | }); |
| 69 | 69 | return $this; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
| 73 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
| 74 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
| 72 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 73 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
| 74 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 75 | 75 | return $rating; |
| 76 | 76 | }); |
| 77 | 77 | return $this; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function fieldAsLabel($index,$icon=NULL){ |
|
| 81 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
| 82 | - $lbl=$this->_getLabelField($caption,$icon); |
|
| 80 | + public function fieldAsLabel($index, $icon=NULL) { |
|
| 81 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
| 82 | + $lbl=$this->_getLabelField($caption, $icon); |
|
| 83 | 83 | return $lbl; |
| 84 | 84 | }); |
| 85 | 85 | return $this; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
| 89 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
| 90 | - $header=new HtmlHeader($id,$niveau,$value); |
|
| 91 | - if(isset($icon)) |
|
| 88 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
| 89 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
| 90 | + $header=new HtmlHeader($id, $niveau, $value); |
|
| 91 | + if (isset($icon)) |
|
| 92 | 92 | $header->asIcon($icon, $value); |
| 93 | 93 | return $header; |
| 94 | - }, $index,$attributes,"header"); |
|
| 94 | + }, $index, $attributes, "header"); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
| 98 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
| 99 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
| 100 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 98 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
| 99 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
| 100 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
| 101 | 101 | return $image; |
| 102 | 102 | }); |
| 103 | 103 | return $this; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
| 107 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 108 | - $img=new HtmlImage($id,$value); |
|
| 106 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 107 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 108 | + $img=new HtmlImage($id, $value); |
|
| 109 | 109 | $img->asAvatar(); |
| 110 | 110 | return $img; |
| 111 | - }, $index,$attributes,"avatar"); |
|
| 111 | + }, $index, $attributes, "avatar"); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 115 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 116 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
| 114 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 115 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 116 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
| 117 | 117 | return $input; |
| 118 | - }, $index,$attributes,"radio"); |
|
| 118 | + }, $index, $attributes, "radio"); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 122 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 123 | - $input= new HtmlInput($id,"text",$value); |
|
| 121 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 122 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 123 | + $input=new HtmlInput($id, "text", $value); |
|
| 124 | 124 | //TODO check getField |
| 125 | 125 | $input->setName($name); |
| 126 | 126 | return $input; |
| 127 | - }, $index,$attributes,"input"); |
|
| 127 | + }, $index, $attributes, "input"); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
| 131 | - if(\is_array($attributes)===false){ |
|
| 130 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
| 131 | + if (\is_array($attributes)===false) { |
|
| 132 | 132 | $attributes=[]; |
| 133 | 133 | } |
| 134 | 134 | $attributes["imputType"]="hidden"; |
| 135 | - return $this->fieldAsInput($index,$attributes); |
|
| 135 | + return $this->fieldAsInput($index, $attributes); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 139 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 140 | - $input=new HtmlCheckbox($id,"",$this->_instanceViewer->getIdentifier()); |
|
| 138 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 139 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 140 | + $input=new HtmlCheckbox($id, "", $this->_instanceViewer->getIdentifier()); |
|
| 141 | 141 | $input->setChecked(JString::isBooleanTrue($value)); |
| 142 | 142 | $input->getField()->setProperty("name", $name); |
| 143 | 143 | return $input; |
| 144 | - }, $index,$attributes,"ck"); |
|
| 144 | + }, $index, $attributes, "ck"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 148 | - return $this->_fieldAs(function($id,$name,$value) use($elements,$multiple){ |
|
| 149 | - $dd=new HtmlDropdown($id,$value,$elements); |
|
| 150 | - $dd->asSelect($name,$multiple); |
|
| 147 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 148 | + return $this->_fieldAs(function($id, $name, $value) use($elements, $multiple){ |
|
| 149 | + $dd=new HtmlDropdown($id, $value, $elements); |
|
| 150 | + $dd->asSelect($name, $multiple); |
|
| 151 | 151 | return $dd; |
| 152 | - }, $index,$attributes,"dd"); |
|
| 152 | + }, $index, $attributes, "dd"); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | \ No newline at end of file |