@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Ajax\semantic\html\collections\table\traits; |
| 3 | 3 | |
| 4 | -trait TableTrait{ |
|
| 4 | +trait TableTrait { |
|
| 5 | 5 | /** |
| 6 | 6 | * @return HtmlTable |
| 7 | 7 | */ |
| 8 | 8 | abstract protected function getTable(); |
| 9 | 9 | |
| 10 | - protected function addToPropertyTable($property,$value){ |
|
| 10 | + protected function addToPropertyTable($property, $value) { |
|
| 11 | 11 | return $this->getTable()->addToProperty($property, $value); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -18,15 +18,15 @@ discard block |
||
| 18 | 18 | public function setBasic($very=false) { |
| 19 | 19 | $table=$this->getTable(); |
| 20 | 20 | if ($very) |
| 21 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
| 22 | - return $table->addToPropertyCtrl("class", "basic", array ("basic" )); |
|
| 21 | + $table->addToPropertyCtrl("class", "very", array("very")); |
|
| 22 | + return $table->addToPropertyCtrl("class", "basic", array("basic")); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function setCompact($very=false) { |
| 26 | 26 | $table=$this->getTable(); |
| 27 | 27 | if ($very) |
| 28 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
| 29 | - return $table->addToPropertyCtrl("class", "compact", array ("compact" )); |
|
| 28 | + $table->addToPropertyCtrl("class", "very", array("very")); |
|
| 29 | + return $table->addToPropertyCtrl("class", "compact", array("compact")); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function setCollapsing() { |
@@ -17,15 +17,17 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function setBasic($very=false) { |
| 19 | 19 | $table=$this->getTable(); |
| 20 | - if ($very) |
|
| 21 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
| 20 | + if ($very) { |
|
| 21 | + $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
| 22 | + } |
|
| 22 | 23 | return $table->addToPropertyCtrl("class", "basic", array ("basic" )); |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | public function setCompact($very=false) { |
| 26 | 27 | $table=$this->getTable(); |
| 27 | - if ($very) |
|
| 28 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
| 28 | + if ($very) { |
|
| 29 | + $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
| 30 | + } |
|
| 29 | 31 | return $table->addToPropertyCtrl("class", "compact", array ("compact" )); |
| 30 | 32 | } |
| 31 | 33 | |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n"; |
| 7 | 7 | public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n"; |
| 8 | 8 | |
| 9 | - public static function containsCode($expression){ |
|
| 10 | - return strrpos($expression, 'this')!==false||strrpos($expression, 'event')!==false||strrpos($expression, 'self')!==false; |
|
| 9 | + public static function containsCode($expression) { |
|
| 10 | + return strrpos($expression, 'this')!==false || strrpos($expression, 'event')!==false || strrpos($expression, 'self')!==false; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public function setClass($classNames) { |
| 16 | - if(\is_array($classNames)){ |
|
| 16 | + if (\is_array($classNames)) { |
|
| 17 | 17 | $classNames=implode(" ", $classNames); |
| 18 | 18 | } |
| 19 | 19 | $this->setProperty("class", $classNames); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function addClass($classNames) { |
| 24 | - if(\is_array($classNames)){ |
|
| 24 | + if (\is_array($classNames)) { |
|
| 25 | 25 | $classNames=implode(" ", $classNames); |
| 26 | 26 | } |
| 27 | 27 | $this->addToProperty("class", $classNames); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function fromArray($array) { |
| 54 | 54 | $array=parent::fromArray($array); |
| 55 | - foreach ( $array as $key => $value ) { |
|
| 55 | + foreach ($array as $key => $value) { |
|
| 56 | 56 | $this->setProperty($key, $value); |
| 57 | 57 | } |
| 58 | 58 | return $array; |
@@ -8,7 +8,6 @@ |
||
| 8 | 8 | use Ajax\semantic\html\elements\HtmlInput; |
| 9 | 9 | use Ajax\semantic\html\collections\menus\HtmlPaginationMenu; |
| 10 | 10 | use Ajax\semantic\html\modules\checkbox\HtmlCheckbox; |
| 11 | -use Ajax\semantic\html\elements\HtmlButton; |
|
| 12 | 11 | use Ajax\semantic\html\base\constants\Direction; |
| 13 | 12 | use Ajax\service\JArray; |
| 14 | 13 | use Ajax\semantic\widgets\base\InstanceViewer; |
@@ -36,6 +36,10 @@ discard block |
||
| 36 | 36 | protected $_targetSelector; |
| 37 | 37 | protected $_checkedMessage; |
| 38 | 38 | |
| 39 | + /** |
|
| 40 | + * @param string $identifier |
|
| 41 | + * @param string $model |
|
| 42 | + */ |
|
| 39 | 43 | public function __construct($identifier,$model,$modelInstance=NULL) { |
| 40 | 44 | parent::__construct($identifier, $model,$modelInstance); |
| 41 | 45 | $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
@@ -75,6 +79,9 @@ discard block |
||
| 75 | 79 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
| 76 | 80 | } |
| 77 | 81 | |
| 82 | + /** |
|
| 83 | + * @param string $op |
|
| 84 | + */ |
|
| 78 | 85 | protected function _generateBehavior($op,JsUtils $js){ |
| 79 | 86 | if(isset($this->_urls[$op])) |
| 80 | 87 | $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),["attr"=>"data-ajax"]); |
@@ -210,6 +217,9 @@ discard block |
||
| 210 | 217 | return $this; |
| 211 | 218 | } |
| 212 | 219 | |
| 220 | + /** |
|
| 221 | + * @param PositionInTable $part |
|
| 222 | + */ |
|
| 213 | 223 | private function addToolbarRow($part,$table,$captions){ |
| 214 | 224 | $hasPart=$table->hasPart($part); |
| 215 | 225 | if($hasPart){ |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | */ |
| 25 | 25 | class DataTable extends Widget { |
| 26 | - use TableTrait,DataTableFieldAsTrait; |
|
| 26 | + use TableTrait, DataTableFieldAsTrait; |
|
| 27 | 27 | protected $_searchField; |
| 28 | 28 | protected $_urls; |
| 29 | 29 | protected $_pagination; |
@@ -36,30 +36,30 @@ discard block |
||
| 36 | 36 | protected $_targetSelector; |
| 37 | 37 | protected $_checkedMessage; |
| 38 | 38 | |
| 39 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 40 | - parent::__construct($identifier, $model,$modelInstance); |
|
| 41 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
| 39 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 40 | + parent::__construct($identifier, $model, $modelInstance); |
|
| 41 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
| 42 | 42 | $this->_urls=[]; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function run(JsUtils $js){ |
|
| 46 | - if($this->_hasCheckboxes && isset($js)){ |
|
| 45 | + public function run(JsUtils $js) { |
|
| 46 | + if ($this->_hasCheckboxes && isset($js)) { |
|
| 47 | 47 | $this->_runCheckboxes($js); |
| 48 | 48 | } |
| 49 | - if($this->_visibleHover){ |
|
| 50 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 51 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 49 | + if ($this->_visibleHover) { |
|
| 50 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 51 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 52 | 52 | } |
| 53 | - if($this->_hasDelete) |
|
| 53 | + if ($this->_hasDelete) |
|
| 54 | 54 | $this->_generateBehavior("delete", $js); |
| 55 | - if($this->_hasEdit) |
|
| 55 | + if ($this->_hasEdit) |
|
| 56 | 56 | $this->_generateBehavior("edit", $js); |
| 57 | 57 | return parent::run($js); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - protected function _runCheckboxes(JsUtils $js){ |
|
| 60 | + protected function _runCheckboxes(JsUtils $js) { |
|
| 61 | 61 | $checkedMessageCall=""; |
| 62 | - if($this->_hasCheckedMessage){ |
|
| 62 | + if ($this->_hasCheckedMessage) { |
|
| 63 | 63 | $msg=$this->getCheckedMessage(); |
| 64 | 64 | $checkedMessageFunction="function updateChecked(){var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length; |
| 65 | 65 | if(count==1) msg='".$msg[1]."'; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | \$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);}); |
| 68 | 68 | \$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);}\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();"; |
| 69 | 69 | $checkedMessageCall="updateChecked();"; |
| 70 | - $js->exec($checkedMessageFunction,true); |
|
| 70 | + $js->exec($checkedMessageFunction, true); |
|
| 71 | 71 | } |
| 72 | 72 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
| 73 | 73 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - protected function _generateBehavior($op,JsUtils $js){ |
|
| 79 | - if(isset($this->_urls[$op])) |
|
| 80 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),["attr"=>"data-ajax"]); |
|
| 78 | + protected function _generateBehavior($op, JsUtils $js) { |
|
| 79 | + if (isset($this->_urls[$op])) |
|
| 80 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), ["attr"=>"data-ajax"]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -89,70 +89,70 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 93 | - if(!$this->_generated){ |
|
| 92 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 93 | + if (!$this->_generated) { |
|
| 94 | 94 | $this->_instanceViewer->setInstance($this->_model); |
| 95 | 95 | $captions=$this->_instanceViewer->getCaptions(); |
| 96 | 96 | |
| 97 | 97 | $table=$this->content["table"]; |
| 98 | 98 | |
| 99 | - if($this->_hasCheckboxes){ |
|
| 99 | + if ($this->_hasCheckboxes) { |
|
| 100 | 100 | $this->_generateMainCheckbox($captions); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $table->setRowCount(0, \sizeof($captions)); |
| 104 | 104 | $table->setHeaderValues($captions); |
| 105 | - if(isset($this->_compileParts)) |
|
| 105 | + if (isset($this->_compileParts)) |
|
| 106 | 106 | $table->setCompileParts($this->_compileParts); |
| 107 | 107 | |
| 108 | - if(isset($this->_searchField) && isset($js)){ |
|
| 109 | - if(isset($this->_urls["refresh"])) |
|
| 110 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 108 | + if (isset($this->_searchField) && isset($js)) { |
|
| 109 | + if (isset($this->_urls["refresh"])) |
|
| 110 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $this->_generateContent($table); |
| 114 | 114 | |
| 115 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
| 115 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
| 116 | 116 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
| 119 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
| 120 | 120 | $this->_generatePagination($table); |
| 121 | 121 | } |
| 122 | - if(isset($this->_toolbar)){ |
|
| 122 | + if (isset($this->_toolbar)) { |
|
| 123 | 123 | $this->_setToolbarPosition($table, $captions); |
| 124 | 124 | } |
| 125 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
| 125 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
| 126 | 126 | $this->_compileForm(); |
| 127 | 127 | $this->_generated=true; |
| 128 | 128 | } |
| 129 | - return parent::compile($js,$view); |
|
| 129 | + return parent::compile($js, $view); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - private function _generateMainCheckbox(&$captions){ |
|
| 133 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
| 132 | + private function _generateMainCheckbox(&$captions) { |
|
| 133 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
| 134 | 134 | $checkedMessageCall=""; |
| 135 | - if($this->_hasCheckedMessage) |
|
| 135 | + if ($this->_hasCheckedMessage) |
|
| 136 | 136 | $checkedMessageCall="updateChecked();"; |
| 137 | 137 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);".$checkedMessageCall); |
| 138 | 138 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);".$checkedMessageCall); |
| 139 | 139 | \array_unshift($captions, $ck); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - protected function _generateContent($table){ |
|
| 142 | + protected function _generateContent($table) { |
|
| 143 | 143 | $objects=$this->_modelInstance; |
| 144 | - if(isset($this->_pagination)){ |
|
| 144 | + if (isset($this->_pagination)) { |
|
| 145 | 145 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
| 146 | 146 | } |
| 147 | 147 | InstanceViewer::setIndex(0); |
| 148 | 148 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
| 149 | 149 | $this->_instanceViewer->setInstance($instance); |
| 150 | 150 | InstanceViewer::$index++; |
| 151 | - $values= $this->_instanceViewer->getValues(); |
|
| 152 | - if($this->_hasCheckboxes){ |
|
| 153 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
| 151 | + $values=$this->_instanceViewer->getValues(); |
|
| 152 | + if ($this->_hasCheckboxes) { |
|
| 153 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
| 154 | 154 | $field=$ck->getField(); |
| 155 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
| 155 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
| 156 | 156 | $field->setProperty("name", "selection[]"); |
| 157 | 157 | \array_unshift($values, $ck); |
| 158 | 158 | } |
@@ -163,37 +163,37 @@ discard block |
||
| 163 | 163 | }); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - private function _generatePagination($table){ |
|
| 166 | + private function _generatePagination($table) { |
|
| 167 | 167 | $footer=$table->getFooter(); |
| 168 | 168 | $footer->mergeCol(); |
| 169 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
| 169 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
| 170 | 170 | $menu->floatRight(); |
| 171 | 171 | $menu->setActiveItem($this->_pagination->getPage()-1); |
| 172 | 172 | $footer->setValues($menu); |
| 173 | - if(isset($this->_urls["refresh"])) |
|
| 174 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 173 | + if (isset($this->_urls["refresh"])) |
|
| 174 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - protected function _getFieldName($index){ |
|
| 177 | + protected function _getFieldName($index) { |
|
| 178 | 178 | return parent::_getFieldName($index)."[]"; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - protected function _getFieldCaption($index){ |
|
| 181 | + protected function _getFieldCaption($index) { |
|
| 182 | 182 | return null; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
| 186 | - switch ($this->_toolbarPosition){ |
|
| 185 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 186 | + switch ($this->_toolbarPosition) { |
|
| 187 | 187 | case PositionInTable::BEFORETABLE: |
| 188 | 188 | case PositionInTable::AFTERTABLE: |
| 189 | - if(isset($this->_compileParts)===false){ |
|
| 189 | + if (isset($this->_compileParts)===false) { |
|
| 190 | 190 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 191 | 191 | } |
| 192 | 192 | break; |
| 193 | 193 | case PositionInTable::HEADER: |
| 194 | 194 | case PositionInTable::FOOTER: |
| 195 | 195 | case PositionInTable::BODY: |
| 196 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
| 196 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
| 197 | 197 | break; |
| 198 | 198 | } |
| 199 | 199 | } |
@@ -205,23 +205,23 @@ discard block |
||
| 205 | 205 | * @param callable $callback function called after the field compilation |
| 206 | 206 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 207 | 207 | */ |
| 208 | - public function afterCompile($index,$callback){ |
|
| 209 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
| 208 | + public function afterCompile($index, $callback) { |
|
| 209 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
| 210 | 210 | return $this; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - private function addToolbarRow($part,$table,$captions){ |
|
| 213 | + private function addToolbarRow($part, $table, $captions) { |
|
| 214 | 214 | $hasPart=$table->hasPart($part); |
| 215 | - if($hasPart){ |
|
| 215 | + if ($hasPart) { |
|
| 216 | 216 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 217 | - }else{ |
|
| 217 | + } else { |
|
| 218 | 218 | $row=$table->getPart($part)->getRow(0); |
| 219 | 219 | } |
| 220 | 220 | $row->mergeCol(); |
| 221 | 221 | $row->setValues([$this->_toolbar]); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - public function getHtmlComponent(){ |
|
| 224 | + public function getHtmlComponent() { |
|
| 225 | 225 | return $this->content["table"]; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -235,18 +235,18 @@ discard block |
||
| 235 | 235 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 236 | 236 | */ |
| 237 | 237 | public function setUrls($urls) { |
| 238 | - if(\is_array($urls)){ |
|
| 239 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
| 240 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
| 241 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
| 242 | - }else{ |
|
| 243 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
| 238 | + if (\is_array($urls)) { |
|
| 239 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 240 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 241 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 242 | + } else { |
|
| 243 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
| 244 | 244 | } |
| 245 | 245 | return $this; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - public function paginate($items_per_page=10,$page=1){ |
|
| 249 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
| 248 | + public function paginate($items_per_page=10, $page=1) { |
|
| 249 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function getHasCheckboxes() { |
@@ -258,20 +258,20 @@ discard block |
||
| 258 | 258 | return $this; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - public function refresh($compileParts=["tbody"]){ |
|
| 261 | + public function refresh($compileParts=["tbody"]) { |
|
| 262 | 262 | $this->_compileParts=$compileParts; |
| 263 | 263 | return $this; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
| 267 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
| 267 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 268 | 268 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - public function getSearchField(){ |
|
| 272 | - if(isset($this->_searchField)===false){ |
|
| 273 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
| 274 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
| 271 | + public function getSearchField() { |
|
| 272 | + if (isset($this->_searchField)===false) { |
|
| 273 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 274 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
| 275 | 275 | } |
| 276 | 276 | return $this->_searchField; |
| 277 | 277 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | return $this; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - public function asForm(){ |
|
| 290 | + public function asForm() { |
|
| 291 | 291 | return $this->getForm(); |
| 292 | 292 | } |
| 293 | 293 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | |
| 296 | 296 | protected function getTargetSelector() { |
| 297 | 297 | $result=$this->_targetSelector; |
| 298 | - if(!isset($result)) |
|
| 298 | + if (!isset($result)) |
|
| 299 | 299 | $result="#".$this->identifier; |
| 300 | 300 | return $result; |
| 301 | 301 | } |
@@ -311,9 +311,9 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | protected function getCheckedMessage() { |
| 314 | - $result= $this->_checkedMessage; |
|
| 315 | - if(!isset($result)){ |
|
| 316 | - $result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"]; |
|
| 314 | + $result=$this->_checkedMessage; |
|
| 315 | + if (!isset($result)) { |
|
| 316 | + $result=[0=>"none selected", 1=>"one item selected", "other"=>"{count} items selected"]; |
|
| 317 | 317 | } |
| 318 | 318 | return $result; |
| 319 | 319 | } |
@@ -333,14 +333,14 @@ discard block |
||
| 333 | 333 | * @param array $checkedMessage |
| 334 | 334 | * @param callable $callback |
| 335 | 335 | */ |
| 336 | - public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
|
| 337 | - if(isset($checkedMessage)) |
|
| 336 | + public function addCountCheckedInToolbar(array $checkedMessage=null, $callback=null) { |
|
| 337 | + if (isset($checkedMessage)) |
|
| 338 | 338 | $this->_checkedMessage=$checkedMessage; |
| 339 | 339 | $checkedMessage=$this->getCheckedMessage(); |
| 340 | 340 | $this->_hasCheckboxes=true; |
| 341 | 341 | $this->_hasCheckedMessage=true; |
| 342 | - $element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]); |
|
| 343 | - $this->addInToolbar($element,$callback); |
|
| 342 | + $element=new HtmlLabel("checked-count-".$this->identifier, $checkedMessage[0]); |
|
| 343 | + $this->addInToolbar($element, $callback); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -50,10 +50,12 @@ discard block |
||
| 50 | 50 | $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
| 51 | 51 | $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
| 52 | 52 | } |
| 53 | - if($this->_hasDelete) |
|
| 54 | - $this->_generateBehavior("delete", $js); |
|
| 55 | - if($this->_hasEdit) |
|
| 56 | - $this->_generateBehavior("edit", $js); |
|
| 53 | + if($this->_hasDelete) { |
|
| 54 | + $this->_generateBehavior("delete", $js); |
|
| 55 | + } |
|
| 56 | + if($this->_hasEdit) { |
|
| 57 | + $this->_generateBehavior("edit", $js); |
|
| 58 | + } |
|
| 57 | 59 | return parent::run($js); |
| 58 | 60 | } |
| 59 | 61 | |
@@ -76,8 +78,9 @@ discard block |
||
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | protected function _generateBehavior($op,JsUtils $js){ |
| 79 | - if(isset($this->_urls[$op])) |
|
| 80 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),["attr"=>"data-ajax"]); |
|
| 81 | + if(isset($this->_urls[$op])) { |
|
| 82 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),["attr"=>"data-ajax"]); |
|
| 83 | + } |
|
| 81 | 84 | } |
| 82 | 85 | |
| 83 | 86 | /** |
@@ -102,12 +105,14 @@ discard block |
||
| 102 | 105 | |
| 103 | 106 | $table->setRowCount(0, \sizeof($captions)); |
| 104 | 107 | $table->setHeaderValues($captions); |
| 105 | - if(isset($this->_compileParts)) |
|
| 106 | - $table->setCompileParts($this->_compileParts); |
|
| 108 | + if(isset($this->_compileParts)) { |
|
| 109 | + $table->setCompileParts($this->_compileParts); |
|
| 110 | + } |
|
| 107 | 111 | |
| 108 | 112 | if(isset($this->_searchField) && isset($js)){ |
| 109 | - if(isset($this->_urls["refresh"])) |
|
| 110 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 113 | + if(isset($this->_urls["refresh"])) { |
|
| 114 | + $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 115 | + } |
|
| 111 | 116 | } |
| 112 | 117 | |
| 113 | 118 | $this->_generateContent($table); |
@@ -132,8 +137,9 @@ discard block |
||
| 132 | 137 | private function _generateMainCheckbox(&$captions){ |
| 133 | 138 | $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
| 134 | 139 | $checkedMessageCall=""; |
| 135 | - if($this->_hasCheckedMessage) |
|
| 136 | - $checkedMessageCall="updateChecked();"; |
|
| 140 | + if($this->_hasCheckedMessage) { |
|
| 141 | + $checkedMessageCall="updateChecked();"; |
|
| 142 | + } |
|
| 137 | 143 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);".$checkedMessageCall); |
| 138 | 144 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);".$checkedMessageCall); |
| 139 | 145 | \array_unshift($captions, $ck); |
@@ -170,8 +176,9 @@ discard block |
||
| 170 | 176 | $menu->floatRight(); |
| 171 | 177 | $menu->setActiveItem($this->_pagination->getPage()-1); |
| 172 | 178 | $footer->setValues($menu); |
| 173 | - if(isset($this->_urls["refresh"])) |
|
| 174 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 179 | + if(isset($this->_urls["refresh"])) { |
|
| 180 | + $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 181 | + } |
|
| 175 | 182 | } |
| 176 | 183 | |
| 177 | 184 | protected function _getFieldName($index){ |
@@ -214,7 +221,7 @@ discard block |
||
| 214 | 221 | $hasPart=$table->hasPart($part); |
| 215 | 222 | if($hasPart){ |
| 216 | 223 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 217 | - }else{ |
|
| 224 | + } else{ |
|
| 218 | 225 | $row=$table->getPart($part)->getRow(0); |
| 219 | 226 | } |
| 220 | 227 | $row->mergeCol(); |
@@ -239,7 +246,7 @@ discard block |
||
| 239 | 246 | $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
| 240 | 247 | $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
| 241 | 248 | $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
| 242 | - }else{ |
|
| 249 | + } else{ |
|
| 243 | 250 | $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
| 244 | 251 | } |
| 245 | 252 | return $this; |
@@ -295,8 +302,9 @@ discard block |
||
| 295 | 302 | |
| 296 | 303 | protected function getTargetSelector() { |
| 297 | 304 | $result=$this->_targetSelector; |
| 298 | - if(!isset($result)) |
|
| 299 | - $result="#".$this->identifier; |
|
| 305 | + if(!isset($result)) { |
|
| 306 | + $result="#".$this->identifier; |
|
| 307 | + } |
|
| 300 | 308 | return $result; |
| 301 | 309 | } |
| 302 | 310 | |
@@ -334,8 +342,9 @@ discard block |
||
| 334 | 342 | * @param callable $callback |
| 335 | 343 | */ |
| 336 | 344 | public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
| 337 | - if(isset($checkedMessage)) |
|
| 338 | - $this->_checkedMessage=$checkedMessage; |
|
| 345 | + if(isset($checkedMessage)) { |
|
| 346 | + $this->_checkedMessage=$checkedMessage; |
|
| 347 | + } |
|
| 339 | 348 | $checkedMessage=$this->getCheckedMessage(); |
| 340 | 349 | $this->_hasCheckboxes=true; |
| 341 | 350 | $this->_hasCheckedMessage=true; |
@@ -12,15 +12,28 @@ discard block |
||
| 12 | 12 | * @property InstanceViewer $_instanceViewer |
| 13 | 13 | */ |
| 14 | 14 | trait DataTableFieldAsTrait{ |
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @param \Closure $field |
|
| 18 | + */ |
|
| 15 | 19 | abstract public function addField($field); |
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param integer $index |
|
| 23 | + * @param \Closure $field |
|
| 24 | + */ |
|
| 16 | 25 | abstract public function insertField($index,$field); |
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @param \Closure $field |
|
| 29 | + */ |
|
| 17 | 30 | abstract public function insertInField($index,$field); |
| 18 | 31 | abstract public function fieldAs($index,$type,$attributes=NULL); |
| 19 | 32 | /** |
| 20 | 33 | * @param string $caption |
| 21 | 34 | * @param callable $callback |
| 22 | 35 | * @param boolean $visibleHover |
| 23 | - * @return callable |
|
| 36 | + * @return \Closure |
|
| 24 | 37 | */ |
| 25 | 38 | private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
| 26 | 39 | return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
@@ -30,7 +43,7 @@ discard block |
||
| 30 | 43 | * @param callable $thisCallback |
| 31 | 44 | * @param array $parameters |
| 32 | 45 | * @param callable $callback |
| 33 | - * @return callable |
|
| 46 | + * @return \Closure |
|
| 34 | 47 | */ |
| 35 | 48 | private function getCallable($thisCallback,$parameters,$callback=null){ |
| 36 | 49 | $result=function($instance) use($thisCallback,$parameters,$callback){ |
@@ -82,6 +95,9 @@ discard block |
||
| 82 | 95 | }, $index,$attributes); |
| 83 | 96 | } |
| 84 | 97 | |
| 98 | + /** |
|
| 99 | + * @param HtmlButton $element |
|
| 100 | + */ |
|
| 85 | 101 | protected function _visibleOver($element){ |
| 86 | 102 | $this->_visibleHover=true; |
| 87 | 103 | return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
@@ -92,7 +108,7 @@ discard block |
||
| 92 | 108 | * @param string $caption |
| 93 | 109 | * @param callable $callback |
| 94 | 110 | * @param boolean $visibleHover |
| 95 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
| 111 | + * @return DataTableFieldAsTrait |
|
| 96 | 112 | */ |
| 97 | 113 | public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
| 98 | 114 | $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
@@ -104,7 +120,7 @@ discard block |
||
| 104 | 120 | * @param int $index |
| 105 | 121 | * @param string $caption |
| 106 | 122 | * @param callable $callback |
| 107 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
| 123 | + * @return DataTableFieldAsTrait |
|
| 108 | 124 | */ |
| 109 | 125 | public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
| 110 | 126 | $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
@@ -116,18 +132,26 @@ discard block |
||
| 116 | 132 | * @param int $index |
| 117 | 133 | * @param string $caption |
| 118 | 134 | * @param callable $callback |
| 119 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
| 135 | + * @return DataTableFieldAsTrait |
|
| 120 | 136 | */ |
| 121 | 137 | public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
| 122 | 138 | $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
| 123 | 139 | return $this; |
| 124 | 140 | } |
| 125 | 141 | |
| 142 | + /** |
|
| 143 | + * @param string $icon |
|
| 144 | + * @param string $class |
|
| 145 | + */ |
|
| 126 | 146 | private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
| 127 | 147 | $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
| 128 | 148 | return $this; |
| 129 | 149 | } |
| 130 | 150 | |
| 151 | + /** |
|
| 152 | + * @param string $icon |
|
| 153 | + * @param string $class |
|
| 154 | + */ |
|
| 131 | 155 | private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
| 132 | 156 | $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
| 133 | 157 | return $this; |
@@ -11,19 +11,19 @@ discard block |
||
| 11 | 11 | * @property boolean $_visibleHover |
| 12 | 12 | * @property InstanceViewer $_instanceViewer |
| 13 | 13 | */ |
| 14 | -trait DataTableFieldAsTrait{ |
|
| 14 | +trait DataTableFieldAsTrait { |
|
| 15 | 15 | abstract public function addField($field); |
| 16 | - abstract public function insertField($index,$field); |
|
| 17 | - abstract public function insertInField($index,$field); |
|
| 18 | - abstract public function fieldAs($index,$type,$attributes=NULL); |
|
| 16 | + abstract public function insertField($index, $field); |
|
| 17 | + abstract public function insertInField($index, $field); |
|
| 18 | + abstract public function fieldAs($index, $type, $attributes=NULL); |
|
| 19 | 19 | /** |
| 20 | 20 | * @param string $caption |
| 21 | 21 | * @param callable $callback |
| 22 | 22 | * @param boolean $visibleHover |
| 23 | 23 | * @return callable |
| 24 | 24 | */ |
| 25 | - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
|
| 26 | - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
|
| 25 | + private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) { |
|
| 26 | + return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | * @param callable $callback |
| 33 | 33 | * @return callable |
| 34 | 34 | */ |
| 35 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
| 36 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
| 37 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
| 38 | - if(isset($callback)){ |
|
| 39 | - if(\is_callable($callback)){ |
|
| 40 | - $callback($object,$instance); |
|
| 35 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
| 36 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
| 37 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
| 38 | + if (isset($callback)) { |
|
| 39 | + if (\is_callable($callback)) { |
|
| 40 | + $callback($object, $instance); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | - if($object instanceof HtmlSemDoubleElement){ |
|
| 44 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
| 45 | - if($object->propertyContains("class","visibleover")){ |
|
| 43 | + if ($object instanceof HtmlSemDoubleElement) { |
|
| 44 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
| 45 | + if ($object->propertyContains("class", "visibleover")) { |
|
| 46 | 46 | $this->_visibleHover=true; |
| 47 | - $object->setProperty("style","visibility:hidden;"); |
|
| 47 | + $object->setProperty("style", "visibility:hidden;"); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | return $object; |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @param string $caption |
| 57 | 57 | * @return HtmlButton |
| 58 | 58 | */ |
| 59 | - private function getFieldButton($caption,$visibleHover=true){ |
|
| 60 | - $bt= new HtmlButton("",$caption); |
|
| 61 | - if($visibleHover) |
|
| 59 | + private function getFieldButton($caption, $visibleHover=true) { |
|
| 60 | + $bt=new HtmlButton("", $caption); |
|
| 61 | + if ($visibleHover) |
|
| 62 | 62 | $this->_visibleOver($bt); |
| 63 | 63 | return $bt; |
| 64 | 64 | } |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
| 73 | 73 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 74 | 74 | */ |
| 75 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
| 76 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
|
| 77 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 78 | - $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
|
| 79 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 75 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 76 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $index, $attributes){ |
|
| 77 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 78 | + $button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]); |
|
| 79 | + if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 80 | 80 | $this->_visibleOver($button); |
| 81 | 81 | return $button; |
| 82 | - }, $index,$attributes); |
|
| 82 | + }, $index, $attributes); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - protected function _visibleOver($element){ |
|
| 85 | + protected function _visibleOver($element) { |
|
| 86 | 86 | $this->_visibleHover=true; |
| 87 | - return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
|
| 87 | + return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;"); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * @param boolean $visibleHover |
| 95 | 95 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 96 | 96 | */ |
| 97 | - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
|
| 98 | - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
|
| 97 | + public function addFieldButton($caption, $visibleHover=true, $callback=null) { |
|
| 98 | + $this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback)); |
|
| 99 | 99 | return $this; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | * @param callable $callback |
| 107 | 107 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 108 | 108 | */ |
| 109 | - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
| 110 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
| 109 | + public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
| 110 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
| 111 | 111 | return $this; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -118,25 +118,25 @@ discard block |
||
| 118 | 118 | * @param callable $callback |
| 119 | 119 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 120 | 120 | */ |
| 121 | - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
| 122 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
| 121 | + public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
| 122 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
| 123 | 123 | return $this; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
|
| 127 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
| 126 | + private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) { |
|
| 127 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
| 128 | 128 | return $this; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
|
| 132 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
| 131 | + private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) { |
|
| 132 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
| 133 | 133 | return $this; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
| 137 | - $bt=$this->getFieldButton("",$visibleHover); |
|
| 136 | + private function getDefaultButton($icon, $class=null, $visibleHover=true) { |
|
| 137 | + $bt=$this->getFieldButton("", $visibleHover); |
|
| 138 | 138 | $bt->asIcon($icon); |
| 139 | - if(isset($class)) |
|
| 139 | + if (isset($class)) |
|
| 140 | 140 | $bt->addClass($class); |
| 141 | 141 | return $bt; |
| 142 | 142 | } |
@@ -147,30 +147,30 @@ discard block |
||
| 147 | 147 | * @param callable $callback |
| 148 | 148 | * @return \Ajax\semantic\widgets\datatable\DataTableFieldAsTrait |
| 149 | 149 | */ |
| 150 | - public function addDeleteButton($visibleHover=true,$generateBehavior=true,$callback=null){ |
|
| 150 | + public function addDeleteButton($visibleHover=true, $generateBehavior=true, $callback=null) { |
|
| 151 | 151 | $this->_hasDelete=$generateBehavior; |
| 152 | - return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback); |
|
| 152 | + return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public function addEditButton($visibleHover=true,$generateBehavior=true,$callback=null){ |
|
| 155 | + public function addEditButton($visibleHover=true, $generateBehavior=true, $callback=null) { |
|
| 156 | 156 | $this->_hasEdit=$generateBehavior; |
| 157 | - return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback); |
|
| 157 | + return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function addEditDeleteButtons($visibleHover=true,$generateBehavior=true,$callbackEdit=null,$callbackDelete=null){ |
|
| 161 | - $this->addEditButton($visibleHover,$generateBehavior,$callbackEdit); |
|
| 160 | + public function addEditDeleteButtons($visibleHover=true, $generateBehavior=true, $callbackEdit=null, $callbackDelete=null) { |
|
| 161 | + $this->addEditButton($visibleHover, $generateBehavior, $callbackEdit); |
|
| 162 | 162 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
| 163 | - $this->insertDeleteButtonIn($index,$visibleHover,$generateBehavior,$callbackDelete); |
|
| 163 | + $this->insertDeleteButtonIn($index, $visibleHover, $generateBehavior, $callbackDelete); |
|
| 164 | 164 | return $this; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function insertDeleteButtonIn($index,$visibleHover=true,$generateBehavior=true,$callback=null){ |
|
| 167 | + public function insertDeleteButtonIn($index, $visibleHover=true, $generateBehavior=true, $callback=null) { |
|
| 168 | 168 | $this->_hasDelete=$generateBehavior; |
| 169 | - return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback); |
|
| 169 | + return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function insertEditButtonIn($index,$visibleHover=true,$generateBehavior=true,$callback=null){ |
|
| 172 | + public function insertEditButtonIn($index, $visibleHover=true, $generateBehavior=true, $callback=null) { |
|
| 173 | 173 | $this->_hasEdit=$generateBehavior; |
| 174 | - return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback); |
|
| 174 | + return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | \ No newline at end of file |
@@ -58,8 +58,9 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | private function getFieldButton($caption,$visibleHover=true){ |
| 60 | 60 | $bt= new HtmlButton("",$caption); |
| 61 | - if($visibleHover) |
|
| 62 | - $this->_visibleOver($bt); |
|
| 61 | + if($visibleHover) { |
|
| 62 | + $this->_visibleOver($bt); |
|
| 63 | + } |
|
| 63 | 64 | return $bt; |
| 64 | 65 | } |
| 65 | 66 | |
@@ -76,8 +77,9 @@ discard block |
||
| 76 | 77 | return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
| 77 | 78 | $button=new HtmlButton($id,$value,$cssStyle); |
| 78 | 79 | $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
| 79 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 80 | - $this->_visibleOver($button); |
|
| 80 | + if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) { |
|
| 81 | + $this->_visibleOver($button); |
|
| 82 | + } |
|
| 81 | 83 | return $button; |
| 82 | 84 | }, $index,$attributes); |
| 83 | 85 | } |
@@ -136,8 +138,9 @@ discard block |
||
| 136 | 138 | private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
| 137 | 139 | $bt=$this->getFieldButton("",$visibleHover); |
| 138 | 140 | $bt->asIcon($icon); |
| 139 | - if(isset($class)) |
|
| 140 | - $bt->addClass($class); |
|
| 141 | + if(isset($class)) { |
|
| 142 | + $bt->addClass($class); |
|
| 143 | + } |
|
| 141 | 144 | return $bt; |
| 142 | 145 | } |
| 143 | 146 | |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | * @author jc |
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | -trait BaseHtmlPropertiesTrait{ |
|
| 11 | +trait BaseHtmlPropertiesTrait { |
|
| 12 | 12 | |
| 13 | - protected $properties=array (); |
|
| 13 | + protected $properties=array(); |
|
| 14 | 14 | abstract protected function ctrl($name, $value, $typeCtrl); |
| 15 | 15 | abstract protected function removeOldValues(&$oldValue, $allValues); |
| 16 | - abstract protected function _getElementBy($callback,$elements); |
|
| 16 | + abstract protected function _getElementBy($callback, $elements); |
|
| 17 | 17 | public function getProperties() { |
| 18 | 18 | return $this->properties; |
| 19 | 19 | } |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function addToProperty($name, $value, $separator=" ") { |
| 41 | 41 | if (\is_array($value)) { |
| 42 | - foreach ( $value as $v ) { |
|
| 42 | + foreach ($value as $v) { |
|
| 43 | 43 | $this->addToProperty($name, $v, $separator); |
| 44 | 44 | } |
| 45 | - } else if ($value !== "" && $this->propertyContains($name, $value) === false) { |
|
| 45 | + } else if ($value!=="" && $this->propertyContains($name, $value)===false) { |
|
| 46 | 46 | $v=@$this->properties[$name]; |
| 47 | - if (isset($v) && $v !== "") |
|
| 48 | - $v=$v . $separator . $value; |
|
| 47 | + if (isset($v) && $v!=="") |
|
| 48 | + $v=$v.$separator.$value; |
|
| 49 | 49 | else |
| 50 | 50 | $v=$value; |
| 51 | 51 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | public function addToPropertyCtrlCheck($name, $value, $typeCtrl) { |
| 86 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 86 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 87 | 87 | return $this->addToProperty($name, $value); |
| 88 | 88 | } |
| 89 | 89 | return $this; |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | protected function setPropertyCtrl($name, $value, $typeCtrl) { |
| 107 | - if ($this->ctrl($name, $value, $typeCtrl) === true) |
|
| 107 | + if ($this->ctrl($name, $value, $typeCtrl)===true) |
|
| 108 | 108 | return $this->setProperty($name, $value); |
| 109 | 109 | return $this; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - protected function getElementByPropertyValue($propertyName,$value, $elements) { |
|
| 113 | - return $this->_getElementBy(function($element) use ($propertyName,$value){return $element->propertyContains($propertyName, $value) === true;}, $elements); |
|
| 112 | + protected function getElementByPropertyValue($propertyName, $value, $elements) { |
|
| 113 | + return $this->_getElementBy(function($element) use ($propertyName, $value){return $element->propertyContains($propertyName, $value)===true; }, $elements); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | \ No newline at end of file |
@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function getProperty($name) { |
| 36 | - if (array_key_exists($name, $this->properties)) |
|
| 37 | - return $this->properties[$name]; |
|
| 36 | + if (array_key_exists($name, $this->properties)) { |
|
| 37 | + return $this->properties[$name]; |
|
| 38 | + } |
|
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | public function addToProperty($name, $value, $separator=" ") { |
@@ -44,10 +45,11 @@ discard block |
||
| 44 | 45 | } |
| 45 | 46 | } else if ($value !== "" && $this->propertyContains($name, $value) === false) { |
| 46 | 47 | $v=@$this->properties[$name]; |
| 47 | - if (isset($v) && $v !== "") |
|
| 48 | - $v=$v . $separator . $value; |
|
| 49 | - else |
|
| 50 | - $v=$value; |
|
| 48 | + if (isset($v) && $v !== "") { |
|
| 49 | + $v=$v . $separator . $value; |
|
| 50 | + } else { |
|
| 51 | + $v=$value; |
|
| 52 | + } |
|
| 51 | 53 | |
| 52 | 54 | return $this->setProperty($name, $v); |
| 53 | 55 | } |
@@ -70,8 +72,9 @@ discard block |
||
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | protected function addToPropertyUnique($name, $value, $typeCtrl) { |
| 73 | - if (@class_exists($typeCtrl, true)) |
|
| 74 | - $typeCtrl=$typeCtrl::getConstants(); |
|
| 75 | + if (@class_exists($typeCtrl, true)) { |
|
| 76 | + $typeCtrl=$typeCtrl::getConstants(); |
|
| 77 | + } |
|
| 75 | 78 | if (\is_array($typeCtrl)) { |
| 76 | 79 | $this->removeOldValues($this->properties[$name], $typeCtrl); |
| 77 | 80 | } |
@@ -90,8 +93,9 @@ discard block |
||
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | public function removeProperty($name) { |
| 93 | - if (\array_key_exists($name, $this->properties)) |
|
| 94 | - unset($this->properties[$name]); |
|
| 96 | + if (\array_key_exists($name, $this->properties)) { |
|
| 97 | + unset($this->properties[$name]); |
|
| 98 | + } |
|
| 95 | 99 | return $this; |
| 96 | 100 | } |
| 97 | 101 | |
@@ -104,8 +108,9 @@ discard block |
||
| 104 | 108 | } |
| 105 | 109 | |
| 106 | 110 | protected function setPropertyCtrl($name, $value, $typeCtrl) { |
| 107 | - if ($this->ctrl($name, $value, $typeCtrl) === true) |
|
| 108 | - return $this->setProperty($name, $value); |
|
| 111 | + if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 112 | + return $this->setProperty($name, $value); |
|
| 113 | + } |
|
| 109 | 114 | return $this; |
| 110 | 115 | } |
| 111 | 116 | |
@@ -55,6 +55,10 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | |
| 58 | + /** |
|
| 59 | + * @param string $name |
|
| 60 | + * @param string[] $typeCtrl |
|
| 61 | + */ |
|
| 58 | 62 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 59 | 63 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
| 60 | 64 | return $name=$value; |
@@ -72,6 +76,10 @@ discard block |
||
| 72 | 76 | |
| 73 | 77 | |
| 74 | 78 | |
| 79 | + /** |
|
| 80 | + * @param string $name |
|
| 81 | + * @param string[] $typeCtrl |
|
| 82 | + */ |
|
| 75 | 83 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 76 | 84 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
| 77 | 85 | if (\is_array($typeCtrl)) { |
@@ -82,6 +90,9 @@ discard block |
||
| 82 | 90 | return $this; |
| 83 | 91 | } |
| 84 | 92 | |
| 93 | + /** |
|
| 94 | + * @param string $name |
|
| 95 | + */ |
|
| 85 | 96 | protected function addToMember(&$name, $value, $separator=" ") { |
| 86 | 97 | $name=str_ireplace($value, "", $name) . $separator . $value; |
| 87 | 98 | return $this; |
@@ -94,6 +105,9 @@ discard block |
||
| 94 | 105 | $oldValue=trim($oldValue); |
| 95 | 106 | } |
| 96 | 107 | |
| 108 | + /** |
|
| 109 | + * @param \Closure $callback |
|
| 110 | + */ |
|
| 97 | 111 | protected function _getElementBy($callback,$elements){ |
| 98 | 112 | if (\is_array($elements)) { |
| 99 | 113 | $flag=false; |
@@ -99,15 +99,18 @@ discard block |
||
| 99 | 99 | $flag=false; |
| 100 | 100 | $index=0; |
| 101 | 101 | while ( !$flag && $index < sizeof($elements) ) { |
| 102 | - if ($elements[$index] instanceof BaseHtml) |
|
| 103 | - $flag=($callback($elements[$index])); |
|
| 102 | + if ($elements[$index] instanceof BaseHtml) { |
|
| 103 | + $flag=($callback($elements[$index])); |
|
| 104 | + } |
|
| 104 | 105 | $index++; |
| 105 | 106 | } |
| 106 | - if ($flag === true) |
|
| 107 | - return $elements[$index - 1]; |
|
| 107 | + if ($flag === true) { |
|
| 108 | + return $elements[$index - 1]; |
|
| 109 | + } |
|
| 108 | 110 | } elseif ($elements instanceof BaseHtml) { |
| 109 | - if ($callback($elements)) |
|
| 110 | - return $elements; |
|
| 111 | + if ($callback($elements)) { |
|
| 112 | + return $elements; |
|
| 113 | + } |
|
| 111 | 114 | } |
| 112 | 115 | return null; |
| 113 | 116 | } |
@@ -140,8 +143,9 @@ discard block |
||
| 140 | 143 | |
| 141 | 144 | public function fromArray($array) { |
| 142 | 145 | foreach ( $this as $key => $value ) { |
| 143 | - if(array_key_exists($key, $array)===true) |
|
| 144 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 146 | + if(array_key_exists($key, $array)===true) { |
|
| 147 | + $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 148 | + } |
|
| 145 | 149 | } |
| 146 | 150 | foreach ( $array as $key => $value ) { |
| 147 | 151 | if($this->_callSetter($key, $key, $value, $array)===false){ |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * @version 1.3 |
| 16 | 16 | */ |
| 17 | 17 | abstract class BaseHtml extends BaseWidget { |
| 18 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
| 18 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
| 19 | 19 | protected $_template; |
| 20 | 20 | protected $tagName; |
| 21 | - protected $_wrapBefore=array (); |
|
| 22 | - protected $_wrapAfter=array (); |
|
| 21 | + protected $_wrapBefore=array(); |
|
| 22 | + protected $_wrapAfter=array(); |
|
| 23 | 23 | protected $_bsComponent; |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | abstract public function run(JsUtils $js); |
| 31 | 31 | |
| 32 | - private function _callSetter($setter,$key,$value,&$array){ |
|
| 32 | + private function _callSetter($setter, $key, $value, &$array) { |
|
| 33 | 33 | $result=false; |
| 34 | 34 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
| 35 | 35 | try { |
| 36 | 36 | $this->$setter($value); |
| 37 | 37 | unset($array[$key]); |
| 38 | 38 | $result=true; |
| 39 | - } catch ( \Exception $e ) { |
|
| 39 | + }catch (\Exception $e) { |
|
| 40 | 40 | $result=false; |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | protected function getTemplate(JsUtils $js=NULL) { |
| 47 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 47 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | protected function ctrl($name, $value, $typeCtrl) { |
| 51 | 51 | if (\is_array($typeCtrl)) { |
| 52 | - if (array_search($value, $typeCtrl) === false) { |
|
| 53 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
| 52 | + if (array_search($value, $typeCtrl)===false) { |
|
| 53 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 54 | 54 | } |
| 55 | 55 | } else { |
| 56 | 56 | if (!$typeCtrl($value)) { |
| 57 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
| 57 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | return true; |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 66 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 66 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 67 | 67 | return $name=$value; |
| 68 | 68 | } |
| 69 | 69 | return $this; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
| 73 | 73 | if (\is_array($typeCtrl)) { |
| 74 | 74 | $this->removeOldValues($name, $typeCtrl); |
| 75 | - $name.=$separator . $value; |
|
| 75 | + $name.=$separator.$value; |
|
| 76 | 76 | } |
| 77 | 77 | return $this; |
| 78 | 78 | } |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 83 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 83 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 84 | 84 | if (\is_array($typeCtrl)) { |
| 85 | 85 | $this->removeOldValues($name, $typeCtrl); |
| 86 | 86 | } |
| 87 | - $name.=$separator . $value; |
|
| 87 | + $name.=$separator.$value; |
|
| 88 | 88 | } |
| 89 | 89 | return $this; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | protected function addToMember(&$name, $value, $separator=" ") { |
| 93 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
| 93 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
| 94 | 94 | return $this; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | $oldValue=trim($oldValue); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - protected function _getElementBy($callback,$elements){ |
|
| 104 | + protected function _getElementBy($callback, $elements) { |
|
| 105 | 105 | if (\is_array($elements)) { |
| 106 | 106 | $flag=false; |
| 107 | 107 | $index=0; |
| 108 | - while ( !$flag && $index < sizeof($elements) ) { |
|
| 108 | + while (!$flag && $index<sizeof($elements)) { |
|
| 109 | 109 | if ($elements[$index] instanceof BaseHtml) |
| 110 | 110 | $flag=($callback($elements[$index])); |
| 111 | 111 | $index++; |
| 112 | 112 | } |
| 113 | - if ($flag === true) |
|
| 114 | - return $elements[$index - 1]; |
|
| 113 | + if ($flag===true) |
|
| 114 | + return $elements[$index-1]; |
|
| 115 | 115 | } elseif ($elements instanceof BaseHtml) { |
| 116 | 116 | if ($callback($elements)) |
| 117 | 117 | return $elements; |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public function fromArray($array) { |
| 142 | - foreach ( $this as $key => $value ) { |
|
| 143 | - if(array_key_exists($key, $array)===true) |
|
| 144 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 142 | + foreach ($this as $key => $value) { |
|
| 143 | + if (array_key_exists($key, $array)===true) |
|
| 144 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
| 145 | 145 | } |
| 146 | - foreach ( $array as $key => $value ) { |
|
| 147 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
| 148 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
| 146 | + foreach ($array as $key => $value) { |
|
| 147 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
| 148 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | return $array; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | public function fromDatabaseObjects($objects, $function) { |
| 155 | 155 | if (isset($objects)) { |
| 156 | - foreach ( $objects as $object ) { |
|
| 156 | + foreach ($objects as $object) { |
|
| 157 | 157 | $this->fromDatabaseObject($object, $function); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | public function getElementById($identifier, $elements) { |
| 177 | - return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
| 177 | + return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function getBsComponent() { |
@@ -188,19 +188,19 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 190 | 190 | $result=$this->getTemplate($js); |
| 191 | - foreach ( $this as $key => $value ) { |
|
| 192 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
| 191 | + foreach ($this as $key => $value) { |
|
| 192 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
| 193 | 193 | if (\is_array($value)) { |
| 194 | 194 | $v=PropertyWrapper::wrap($value, $js); |
| 195 | 195 | } else { |
| 196 | 196 | $v=$value; |
| 197 | 197 | } |
| 198 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
| 198 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | if (isset($js)===true) { |
| 202 | 202 | $this->run($js); |
| 203 | - if (isset($view) === true) { |
|
| 203 | + if (isset($view)===true) { |
|
| 204 | 204 | $js->addViewElement($this->identifier, $result, $view); |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -17,186 +17,186 @@ 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){return $value;}; |
|
| 28 | + $this->defaultValueFunction=function($name, $value) {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($index=NULL){ |
|
| 42 | - if(!isset($index)) |
|
| 41 | + public function getIdentifier($index=NULL) { |
|
| 42 | + if (!isset($index)) |
|
| 43 | 43 | $index=self::$index; |
| 44 | 44 | $value=$index; |
| 45 | - if(isset($this->values["identifier"])) |
|
| 46 | - $value=$this->values["identifier"]($index,$this->instance); |
|
| 45 | + if (isset($this->values["identifier"])) |
|
| 46 | + $value=$this->values["identifier"]($index, $this->instance); |
|
| 47 | 47 | return $value; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public function getValue($index){ |
|
| 50 | + public function getValue($index) { |
|
| 51 | 51 | $property=$this->properties[$index]; |
| 52 | 52 | return $this->_getValue($property, $index); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - protected function _beforeAddProperty($index,&$field){ |
|
| 55 | + protected function _beforeAddProperty($index, &$field) { |
|
| 56 | 56 | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - protected function _getDefaultValue($name,$value,$index){ |
|
| 59 | + protected function _getDefaultValue($name, $value, $index) { |
|
| 60 | 60 | $func=$this->defaultValueFunction; |
| 61 | - return $func($name,$value,$index,$this->instance); |
|
| 61 | + return $func($name, $value, $index, $this->instance); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - protected function _getPropertyValue(\ReflectionProperty $property,$index){ |
|
| 64 | + protected function _getPropertyValue(\ReflectionProperty $property, $index) { |
|
| 65 | 65 | $property->setAccessible(true); |
| 66 | 66 | $value=$property->getValue($this->instance); |
| 67 | - if(isset($this->values[$index])){ |
|
| 68 | - $value= $this->values[$index]($value,$this->instance,$index); |
|
| 69 | - }else{ |
|
| 70 | - $value=$this->_getDefaultValue($property->getName(),$value, $index); |
|
| 67 | + if (isset($this->values[$index])) { |
|
| 68 | + $value=$this->values[$index]($value, $this->instance, $index); |
|
| 69 | + } else { |
|
| 70 | + $value=$this->_getDefaultValue($property->getName(), $value, $index); |
|
| 71 | 71 | } |
| 72 | 72 | return $value; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - protected function _getValue($property,$index){ |
|
| 75 | + protected function _getValue($property, $index) { |
|
| 76 | 76 | $value=null; |
| 77 | - if($property instanceof \ReflectionProperty){ |
|
| 77 | + if ($property instanceof \ReflectionProperty) { |
|
| 78 | 78 | $value=$this->_getPropertyValue($property, $index); |
| 79 | - }else{ |
|
| 80 | - if(\is_callable($property)) |
|
| 79 | + } else { |
|
| 80 | + if (\is_callable($property)) |
|
| 81 | 81 | $value=$property($this->instance); |
| 82 | - elseif(\is_array($property)){ |
|
| 83 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
| 82 | + elseif (\is_array($property)) { |
|
| 83 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
| 84 | 84 | $value=\implode("", $values); |
| 85 | - }else{ |
|
| 86 | - if(isset($this->values[$index])){ |
|
| 87 | - $value= $this->values[$index]($property,$this->instance,$index); |
|
| 88 | - }elseif(isset($this->instance->{$property})){ |
|
| 85 | + } else { |
|
| 86 | + if (isset($this->values[$index])) { |
|
| 87 | + $value=$this->values[$index]($property, $this->instance, $index); |
|
| 88 | + }elseif (isset($this->instance->{$property})) { |
|
| 89 | 89 | $value=$this->instance->{$property}; |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | - if(isset($this->afterCompile[$index])){ |
|
| 94 | - if(\is_callable($this->afterCompile[$index])){ |
|
| 95 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
| 93 | + if (isset($this->afterCompile[$index])) { |
|
| 94 | + if (\is_callable($this->afterCompile[$index])) { |
|
| 95 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | return $value; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function insertField($index,$field){ |
|
| 102 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
| 101 | + public function insertField($index, $field) { |
|
| 102 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
| 103 | 103 | return $this; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - public function insertInField($index,$field){ |
|
| 106 | + public function insertInField($index, $field) { |
|
| 107 | 107 | $vb=$this->visibleProperties; |
| 108 | - if(isset($vb[$index])){ |
|
| 109 | - if(\is_array($vb[$index])){ |
|
| 108 | + if (isset($vb[$index])) { |
|
| 109 | + if (\is_array($vb[$index])) { |
|
| 110 | 110 | $this->visibleProperties[$index][]=$field; |
| 111 | - }else{ |
|
| 112 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
| 111 | + } else { |
|
| 112 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
| 113 | 113 | } |
| 114 | - }else{ |
|
| 114 | + } else { |
|
| 115 | 115 | return $this->insertField($index, $field); |
| 116 | 116 | } |
| 117 | 117 | return $this; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - public function addField($field){ |
|
| 120 | + public function addField($field) { |
|
| 121 | 121 | $this->visibleProperties[]=$field; |
| 122 | 122 | return $this; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function count(){ |
|
| 125 | + public function count() { |
|
| 126 | 126 | return \sizeof($this->properties); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - public function visiblePropertiesCount(){ |
|
| 129 | + public function visiblePropertiesCount() { |
|
| 130 | 130 | return \sizeof($this->visibleProperties); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - public function getProperty($index){ |
|
| 133 | + public function getProperty($index) { |
|
| 134 | 134 | return $this->properties[$index]; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - public function getFieldName($index){ |
|
| 137 | + public function getFieldName($index) { |
|
| 138 | 138 | $property=$this->getProperty($index); |
| 139 | - if($property instanceof \ReflectionProperty){ |
|
| 139 | + if ($property instanceof \ReflectionProperty) { |
|
| 140 | 140 | $result=$property->getName(); |
| 141 | - }elseif(\is_callable($property)){ |
|
| 141 | + }elseif (\is_callable($property)) { |
|
| 142 | 142 | $result=$this->visibleProperties[$index]; |
| 143 | - }else{ |
|
| 143 | + } else { |
|
| 144 | 144 | $result=$property; |
| 145 | 145 | } |
| 146 | 146 | return $result; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
| 150 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
| 151 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
| 150 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
| 151 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | public function setInstance($instance) { |
| 155 | - if(\is_string($instance)){ |
|
| 155 | + if (\is_string($instance)) { |
|
| 156 | 156 | $instance=new $instance(); |
| 157 | 157 | } |
| 158 | 158 | $this->instance=$instance; |
| 159 | 159 | $this->properties=[]; |
| 160 | 160 | $this->reflect=new \ReflectionClass($instance); |
| 161 | - if(\sizeof($this->visibleProperties)===0){ |
|
| 161 | + if (\sizeof($this->visibleProperties)===0) { |
|
| 162 | 162 | $this->properties=$this->getDefaultProperties(); |
| 163 | - }else{ |
|
| 164 | - foreach ($this->visibleProperties as $property){ |
|
| 163 | + } else { |
|
| 164 | + foreach ($this->visibleProperties as $property) { |
|
| 165 | 165 | $this->setInstanceProperty($property); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | return $this; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - private function setInstanceProperty($property){ |
|
| 172 | - if(\is_callable($property)){ |
|
| 171 | + private function setInstanceProperty($property) { |
|
| 172 | + if (\is_callable($property)) { |
|
| 173 | 173 | $this->properties[]=$property; |
| 174 | - }elseif(\is_string($property)){ |
|
| 175 | - try{ |
|
| 174 | + }elseif (\is_string($property)) { |
|
| 175 | + try { |
|
| 176 | 176 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 177 | 177 | $rProperty=$this->reflect->getProperty($property); |
| 178 | 178 | $this->properties[]=$rProperty; |
| 179 | - }catch(\Exception $e){ |
|
| 179 | + }catch (\Exception $e) { |
|
| 180 | 180 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 181 | 181 | $this->properties[]=$property; |
| 182 | 182 | } |
| 183 | - }elseif(\is_int($property)){ |
|
| 183 | + }elseif (\is_int($property)) { |
|
| 184 | 184 | $props=$this->getDefaultProperties(); |
| 185 | - if(isset($props[$property])) |
|
| 185 | + if (isset($props[$property])) |
|
| 186 | 186 | $this->properties[]=$props[$property]; |
| 187 | 187 | else |
| 188 | 188 | $this->properties[]=$property; |
| 189 | - }else{ |
|
| 189 | + } else { |
|
| 190 | 190 | $this->properties[]=$property; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - protected function getDefaultProperties(){ |
|
| 194 | + protected function getDefaultProperties() { |
|
| 195 | 195 | $result=[]; |
| 196 | 196 | $properties=$this->reflect->getProperties(); |
| 197 | - foreach ($properties as $property){ |
|
| 197 | + foreach ($properties as $property) { |
|
| 198 | 198 | $showable=$this->showableProperty($property); |
| 199 | - if($showable!==false){ |
|
| 199 | + if ($showable!==false) { |
|
| 200 | 200 | $result[]=$property; |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -208,12 +208,12 @@ discard block |
||
| 208 | 208 | return $this; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public function setValueFunction($index,$callback){ |
|
| 211 | + public function setValueFunction($index, $callback) { |
|
| 212 | 212 | $this->values[$index]=$callback; |
| 213 | 213 | return $this; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - public function setIdentifierFunction($callback){ |
|
| 216 | + public function setIdentifierFunction($callback) { |
|
| 217 | 217 | $this->values["identifier"]=$callback; |
| 218 | 218 | return $this; |
| 219 | 219 | } |
@@ -226,41 +226,41 @@ discard block |
||
| 226 | 226 | return $this->properties; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - public function getCaption($index){ |
|
| 230 | - if(isset($this->captions[$index])){ |
|
| 229 | + public function getCaption($index) { |
|
| 230 | + if (isset($this->captions[$index])) { |
|
| 231 | 231 | return $this->captions[$index]; |
| 232 | 232 | } |
| 233 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 233 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
| 234 | 234 | return $this->properties[$index]->getName(); |
| 235 | - elseif(\is_callable($this->properties[$index])) |
|
| 235 | + elseif (\is_callable($this->properties[$index])) |
|
| 236 | 236 | return ""; |
| 237 | 237 | else |
| 238 | 238 | return $this->properties[$index]; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - public function getCaptions(){ |
|
| 242 | - if(isset($this->captions)){ |
|
| 243 | - $captions= $this->captions; |
|
| 244 | - for($i=\sizeof($captions);$i<$this->count();$i++){ |
|
| 241 | + public function getCaptions() { |
|
| 242 | + if (isset($this->captions)) { |
|
| 243 | + $captions=$this->captions; |
|
| 244 | + for ($i=\sizeof($captions); $i<$this->count(); $i++) { |
|
| 245 | 245 | $captions[]=""; |
| 246 | 246 | } |
| 247 | - }else{ |
|
| 247 | + } else { |
|
| 248 | 248 | $captions=[]; |
| 249 | 249 | $index=0; |
| 250 | 250 | $count=$this->count(); |
| 251 | - while($index<$count){ |
|
| 251 | + while ($index<$count) { |
|
| 252 | 252 | $captions[]=$this->getCaption($index++); |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
| 255 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
| 256 | 256 | $callback=$this->captionCallback; |
| 257 | - $callback($captions,$this->instance); |
|
| 257 | + $callback($captions, $this->instance); |
|
| 258 | 258 | } |
| 259 | 259 | return $captions; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - public function setCaption($index,$caption){ |
|
| 263 | - if(isset($this->captions)===false) |
|
| 262 | + public function setCaption($index, $caption) { |
|
| 263 | + if (isset($this->captions)===false) |
|
| 264 | 264 | $this->captions=[]; |
| 265 | 265 | $this->captions[$index]=$caption; |
| 266 | 266 | return $this; |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @param callable $callback function called after the field compilation |
| 279 | 279 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
| 280 | 280 | */ |
| 281 | - public function afterCompile($index,$callback){ |
|
| 281 | + public function afterCompile($index, $callback) { |
|
| 282 | 282 | $this->afterCompile[$index]=$callback; |
| 283 | 283 | return $this; |
| 284 | 284 | } |
@@ -21,8 +21,9 @@ discard block |
||
| 21 | 21 | $this->widgetIdentifier=$identifier; |
| 22 | 22 | $this->values=[]; |
| 23 | 23 | $this->afterCompile=[]; |
| 24 | - if(isset($instance)) |
|
| 25 | - $this->setInstance($instance); |
|
| 24 | + if(isset($instance)) { |
|
| 25 | + $this->setInstance($instance); |
|
| 26 | + } |
|
| 26 | 27 | $this->setCaptions($captions); |
| 27 | 28 | $this->captionCallback=NULL; |
| 28 | 29 | $this->defaultValueFunction=function($name,$value){return $value;}; |
@@ -39,11 +40,13 @@ discard block |
||
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | public function getIdentifier($index=NULL){ |
| 42 | - if(!isset($index)) |
|
| 43 | - $index=self::$index; |
|
| 43 | + if(!isset($index)) { |
|
| 44 | + $index=self::$index; |
|
| 45 | + } |
|
| 44 | 46 | $value=$index; |
| 45 | - if(isset($this->values["identifier"])) |
|
| 46 | - $value=$this->values["identifier"]($index,$this->instance); |
|
| 47 | + if(isset($this->values["identifier"])) { |
|
| 48 | + $value=$this->values["identifier"]($index,$this->instance); |
|
| 49 | + } |
|
| 47 | 50 | return $value; |
| 48 | 51 | } |
| 49 | 52 | |
@@ -66,7 +69,7 @@ discard block |
||
| 66 | 69 | $value=$property->getValue($this->instance); |
| 67 | 70 | if(isset($this->values[$index])){ |
| 68 | 71 | $value= $this->values[$index]($value,$this->instance,$index); |
| 69 | - }else{ |
|
| 72 | + } else{ |
|
| 70 | 73 | $value=$this->_getDefaultValue($property->getName(),$value, $index); |
| 71 | 74 | } |
| 72 | 75 | return $value; |
@@ -76,16 +79,16 @@ discard block |
||
| 76 | 79 | $value=null; |
| 77 | 80 | if($property instanceof \ReflectionProperty){ |
| 78 | 81 | $value=$this->_getPropertyValue($property, $index); |
| 79 | - }else{ |
|
| 80 | - if(\is_callable($property)) |
|
| 81 | - $value=$property($this->instance); |
|
| 82 | - elseif(\is_array($property)){ |
|
| 82 | + } else{ |
|
| 83 | + if(\is_callable($property)) { |
|
| 84 | + $value=$property($this->instance); |
|
| 85 | + } elseif(\is_array($property)){ |
|
| 83 | 86 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
| 84 | 87 | $value=\implode("", $values); |
| 85 | - }else{ |
|
| 88 | + } else{ |
|
| 86 | 89 | if(isset($this->values[$index])){ |
| 87 | 90 | $value= $this->values[$index]($property,$this->instance,$index); |
| 88 | - }elseif(isset($this->instance->{$property})){ |
|
| 91 | + } elseif(isset($this->instance->{$property})){ |
|
| 89 | 92 | $value=$this->instance->{$property}; |
| 90 | 93 | } |
| 91 | 94 | } |
@@ -108,10 +111,10 @@ discard block |
||
| 108 | 111 | if(isset($vb[$index])){ |
| 109 | 112 | if(\is_array($vb[$index])){ |
| 110 | 113 | $this->visibleProperties[$index][]=$field; |
| 111 | - }else{ |
|
| 114 | + } else{ |
|
| 112 | 115 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
| 113 | 116 | } |
| 114 | - }else{ |
|
| 117 | + } else{ |
|
| 115 | 118 | return $this->insertField($index, $field); |
| 116 | 119 | } |
| 117 | 120 | return $this; |
@@ -138,9 +141,9 @@ discard block |
||
| 138 | 141 | $property=$this->getProperty($index); |
| 139 | 142 | if($property instanceof \ReflectionProperty){ |
| 140 | 143 | $result=$property->getName(); |
| 141 | - }elseif(\is_callable($property)){ |
|
| 144 | + } elseif(\is_callable($property)){ |
|
| 142 | 145 | $result=$this->visibleProperties[$index]; |
| 143 | - }else{ |
|
| 146 | + } else{ |
|
| 144 | 147 | $result=$property; |
| 145 | 148 | } |
| 146 | 149 | return $result; |
@@ -160,7 +163,7 @@ discard block |
||
| 160 | 163 | $this->reflect=new \ReflectionClass($instance); |
| 161 | 164 | if(\sizeof($this->visibleProperties)===0){ |
| 162 | 165 | $this->properties=$this->getDefaultProperties(); |
| 163 | - }else{ |
|
| 166 | + } else{ |
|
| 164 | 167 | foreach ($this->visibleProperties as $property){ |
| 165 | 168 | $this->setInstanceProperty($property); |
| 166 | 169 | } |
@@ -171,22 +174,23 @@ discard block |
||
| 171 | 174 | private function setInstanceProperty($property){ |
| 172 | 175 | if(\is_callable($property)){ |
| 173 | 176 | $this->properties[]=$property; |
| 174 | - }elseif(\is_string($property)){ |
|
| 177 | + } elseif(\is_string($property)){ |
|
| 175 | 178 | try{ |
| 176 | 179 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 177 | 180 | $rProperty=$this->reflect->getProperty($property); |
| 178 | 181 | $this->properties[]=$rProperty; |
| 179 | - }catch(\Exception $e){ |
|
| 182 | + } catch(\Exception $e){ |
|
| 180 | 183 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 181 | 184 | $this->properties[]=$property; |
| 182 | 185 | } |
| 183 | - }elseif(\is_int($property)){ |
|
| 186 | + } elseif(\is_int($property)){ |
|
| 184 | 187 | $props=$this->getDefaultProperties(); |
| 185 | - if(isset($props[$property])) |
|
| 186 | - $this->properties[]=$props[$property]; |
|
| 187 | - else |
|
| 188 | - $this->properties[]=$property; |
|
| 189 | - }else{ |
|
| 188 | + if(isset($props[$property])) { |
|
| 189 | + $this->properties[]=$props[$property]; |
|
| 190 | + } else { |
|
| 191 | + $this->properties[]=$property; |
|
| 192 | + } |
|
| 193 | + } else{ |
|
| 190 | 194 | $this->properties[]=$property; |
| 191 | 195 | } |
| 192 | 196 | } |
@@ -230,12 +234,13 @@ discard block |
||
| 230 | 234 | if(isset($this->captions[$index])){ |
| 231 | 235 | return $this->captions[$index]; |
| 232 | 236 | } |
| 233 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 234 | - return $this->properties[$index]->getName(); |
|
| 235 | - elseif(\is_callable($this->properties[$index])) |
|
| 236 | - return ""; |
|
| 237 | - else |
|
| 238 | - return $this->properties[$index]; |
|
| 237 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
| 238 | + return $this->properties[$index]->getName(); |
|
| 239 | + } elseif(\is_callable($this->properties[$index])) { |
|
| 240 | + return ""; |
|
| 241 | + } else { |
|
| 242 | + return $this->properties[$index]; |
|
| 243 | + } |
|
| 239 | 244 | } |
| 240 | 245 | |
| 241 | 246 | public function getCaptions(){ |
@@ -244,7 +249,7 @@ discard block |
||
| 244 | 249 | for($i=\sizeof($captions);$i<$this->count();$i++){ |
| 245 | 250 | $captions[]=""; |
| 246 | 251 | } |
| 247 | - }else{ |
|
| 252 | + } else{ |
|
| 248 | 253 | $captions=[]; |
| 249 | 254 | $index=0; |
| 250 | 255 | $count=$this->count(); |
@@ -260,8 +265,9 @@ discard block |
||
| 260 | 265 | } |
| 261 | 266 | |
| 262 | 267 | public function setCaption($index,$caption){ |
| 263 | - if(isset($this->captions)===false) |
|
| 264 | - $this->captions=[]; |
|
| 268 | + if(isset($this->captions)===false) { |
|
| 269 | + $this->captions=[]; |
|
| 270 | + } |
|
| 265 | 271 | $this->captions[$index]=$caption; |
| 266 | 272 | return $this; |
| 267 | 273 | } |
@@ -53,6 +53,9 @@ discard block |
||
| 53 | 53 | $element->setStyle($value); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | + /** |
|
| 57 | + * @param HtmlDropdown $bt |
|
| 58 | + */ |
|
| 56 | 59 | private function dropdownAsButton($bt) { |
| 57 | 60 | $this->addExistingDropDown($bt); |
| 58 | 61 | $bt->setTagName("button"); |
@@ -81,6 +84,9 @@ discard block |
||
| 81 | 84 | return $result; |
| 82 | 85 | } |
| 83 | 86 | |
| 87 | + /** |
|
| 88 | + * @param integer $iid |
|
| 89 | + */ |
|
| 84 | 90 | private function _addArrayElement(array $element,$iid){ |
| 85 | 91 | if (array_key_exists("glyph", $element)) |
| 86 | 92 | $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @return HtmlButtongroups default : "" |
| 40 | 40 | */ |
| 41 | 41 | public function setSize($size) { |
| 42 | - foreach ( $this->elements as $element ) { |
|
| 42 | + foreach ($this->elements as $element) { |
|
| 43 | 43 | $element->setSize($size); |
| 44 | 44 | } |
| 45 | 45 | if (is_int($size)) { |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | public function setStyle($value) { |
| 52 | - foreach ( $this->elements as $element ) |
|
| 52 | + foreach ($this->elements as $element) |
|
| 53 | 53 | $element->setStyle($value); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -69,29 +69,29 @@ discard block |
||
| 69 | 69 | public function addElement($element) { |
| 70 | 70 | $result=$element; |
| 71 | 71 | $iid=sizeof($this->elements)+1; |
| 72 | - if (($element instanceof HtmlDropdown)||($element instanceof HtmlSplitbutton)) { |
|
| 72 | + if (($element instanceof HtmlDropdown) || ($element instanceof HtmlSplitbutton)) { |
|
| 73 | 73 | $this->addExistingDropDown($element); |
| 74 | 74 | } elseif (\is_array($element)) { |
| 75 | - $result=$this->_addArrayElement($element,$iid); |
|
| 75 | + $result=$this->_addArrayElement($element, $iid); |
|
| 76 | 76 | } elseif (is_string($element)) { |
| 77 | - $result=new HtmlButton($this->identifier."-button-".$iid,$element); |
|
| 77 | + $result=new HtmlButton($this->identifier."-button-".$iid, $element); |
|
| 78 | 78 | } |
| 79 | - if($result instanceof HtmlButton) |
|
| 79 | + if ($result instanceof HtmlButton) |
|
| 80 | 80 | $this->elements[]=$result; |
| 81 | 81 | return $result; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - private function _addArrayElement(array $element,$iid){ |
|
| 84 | + private function _addArrayElement(array $element, $iid) { |
|
| 85 | 85 | if (array_key_exists("glyph", $element)) |
| 86 | 86 | $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
| 87 | 87 | elseif (array_key_exists("btnCaption", $element)) { |
| 88 | 88 | if (array_key_exists("split", $element)) |
| 89 | 89 | $bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid); |
| 90 | - else{ |
|
| 90 | + else { |
|
| 91 | 91 | $bt=new HtmlDropdown($this->identifier."-dropdown-".$iid); |
| 92 | 92 | $this->dropdownAsButton($bt); |
| 93 | 93 | } |
| 94 | - } else{ |
|
| 94 | + } else { |
|
| 95 | 95 | $bt=new HtmlButton($this->identifier."-button-".$iid); |
| 96 | 96 | $bt->fromArray($element); |
| 97 | 97 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function addElements($elements) { |
| 102 | - foreach ( $elements as $element ) { |
|
| 102 | + foreach ($elements as $element) { |
|
| 103 | 103 | $this->addElement($element); |
| 104 | 104 | } |
| 105 | 105 | return $this; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } else |
| 120 | 120 | $value="btn-group-".$value; |
| 121 | 121 | if (strstr($value, "justified")) { |
| 122 | - foreach ( $this->elements as $element ) { |
|
| 122 | + foreach ($this->elements as $element) { |
|
| 123 | 123 | $element->wrap('<div class="btn-group" role="group">', '</div>'); |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @see \Ajax\bootstrap\html\base\BaseHtml::on() |
| 151 | 151 | */ |
| 152 | 152 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
| 153 | - foreach ( $this->elements as $element ) { |
|
| 153 | + foreach ($this->elements as $element) { |
|
| 154 | 154 | $element->on($event, $jsCode, $stopPropagation, $preventDefault); |
| 155 | 155 | } |
| 156 | 156 | return $this; |
@@ -49,8 +49,9 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | public function setStyle($value) { |
| 52 | - foreach ( $this->elements as $element ) |
|
| 53 | - $element->setStyle($value); |
|
| 52 | + foreach ( $this->elements as $element ) { |
|
| 53 | + $element->setStyle($value); |
|
| 54 | + } |
|
| 54 | 55 | } |
| 55 | 56 | |
| 56 | 57 | private function dropdownAsButton($bt) { |
@@ -76,18 +77,19 @@ discard block |
||
| 76 | 77 | } elseif (is_string($element)) { |
| 77 | 78 | $result=new HtmlButton($this->identifier."-button-".$iid,$element); |
| 78 | 79 | } |
| 79 | - if($result instanceof HtmlButton) |
|
| 80 | - $this->elements[]=$result; |
|
| 80 | + if($result instanceof HtmlButton) { |
|
| 81 | + $this->elements[]=$result; |
|
| 82 | + } |
|
| 81 | 83 | return $result; |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | private function _addArrayElement(array $element,$iid){ |
| 85 | - if (array_key_exists("glyph", $element)) |
|
| 86 | - $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
|
| 87 | - elseif (array_key_exists("btnCaption", $element)) { |
|
| 88 | - if (array_key_exists("split", $element)) |
|
| 89 | - $bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid); |
|
| 90 | - else{ |
|
| 87 | + if (array_key_exists("glyph", $element)) { |
|
| 88 | + $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
|
| 89 | + } elseif (array_key_exists("btnCaption", $element)) { |
|
| 90 | + if (array_key_exists("split", $element)) { |
|
| 91 | + $bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid); |
|
| 92 | + } else{ |
|
| 91 | 93 | $bt=new HtmlDropdown($this->identifier."-dropdown-".$iid); |
| 92 | 94 | $this->dropdownAsButton($bt); |
| 93 | 95 | } |
@@ -116,8 +118,9 @@ discard block |
||
| 116 | 118 | public function setAlignment($value) { |
| 117 | 119 | if (is_int($value)) { |
| 118 | 120 | $value=CssRef::alignment("btn-group")[$value]; |
| 119 | - } else |
|
| 120 | - $value="btn-group-".$value; |
|
| 121 | + } else { |
|
| 122 | + $value="btn-group-".$value; |
|
| 123 | + } |
|
| 121 | 124 | if (strstr($value, "justified")) { |
| 122 | 125 | foreach ( $this->elements as $element ) { |
| 123 | 126 | $element->wrap('<div class="btn-group" role="group">', '</div>'); |
@@ -132,9 +135,9 @@ discard block |
||
| 132 | 135 | * @return HtmlButton |
| 133 | 136 | */ |
| 134 | 137 | public function getElement($index) { |
| 135 | - if (is_int($index)) |
|
| 136 | - return $this->elements[$index]; |
|
| 137 | - else { |
|
| 138 | + if (is_int($index)) { |
|
| 139 | + return $this->elements[$index]; |
|
| 140 | + } else { |
|
| 138 | 141 | $elm=$this->getElementById($index, $this->elements); |
| 139 | 142 | return $elm; |
| 140 | 143 | } |