@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | */ |
23 | 23 | class DataTable extends Widget { |
24 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
24 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
25 | 25 | protected $_searchField; |
26 | 26 | protected $_urls; |
27 | 27 | protected $_pagination; |
@@ -33,33 +33,33 @@ discard block |
||
33 | 33 | protected $_refreshSelector; |
34 | 34 | |
35 | 35 | |
36 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
37 | - parent::__construct($identifier, $model,$modelInstance); |
|
38 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
36 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
37 | + parent::__construct($identifier, $model, $modelInstance); |
|
38 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
39 | 39 | $this->_urls=[]; |
40 | 40 | } |
41 | 41 | |
42 | - public function run(JsUtils $js){ |
|
43 | - if($this->_hasCheckboxes && isset($js)){ |
|
42 | + public function run(JsUtils $js) { |
|
43 | + if ($this->_hasCheckboxes && isset($js)) { |
|
44 | 44 | $this->_runCheckboxes($js); |
45 | 45 | } |
46 | - if($this->_visibleHover){ |
|
47 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
48 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
46 | + if ($this->_visibleHover) { |
|
47 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
48 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
49 | 49 | } |
50 | - if(\is_array($this->_deleteBehavior)) |
|
51 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
52 | - if(\is_array($this->_editBehavior)) |
|
53 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
50 | + if (\is_array($this->_deleteBehavior)) |
|
51 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
52 | + if (\is_array($this->_editBehavior)) |
|
53 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
54 | 54 | return parent::run($js); |
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
60 | - if(isset($this->_urls[$op])){ |
|
61 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
62 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
59 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
60 | + if (isset($this->_urls[$op])) { |
|
61 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
62 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -72,62 +72,62 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | |
75 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
76 | - if(!$this->_generated){ |
|
75 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
76 | + if (!$this->_generated) { |
|
77 | 77 | $this->_instanceViewer->setInstance($this->_model); |
78 | 78 | $captions=$this->_instanceViewer->getCaptions(); |
79 | 79 | |
80 | 80 | $table=$this->content["table"]; |
81 | 81 | |
82 | - if($this->_hasCheckboxes){ |
|
82 | + if ($this->_hasCheckboxes) { |
|
83 | 83 | $this->_generateMainCheckbox($captions); |
84 | 84 | } |
85 | 85 | |
86 | 86 | $table->setRowCount(0, \sizeof($captions)); |
87 | 87 | $table->setHeaderValues($captions); |
88 | - if(isset($this->_compileParts)) |
|
88 | + if (isset($this->_compileParts)) |
|
89 | 89 | $table->setCompileParts($this->_compileParts); |
90 | 90 | |
91 | - if(isset($this->_searchField) && isset($js)){ |
|
92 | - if(isset($this->_urls["refresh"])) |
|
93 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
91 | + if (isset($this->_searchField) && isset($js)) { |
|
92 | + if (isset($this->_urls["refresh"])) |
|
93 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $this->_generateContent($table); |
97 | 97 | |
98 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
98 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
99 | 99 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
100 | 100 | } |
101 | 101 | |
102 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
102 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
103 | 103 | $this->_generatePagination($table); |
104 | 104 | } |
105 | - if(isset($this->_toolbar)){ |
|
105 | + if (isset($this->_toolbar)) { |
|
106 | 106 | $this->_setToolbarPosition($table, $captions); |
107 | 107 | } |
108 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
108 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
109 | 109 | $this->_compileForm(); |
110 | 110 | $this->_generated=true; |
111 | 111 | } |
112 | - return parent::compile($js,$view); |
|
112 | + return parent::compile($js, $view); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | 116 | |
117 | - protected function _generateContent($table){ |
|
117 | + protected function _generateContent($table) { |
|
118 | 118 | $objects=$this->_modelInstance; |
119 | - if(isset($this->_pagination)){ |
|
119 | + if (isset($this->_pagination)) { |
|
120 | 120 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
121 | 121 | } |
122 | 122 | InstanceViewer::setIndex(0); |
123 | 123 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
124 | 124 | $this->_instanceViewer->setInstance($instance); |
125 | 125 | InstanceViewer::$index++; |
126 | - $values= $this->_instanceViewer->getValues(); |
|
127 | - if($this->_hasCheckboxes){ |
|
128 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
126 | + $values=$this->_instanceViewer->getValues(); |
|
127 | + if ($this->_hasCheckboxes) { |
|
128 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
129 | 129 | $field=$ck->getField(); |
130 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
130 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
131 | 131 | $field->setProperty("name", "selection[]"); |
132 | 132 | \array_unshift($values, $ck); |
133 | 133 | } |
@@ -138,37 +138,37 @@ discard block |
||
138 | 138 | }); |
139 | 139 | } |
140 | 140 | |
141 | - private function _generatePagination($table){ |
|
141 | + private function _generatePagination($table) { |
|
142 | 142 | $footer=$table->getFooter(); |
143 | 143 | $footer->mergeCol(); |
144 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
144 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
145 | 145 | $menu->floatRight(); |
146 | 146 | $menu->setActiveItem($this->_pagination->getPage()-1); |
147 | 147 | $footer->setValues($menu); |
148 | - if(isset($this->_urls["refresh"])) |
|
149 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
148 | + if (isset($this->_urls["refresh"])) |
|
149 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
150 | 150 | } |
151 | 151 | |
152 | - protected function _getFieldName($index){ |
|
152 | + protected function _getFieldName($index) { |
|
153 | 153 | return parent::_getFieldName($index)."[]"; |
154 | 154 | } |
155 | 155 | |
156 | - protected function _getFieldCaption($index){ |
|
156 | + protected function _getFieldCaption($index) { |
|
157 | 157 | return null; |
158 | 158 | } |
159 | 159 | |
160 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
161 | - switch ($this->_toolbarPosition){ |
|
160 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
161 | + switch ($this->_toolbarPosition) { |
|
162 | 162 | case PositionInTable::BEFORETABLE: |
163 | 163 | case PositionInTable::AFTERTABLE: |
164 | - if(isset($this->_compileParts)===false){ |
|
164 | + if (isset($this->_compileParts)===false) { |
|
165 | 165 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
166 | 166 | } |
167 | 167 | break; |
168 | 168 | case PositionInTable::HEADER: |
169 | 169 | case PositionInTable::FOOTER: |
170 | 170 | case PositionInTable::BODY: |
171 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
171 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
172 | 172 | break; |
173 | 173 | } |
174 | 174 | } |
@@ -180,23 +180,23 @@ discard block |
||
180 | 180 | * @param callable $callback function called after the field compilation |
181 | 181 | * @return DataTable |
182 | 182 | */ |
183 | - public function afterCompile($index,$callback){ |
|
184 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
183 | + public function afterCompile($index, $callback) { |
|
184 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
185 | 185 | return $this; |
186 | 186 | } |
187 | 187 | |
188 | - private function addToolbarRow($part,$table,$captions){ |
|
188 | + private function addToolbarRow($part, $table, $captions) { |
|
189 | 189 | $hasPart=$table->hasPart($part); |
190 | - if($hasPart){ |
|
190 | + if ($hasPart) { |
|
191 | 191 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
192 | - }else{ |
|
192 | + } else { |
|
193 | 193 | $row=$table->getPart($part)->getRow(0); |
194 | 194 | } |
195 | 195 | $row->mergeCol(); |
196 | 196 | $row->setValues([$this->_toolbar]); |
197 | 197 | } |
198 | 198 | |
199 | - public function getHtmlComponent(){ |
|
199 | + public function getHtmlComponent() { |
|
200 | 200 | return $this->content["table"]; |
201 | 201 | } |
202 | 202 | |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | * @return DataTable |
211 | 211 | */ |
212 | 212 | public function setUrls($urls) { |
213 | - if(\is_array($urls)){ |
|
214 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
215 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
216 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
217 | - }else{ |
|
218 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
213 | + if (\is_array($urls)) { |
|
214 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
215 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
216 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
217 | + } else { |
|
218 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
219 | 219 | } |
220 | 220 | return $this; |
221 | 221 | } |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | * @param number $pages_visibles The number of visible pages in the Pagination component |
229 | 229 | * @return DataTable |
230 | 230 | */ |
231 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=4){ |
|
232 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
231 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=4) { |
|
232 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
233 | 233 | return $this; |
234 | 234 | } |
235 | 235 | |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * @param number $pages_visibles The number of visible pages in the Pagination component |
241 | 241 | * @return DataTable |
242 | 242 | */ |
243 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
244 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
243 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
244 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
245 | 245 | return $this; |
246 | 246 | } |
247 | 247 | |
@@ -251,20 +251,20 @@ discard block |
||
251 | 251 | * @param array $compileParts |
252 | 252 | * @return DataTable |
253 | 253 | */ |
254 | - public function refresh($compileParts=["tbody"]){ |
|
254 | + public function refresh($compileParts=["tbody"]) { |
|
255 | 255 | $this->_compileParts=$compileParts; |
256 | 256 | return $this; |
257 | 257 | } |
258 | 258 | |
259 | 259 | |
260 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
260 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
261 | 261 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
262 | 262 | } |
263 | 263 | |
264 | - public function getSearchField(){ |
|
265 | - if(isset($this->_searchField)===false){ |
|
266 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
267 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
264 | + public function getSearchField() { |
|
265 | + if (isset($this->_searchField)===false) { |
|
266 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
267 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
268 | 268 | } |
269 | 269 | return $this->_searchField; |
270 | 270 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | return $this; |
281 | 281 | } |
282 | 282 | |
283 | - public function asForm(){ |
|
283 | + public function asForm() { |
|
284 | 284 | return $this->getForm(); |
285 | 285 | } |
286 | 286 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | |
289 | 289 | protected function getTargetSelector() { |
290 | 290 | $result=$this->_targetSelector; |
291 | - if(!isset($result)) |
|
291 | + if (!isset($result)) |
|
292 | 292 | $result="#".$this->identifier; |
293 | 293 | return $result; |
294 | 294 | } |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | } |
305 | 305 | |
306 | 306 | public function getRefreshSelector() { |
307 | - if(isset($this->_refreshSelector)) |
|
307 | + if (isset($this->_refreshSelector)) |
|
308 | 308 | return $this->_refreshSelector; |
309 | 309 | return "#".$this->identifier." tbody"; |
310 | 310 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | private $pages_visibles; |
10 | 10 | private $row_count; |
11 | 11 | |
12 | - public function __construct($items_per_page=10,$pages_visibles=4,$page=1,$row_count=null){ |
|
12 | + public function __construct($items_per_page=10, $pages_visibles=4, $page=1, $row_count=null) { |
|
13 | 13 | $this->items_per_page=$items_per_page; |
14 | 14 | $this->row_count=$row_count; |
15 | 15 | $this->page=$page; |
@@ -17,29 +17,29 @@ discard block |
||
17 | 17 | $this->visible=true; |
18 | 18 | } |
19 | 19 | |
20 | - public function getObjects($objects){ |
|
20 | + public function getObjects($objects) { |
|
21 | 21 | $auto=(!isset($this->row_count)); |
22 | 22 | $os=$objects; |
23 | - if(!\is_array($os)){ |
|
23 | + if (!\is_array($os)) { |
|
24 | 24 | $os=[]; |
25 | - foreach ($objects as $o){ |
|
25 | + foreach ($objects as $o) { |
|
26 | 26 | $os[]=$o; |
27 | 27 | } |
28 | 28 | } |
29 | - $this->page_count = 0; |
|
30 | - $row_count=($auto)?\sizeof($os):$this->row_count; |
|
31 | - if (0 === $row_count) { |
|
29 | + $this->page_count=0; |
|
30 | + $row_count=($auto) ? \sizeof($os) : $this->row_count; |
|
31 | + if (0===$row_count) { |
|
32 | 32 | $this->visible=false; |
33 | 33 | } else { |
34 | 34 | $this->visible=true; |
35 | - $this->page_count = (int)ceil($row_count / $this->items_per_page); |
|
36 | - if($this->page > $this->page_count+1) { |
|
37 | - $this->page = 1; |
|
35 | + $this->page_count=(int)ceil($row_count/$this->items_per_page); |
|
36 | + if ($this->page>$this->page_count+1) { |
|
37 | + $this->page=1; |
|
38 | 38 | } |
39 | 39 | } |
40 | - if($auto){ |
|
41 | - $offset = ($this->page - 1) * $this->items_per_page; |
|
42 | - return array_slice($os, $offset,$this->items_per_page); |
|
40 | + if ($auto) { |
|
41 | + $offset=($this->page-1)*$this->items_per_page; |
|
42 | + return array_slice($os, $offset, $this->items_per_page); |
|
43 | 43 | } |
44 | 44 | return $os; |
45 | 45 | } |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | return $this->page_count; |
76 | 76 | } |
77 | 77 | |
78 | - public function getPagesNumbers(){ |
|
79 | - $middle= (int)ceil(($this->pages_visibles-1)/ 2); |
|
78 | + public function getPagesNumbers() { |
|
79 | + $middle=(int)ceil(($this->pages_visibles-1)/2); |
|
80 | 80 | $first=$this->page-$middle; |
81 | - if($first<1){ |
|
81 | + if ($first<1) { |
|
82 | 82 | $first=1; |
83 | 83 | } |
84 | 84 | $last=$first+$this->pages_visibles-1; |
85 | - if($last>$this->page_count){ |
|
85 | + if ($last>$this->page_count) { |
|
86 | 86 | $last=$this->page_count; |
87 | 87 | } |
88 | 88 | return \range($first, $last); |