@@ -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 | protected $_compiled=false; |
| 25 | 25 | protected $_postCompile; |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | abstract public function run(JsUtils $js); |
| 34 | 34 | |
| 35 | - private function _callSetter($setter,$key,$value,&$array){ |
|
| 35 | + private function _callSetter($setter, $key, $value, &$array) { |
|
| 36 | 36 | $result=false; |
| 37 | 37 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
| 38 | 38 | try { |
| 39 | 39 | $this->$setter($value); |
| 40 | 40 | unset($array[$key]); |
| 41 | 41 | $result=true; |
| 42 | - } catch ( \Exception $e ) { |
|
| 42 | + }catch (\Exception $e) { |
|
| 43 | 43 | $result=false; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -47,17 +47,17 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | protected function getTemplate(JsUtils $js=NULL) { |
| 50 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 50 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | protected function ctrl($name, $value, $typeCtrl) { |
| 54 | 54 | if (\is_array($typeCtrl)) { |
| 55 | - if (array_search($value, $typeCtrl) === false) { |
|
| 56 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
| 55 | + if (array_search($value, $typeCtrl)===false) { |
|
| 56 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | 59 | if (!$typeCtrl($value)) { |
| 60 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
| 60 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | return true; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 69 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 69 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 70 | 70 | return $name=$value; |
| 71 | 71 | } |
| 72 | 72 | return $this; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
| 76 | 76 | if (\is_array($typeCtrl)) { |
| 77 | 77 | $this->removeOldValues($name, $typeCtrl); |
| 78 | - $name.=$separator . $value; |
|
| 78 | + $name.=$separator.$value; |
|
| 79 | 79 | } |
| 80 | 80 | return $this; |
| 81 | 81 | } |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 86 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 86 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 87 | 87 | if (\is_array($typeCtrl)) { |
| 88 | 88 | $this->removeOldValues($name, $typeCtrl); |
| 89 | 89 | } |
| 90 | - $name.=$separator . $value; |
|
| 90 | + $name.=$separator.$value; |
|
| 91 | 91 | } |
| 92 | 92 | return $this; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | protected function addToMember(&$name, $value, $separator=" ") { |
| 96 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
| 96 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
| 97 | 97 | return $this; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -104,18 +104,18 @@ discard block |
||
| 104 | 104 | $oldValue=trim($oldValue); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - protected function _getElementBy($callback,$elements){ |
|
| 107 | + protected function _getElementBy($callback, $elements) { |
|
| 108 | 108 | if (\is_array($elements)) { |
| 109 | 109 | $elements=\array_values($elements); |
| 110 | 110 | $flag=false; |
| 111 | 111 | $index=0; |
| 112 | - while ( !$flag && $index < sizeof($elements) ) { |
|
| 112 | + while (!$flag && $index<sizeof($elements)) { |
|
| 113 | 113 | if ($elements[$index] instanceof BaseHtml) |
| 114 | 114 | $flag=($callback($elements[$index])); |
| 115 | 115 | $index++; |
| 116 | 116 | } |
| 117 | - if ($flag === true) |
|
| 118 | - return $elements[$index - 1]; |
|
| 117 | + if ($flag===true) |
|
| 118 | + return $elements[$index-1]; |
|
| 119 | 119 | } elseif ($elements instanceof BaseHtml) { |
| 120 | 120 | if ($callback($elements)) |
| 121 | 121 | return $elements; |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | public function fromArray($array) { |
| 146 | - foreach ( $this as $key => $value ) { |
|
| 147 | - if(array_key_exists($key, $array)===true) |
|
| 148 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 146 | + foreach ($this as $key => $value) { |
|
| 147 | + if (array_key_exists($key, $array)===true) |
|
| 148 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
| 149 | 149 | } |
| 150 | - foreach ( $array as $key => $value ) { |
|
| 151 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
| 152 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
| 150 | + foreach ($array as $key => $value) { |
|
| 151 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
| 152 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | return $array; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | public function fromDatabaseObjects($objects, $function) { |
| 159 | 159 | if (isset($objects)) { |
| 160 | - foreach ( $objects as $object ) { |
|
| 160 | + foreach ($objects as $object) { |
|
| 161 | 161 | $this->fromDatabaseObject($object, $function); |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | public function getElementById($identifier, $elements) { |
| 181 | - return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
| 181 | + return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public function getBsComponent() { |
@@ -191,14 +191,14 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
| 194 | - if(!$this->_compiled){ |
|
| 195 | - if(isset($js)){ |
|
| 194 | + if (!$this->_compiled) { |
|
| 195 | + if (isset($js)) { |
|
| 196 | 196 | $beforeCompile=$js->getParam("beforeCompileHtml"); |
| 197 | - if(\is_callable($beforeCompile)){ |
|
| 198 | - $beforeCompile($this,$js,$view); |
|
| 197 | + if (\is_callable($beforeCompile)) { |
|
| 198 | + $beforeCompile($this, $js, $view); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | - if(\is_callable($this->_preCompile)){ |
|
| 201 | + if (\is_callable($this->_preCompile)) { |
|
| 202 | 202 | $pc=$this->_preCompile; |
| 203 | 203 | $pc($this); |
| 204 | 204 | } |
@@ -207,26 +207,26 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 210 | - $this->compile_once($js,$view); |
|
| 210 | + $this->compile_once($js, $view); |
|
| 211 | 211 | $result=$this->getTemplate($js); |
| 212 | - foreach ( $this as $key => $value ) { |
|
| 213 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
| 212 | + foreach ($this as $key => $value) { |
|
| 213 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
| 214 | 214 | if (\is_array($value)) { |
| 215 | 215 | $v=PropertyWrapper::wrap($value, $js); |
| 216 | 216 | } else { |
| 217 | 217 | $v=$value; |
| 218 | 218 | } |
| 219 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
| 219 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | if (isset($js)===true) { |
| 223 | 223 | $this->run($js); |
| 224 | - if (isset($view) === true) { |
|
| 224 | + if (isset($view)===true) { |
|
| 225 | 225 | $js->addViewElement($this->_identifier, $result, $view); |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if(\is_callable($this->_postCompile)){ |
|
| 229 | + if (\is_callable($this->_postCompile)) { |
|
| 230 | 230 | $pc=$this->_postCompile; |
| 231 | 231 | $pc($this); |
| 232 | 232 | } |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | return $this->compile(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - public function onPostCompile($callback){ |
|
| 240 | + public function onPostCompile($callback) { |
|
| 241 | 241 | $this->_postCompile=$callback; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - public function onPreCompile($callback){ |
|
| 244 | + public function onPreCompile($callback) { |
|
| 245 | 245 | $this->_preCompile=$callback; |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | */ |
| 26 | 26 | class DataTable extends Widget { |
| 27 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait; |
|
| 27 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait, BaseTrait; |
|
| 28 | 28 | protected $_searchField; |
| 29 | 29 | protected $_urls; |
| 30 | 30 | protected $_pagination; |
@@ -42,35 +42,35 @@ discard block |
||
| 42 | 42 | protected $_colWidths; |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 46 | - parent::__construct($identifier, $model,$modelInstance); |
|
| 47 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
| 45 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 46 | + parent::__construct($identifier, $model, $modelInstance); |
|
| 47 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
| 48 | 48 | $this->_urls=[]; |
| 49 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
| 49 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
| 50 | 50 | $this->_emptyMessage->setIcon("info circle"); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function run(JsUtils $js){ |
|
| 54 | - if($this->_hasCheckboxes && isset($js)){ |
|
| 53 | + public function run(JsUtils $js) { |
|
| 54 | + if ($this->_hasCheckboxes && isset($js)) { |
|
| 55 | 55 | $this->_runCheckboxes($js); |
| 56 | 56 | } |
| 57 | - if($this->_visibleHover){ |
|
| 58 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 59 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 57 | + if ($this->_visibleHover) { |
|
| 58 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 59 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 60 | 60 | } |
| 61 | - if(\is_array($this->_deleteBehavior)) |
|
| 62 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
| 63 | - if(\is_array($this->_editBehavior)) |
|
| 64 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
| 61 | + if (\is_array($this->_deleteBehavior)) |
|
| 62 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
| 63 | + if (\is_array($this->_editBehavior)) |
|
| 64 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
| 65 | 65 | return parent::run($js); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
| 71 | - if(isset($this->_urls[$op])){ |
|
| 72 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
| 73 | - $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector($op),$params); |
|
| 70 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
| 71 | + if (isset($this->_urls[$op])) { |
|
| 72 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
| 73 | + $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
@@ -83,156 +83,156 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
| 86 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 87 | - if(!$this->_generated){ |
|
| 86 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 87 | + if (!$this->_generated) { |
|
| 88 | 88 | $this->_instanceViewer->setInstance($this->_model); |
| 89 | 89 | $captions=$this->_instanceViewer->getCaptions(); |
| 90 | 90 | $table=$this->content["table"]; |
| 91 | - if($this->_hasCheckboxes){ |
|
| 91 | + if ($this->_hasCheckboxes) { |
|
| 92 | 92 | $this->_generateMainCheckbox($captions); |
| 93 | 93 | } |
| 94 | 94 | $table->setRowCount(0, \sizeof($captions)); |
| 95 | - $this->_generateHeader($table,$captions); |
|
| 95 | + $this->_generateHeader($table, $captions); |
|
| 96 | 96 | |
| 97 | - if(isset($this->_compileParts)) |
|
| 97 | + if (isset($this->_compileParts)) |
|
| 98 | 98 | $table->setCompileParts($this->_compileParts); |
| 99 | 99 | |
| 100 | 100 | $this->_generateContent($table); |
| 101 | 101 | |
| 102 | - $this->compileExtraElements($table, $captions,$js); |
|
| 102 | + $this->compileExtraElements($table, $captions, $js); |
|
| 103 | 103 | |
| 104 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
| 104 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
| 105 | 105 | $this->_compileForm(); |
| 106 | 106 | $this->_applyStyleAttributes($table); |
| 107 | 107 | $this->_generated=true; |
| 108 | 108 | } |
| 109 | - return parent::compile($js,$view); |
|
| 109 | + return parent::compile($js, $view); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - protected function compileExtraElements($table,$captions,JsUtils $js=NULL){ |
|
| 113 | - if(isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])){ |
|
| 114 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 112 | + protected function compileExtraElements($table, $captions, JsUtils $js=NULL) { |
|
| 113 | + if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) { |
|
| 114 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
| 115 | 115 | } |
| 116 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
| 116 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
| 117 | 117 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if(isset($this->_toolbar)){ |
|
| 120 | + if (isset($this->_toolbar)) { |
|
| 121 | 121 | $this->_setToolbarPosition($table, $captions); |
| 122 | 122 | } |
| 123 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
| 124 | - $this->_generatePagination($table,$js); |
|
| 123 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
| 124 | + $this->_generatePagination($table, $js); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - protected function _applyStyleAttributes($table){ |
|
| 129 | - if(isset($this->_hiddenColumns)) |
|
| 128 | + protected function _applyStyleAttributes($table) { |
|
| 129 | + if (isset($this->_hiddenColumns)) |
|
| 130 | 130 | $this->_hideColumns(); |
| 131 | - if(isset($this->_colWidths)){ |
|
| 132 | - foreach ($this->_colWidths as $colIndex=>$width){ |
|
| 133 | - $table->setColWidth($colIndex,$width); |
|
| 131 | + if (isset($this->_colWidths)) { |
|
| 132 | + foreach ($this->_colWidths as $colIndex=>$width) { |
|
| 133 | + $table->setColWidth($colIndex, $width); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - protected function _hideColumns(){ |
|
| 139 | - foreach ($this->_hiddenColumns as $colIndex){ |
|
| 138 | + protected function _hideColumns() { |
|
| 139 | + foreach ($this->_hiddenColumns as $colIndex) { |
|
| 140 | 140 | $this->_self->hideColumn($colIndex); |
| 141 | 141 | } |
| 142 | 142 | return $this; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - protected function _generateHeader(HtmlTable $table,$captions){ |
|
| 145 | + protected function _generateHeader(HtmlTable $table, $captions) { |
|
| 146 | 146 | $table->setHeaderValues($captions); |
| 147 | - if(isset($this->_sortable)){ |
|
| 147 | + if (isset($this->_sortable)) { |
|
| 148 | 148 | $table->setSortable($this->_sortable); |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
| 153 | 153 | |
| 154 | - protected function _generateContent($table){ |
|
| 154 | + protected function _generateContent($table) { |
|
| 155 | 155 | $objects=$this->_modelInstance; |
| 156 | - if(isset($this->_pagination)){ |
|
| 156 | + if (isset($this->_pagination)) { |
|
| 157 | 157 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
| 158 | 158 | } |
| 159 | 159 | InstanceViewer::setIndex(0); |
| 160 | 160 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
| 161 | 161 | return $this->_generateRow($instance, $table); |
| 162 | 162 | }); |
| 163 | - if($table->getRowCount()==0){ |
|
| 163 | + if ($table->getRowCount()==0) { |
|
| 164 | 164 | $result=$table->addRow(); |
| 165 | 165 | $result->mergeRow(); |
| 166 | 166 | $result->setValues([$this->_emptyMessage]); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - protected function _generateRow($instance,&$table,$checkedClass=null){ |
|
| 170 | + protected function _generateRow($instance, &$table, $checkedClass=null) { |
|
| 171 | 171 | $this->_instanceViewer->setInstance($instance); |
| 172 | 172 | InstanceViewer::$index++; |
| 173 | - $values= $this->_instanceViewer->getValues(); |
|
| 173 | + $values=$this->_instanceViewer->getValues(); |
|
| 174 | 174 | $id=$this->_instanceViewer->getIdentifier(); |
| 175 | - if($this->_hasCheckboxes){ |
|
| 176 | - $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,""); |
|
| 175 | + if ($this->_hasCheckboxes) { |
|
| 176 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
| 177 | 177 | $ck->setOnChange("event.stopPropagation();"); |
| 178 | 178 | $field=$ck->getField(); |
| 179 | - $field->setProperty("value",$id); |
|
| 179 | + $field->setProperty("value", $id); |
|
| 180 | 180 | $field->setProperty("name", "selection[]"); |
| 181 | - if(isset($checkedClass)) |
|
| 181 | + if (isset($checkedClass)) |
|
| 182 | 182 | $field->setClass($checkedClass); |
| 183 | 183 | \array_unshift($values, $ck); |
| 184 | 184 | } |
| 185 | 185 | $result=$table->newRow(); |
| 186 | 186 | $result->setIdentifier($this->identifier."-tr-".$id); |
| 187 | - $result->setProperty("data-ajax",$id); |
|
| 187 | + $result->setProperty("data-ajax", $id); |
|
| 188 | 188 | $result->setValues($values); |
| 189 | - $result->addToProperty("class",$this->_rowClass); |
|
| 189 | + $result->addToProperty("class", $this->_rowClass); |
|
| 190 | 190 | return $result; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - protected function _generatePagination($table,$js=NULL){ |
|
| 194 | - if(isset($this->_toolbar)){ |
|
| 195 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 193 | + protected function _generatePagination($table, $js=NULL) { |
|
| 194 | + if (isset($this->_toolbar)) { |
|
| 195 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 196 | 196 | $this->_toolbar->setFloated("left"); |
| 197 | 197 | } |
| 198 | 198 | $footer=$table->getFooter(); |
| 199 | 199 | $footer->mergeCol(); |
| 200 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
| 200 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
| 201 | 201 | $menu->floatRight(); |
| 202 | 202 | $menu->setActiveItem($this->_pagination->getPage()-1); |
| 203 | 203 | $footer->addValues($menu); |
| 204 | - $this->_associatePaginationBehavior($menu,$js); |
|
| 204 | + $this->_associatePaginationBehavior($menu, $js); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){ |
|
| 208 | - if(isset($this->_urls["refresh"])){ |
|
| 209 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith","hasLoader"=>false]); |
|
| 207 | + protected function _associatePaginationBehavior(HtmlMenu $menu, JsUtils $js=NULL) { |
|
| 208 | + if (isset($this->_urls["refresh"])) { |
|
| 209 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith", "hasLoader"=>false]); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - protected function _getFieldName($index){ |
|
| 213 | + protected function _getFieldName($index) { |
|
| 214 | 214 | $fieldName=parent::_getFieldName($index); |
| 215 | - if(\is_object($fieldName)) |
|
| 215 | + if (\is_object($fieldName)) |
|
| 216 | 216 | $fieldName="field-".$index; |
| 217 | 217 | return $fieldName."[]"; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - protected function _getFieldCaption($index){ |
|
| 220 | + protected function _getFieldCaption($index) { |
|
| 221 | 221 | return null; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
| 225 | - switch ($this->_toolbarPosition){ |
|
| 224 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 225 | + switch ($this->_toolbarPosition) { |
|
| 226 | 226 | case PositionInTable::BEFORETABLE: |
| 227 | 227 | case PositionInTable::AFTERTABLE: |
| 228 | - if(isset($this->_compileParts)===false){ |
|
| 228 | + if (isset($this->_compileParts)===false) { |
|
| 229 | 229 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 230 | 230 | } |
| 231 | 231 | break; |
| 232 | 232 | case PositionInTable::HEADER: |
| 233 | 233 | case PositionInTable::FOOTER: |
| 234 | 234 | case PositionInTable::BODY: |
| 235 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
| 235 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
| 236 | 236 | break; |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -244,16 +244,16 @@ discard block |
||
| 244 | 244 | * @param callable $callback function called after the field compilation |
| 245 | 245 | * @return DataTable |
| 246 | 246 | */ |
| 247 | - public function afterCompile($index,$callback){ |
|
| 248 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
| 247 | + public function afterCompile($index, $callback) { |
|
| 248 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
| 249 | 249 | return $this; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - private function addToolbarRow($part,$table,$captions){ |
|
| 252 | + private function addToolbarRow($part, $table, $captions) { |
|
| 253 | 253 | $hasPart=$table->hasPart($part); |
| 254 | - if($hasPart){ |
|
| 254 | + if ($hasPart) { |
|
| 255 | 255 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 256 | - }else{ |
|
| 256 | + } else { |
|
| 257 | 257 | $row=$table->getPart($part)->getRow(0); |
| 258 | 258 | } |
| 259 | 259 | $row->mergeCol(); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @see Widget::getHtmlComponent() |
| 266 | 266 | * @return HtmlTable |
| 267 | 267 | */ |
| 268 | - public function getHtmlComponent(){ |
|
| 268 | + public function getHtmlComponent() { |
|
| 269 | 269 | return $this->content["table"]; |
| 270 | 270 | } |
| 271 | 271 | |
@@ -280,12 +280,12 @@ discard block |
||
| 280 | 280 | * @return DataTable |
| 281 | 281 | */ |
| 282 | 282 | public function setUrls($urls) { |
| 283 | - if(\is_array($urls)){ |
|
| 284 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
| 285 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
| 286 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
| 287 | - }else{ |
|
| 288 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
| 283 | + if (\is_array($urls)) { |
|
| 284 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 285 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 286 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 287 | + } else { |
|
| 288 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
| 289 | 289 | } |
| 290 | 290 | return $this; |
| 291 | 291 | } |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 299 | 299 | * @return DataTable |
| 300 | 300 | */ |
| 301 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
| 302 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
| 301 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 302 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 303 | 303 | return $this; |
| 304 | 304 | } |
| 305 | 305 | |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 311 | 311 | * @return DataTable |
| 312 | 312 | */ |
| 313 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
| 314 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
| 313 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
| 314 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
| 315 | 315 | return $this; |
| 316 | 316 | } |
| 317 | 317 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @param array $compileParts |
| 322 | 322 | * @return DataTable |
| 323 | 323 | */ |
| 324 | - public function refresh($compileParts=["tbody"]){ |
|
| 324 | + public function refresh($compileParts=["tbody"]) { |
|
| 325 | 325 | $this->_compileParts=$compileParts; |
| 326 | 326 | return $this; |
| 327 | 327 | } |
@@ -332,14 +332,14 @@ discard block |
||
| 332 | 332 | * @param string $position |
| 333 | 333 | * @return \Ajax\common\html\HtmlDoubleElement |
| 334 | 334 | */ |
| 335 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
| 335 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 336 | 336 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - public function getSearchField(){ |
|
| 340 | - if(isset($this->_searchField)===false){ |
|
| 341 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
| 342 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
| 339 | + public function getSearchField() { |
|
| 340 | + if (isset($this->_searchField)===false) { |
|
| 341 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 342 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
| 343 | 343 | } |
| 344 | 344 | return $this->_searchField; |
| 345 | 345 | } |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * Returns a form corresponding to the Datatable |
| 360 | 360 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 361 | 361 | */ |
| 362 | - public function asForm(){ |
|
| 362 | + public function asForm() { |
|
| 363 | 363 | return $this->getForm(); |
| 364 | 364 | } |
| 365 | 365 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | |
| 368 | 368 | protected function getTargetSelector($op) { |
| 369 | 369 | $result=$this->_targetSelector; |
| 370 | - if(!isset($result[$op])) |
|
| 370 | + if (!isset($result[$op])) |
|
| 371 | 371 | $result="#".$this->identifier; |
| 372 | 372 | return $result[$op]; |
| 373 | 373 | } |
@@ -378,15 +378,15 @@ discard block |
||
| 378 | 378 | * @return DataTable |
| 379 | 379 | */ |
| 380 | 380 | public function setTargetSelector($_targetSelector) { |
| 381 | - if(!\is_array($_targetSelector)){ |
|
| 382 | - $_targetSelector=["edit"=>$_targetSelector,"delete"=>$_targetSelector]; |
|
| 381 | + if (!\is_array($_targetSelector)) { |
|
| 382 | + $_targetSelector=["edit"=>$_targetSelector, "delete"=>$_targetSelector]; |
|
| 383 | 383 | } |
| 384 | 384 | $this->_targetSelector=$_targetSelector; |
| 385 | 385 | return $this; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | public function getRefreshSelector() { |
| 389 | - if(isset($this->_refreshSelector)) |
|
| 389 | + if (isset($this->_refreshSelector)) |
|
| 390 | 390 | return $this->_refreshSelector; |
| 391 | 391 | return "#".$this->identifier." tbody"; |
| 392 | 392 | } |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | * {@inheritDoc} |
| 405 | 405 | * @see \Ajax\common\Widget::show() |
| 406 | 406 | */ |
| 407 | - public function show($modelInstance){ |
|
| 408 | - if(\is_array($modelInstance)){ |
|
| 409 | - if(isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 407 | + public function show($modelInstance) { |
|
| 408 | + if (\is_array($modelInstance)) { |
|
| 409 | + if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 410 | 410 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
| 411 | 411 | } |
| 412 | 412 | $this->_modelInstance=$modelInstance; |
@@ -441,29 +441,29 @@ discard block |
||
| 441 | 441 | return $this; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
| 445 | - $this->_self->setActiveRowSelector($class,$event,$multiple); |
|
| 444 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 445 | + $this->_self->setActiveRowSelector($class, $event, $multiple); |
|
| 446 | 446 | return $this; |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - public function hideColumn($colIndex){ |
|
| 450 | - if(!\is_array($this->_hiddenColumns)) |
|
| 449 | + public function hideColumn($colIndex) { |
|
| 450 | + if (!\is_array($this->_hiddenColumns)) |
|
| 451 | 451 | $this->_hiddenColumns=[]; |
| 452 | 452 | $this->_hiddenColumns[]=$colIndex; |
| 453 | 453 | return $this; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - public function setColWidth($colIndex,$width){ |
|
| 456 | + public function setColWidth($colIndex, $width) { |
|
| 457 | 457 | $this->_colWidths[$colIndex]=$width; |
| 458 | 458 | return $this; |
| 459 | 459 | } |
| 460 | 460 | public function setColWidths($_colWidths) { |
| 461 | - $this->_colWidths = $_colWidths; |
|
| 461 | + $this->_colWidths=$_colWidths; |
|
| 462 | 462 | return $this; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - public function setColAlignment($colIndex,$alignment){ |
|
| 466 | - $this->content["table"]->setColAlignment($colIndex,$alignment); |
|
| 465 | + public function setColAlignment($colIndex, $alignment) { |
|
| 466 | + $this->content["table"]->setColAlignment($colIndex, $alignment); |
|
| 467 | 467 | return $this; |
| 468 | 468 | } |
| 469 | 469 | } |