@@ -6,16 +6,16 @@ discard block |
||
| 6 | 6 | abstract class TrapDirectorTable |
| 7 | 7 | { |
| 8 | 8 | /** @var array $titles table titles (name, display value) */ |
| 9 | - protected $titles = null; |
|
| 9 | + protected $titles=null; |
|
| 10 | 10 | |
| 11 | 11 | /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
| 12 | - protected $content = null; |
|
| 12 | + protected $content=null; |
|
| 13 | 13 | |
| 14 | 14 | /** @var array $columnNames names of columns for filtering */ |
| 15 | - protected $columnNames = array(); |
|
| 15 | + protected $columnNames=array(); |
|
| 16 | 16 | |
| 17 | 17 | /** @var mixed $dbConn connection to database */ |
| 18 | - protected $dbConn = null; |
|
| 18 | + protected $dbConn=null; |
|
| 19 | 19 | |
| 20 | 20 | /** Current view **/ |
| 21 | 21 | protected $view; |
@@ -24,39 +24,39 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | // Database stuff |
| 26 | 26 | /** @var array $table (db ref, name) */ |
| 27 | - protected $table = array(); |
|
| 27 | + protected $table=array(); |
|
| 28 | 28 | |
| 29 | 29 | /** @var mixed $query Query in database; */ |
| 30 | - protected $query = null; |
|
| 30 | + protected $query=null; |
|
| 31 | 31 | |
| 32 | 32 | /** @var array $order : (db column, 'ASC' | 'DESC') */ |
| 33 | - protected $order = array(); |
|
| 34 | - protected $orderQuery = ''; |
|
| 33 | + protected $order=array(); |
|
| 34 | + protected $orderQuery=''; |
|
| 35 | 35 | |
| 36 | 36 | /********* Filter ********/ |
| 37 | 37 | /** @var string $filterString : string filter for db columns */ |
| 38 | - protected $filterString = ''; |
|
| 38 | + protected $filterString=''; |
|
| 39 | 39 | |
| 40 | 40 | /** @var array $filterColumn : columns to apply filter to */ |
| 41 | - protected $filterColumn = array(); |
|
| 41 | + protected $filterColumn=array(); |
|
| 42 | 42 | |
| 43 | 43 | protected $filterQuery=''; |
| 44 | 44 | |
| 45 | 45 | /*************** Paging *************/ |
| 46 | - protected $maxPerPage = 25; |
|
| 46 | + protected $maxPerPage=25; |
|
| 47 | 47 | |
| 48 | - protected $currentPage = 0; |
|
| 48 | + protected $currentPage=0; |
|
| 49 | 49 | |
| 50 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
| 50 | + function __construct(array $table, array $titles, array $columns, array $columnNames, $dbConn, $view, $urlPath) |
|
| 51 | 51 | { |
| 52 | - $this->table = $table; |
|
| 53 | - $this->titles = $titles; |
|
| 54 | - $this->content = $columns; |
|
| 55 | - $this->columnNames = $columnNames; |
|
| 56 | - $this->dbConn = $dbConn; |
|
| 52 | + $this->table=$table; |
|
| 53 | + $this->titles=$titles; |
|
| 54 | + $this->content=$columns; |
|
| 55 | + $this->columnNames=$columnNames; |
|
| 56 | + $this->dbConn=$dbConn; |
|
| 57 | 57 | |
| 58 | - $this->view = $view; |
|
| 59 | - $this->urlPath = $urlPath; |
|
| 58 | + $this->view=$view; |
|
| 59 | + $this->urlPath=$urlPath; |
|
| 60 | 60 | |
| 61 | 61 | return $this; |
| 62 | 62 | } |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | protected function getCurrentURLAndQS(string $caller) |
| 79 | 79 | { |
| 80 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
| 80 | + $actionURL=$this->getCurrentURL().'?'; |
|
| 81 | 81 | $QSList=array(); |
| 82 | 82 | if ($caller != 'filter' && $this->curFilterQuery() != '') |
| 83 | - array_push($QSList , $this->curFilterQuery()); |
|
| 83 | + array_push($QSList, $this->curFilterQuery()); |
|
| 84 | 84 | |
| 85 | 85 | if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
| 86 | - array_push($QSList , $this->curPagingQuery()); |
|
| 86 | + array_push($QSList, $this->curPagingQuery()); |
|
| 87 | 87 | |
| 88 | 88 | if ($caller != 'order' && $this->curOrderQuery() != '') |
| 89 | - array_push($QSList , $this->curOrderQuery()); |
|
| 89 | + array_push($QSList, $this->curOrderQuery()); |
|
| 90 | 90 | |
| 91 | 91 | if (count($QSList) != 0) |
| 92 | - $actionURL .= implode('&', $QSList); |
|
| 92 | + $actionURL.=implode('&', $QSList); |
|
| 93 | 93 | |
| 94 | 94 | return $actionURL; |
| 95 | 95 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function getBaseQuery() |
| 103 | 103 | { |
| 104 | - $this->query = $this->dbConn->select(); |
|
| 105 | - $this->query = $this->query->from( |
|
| 104 | + $this->query=$this->dbConn->select(); |
|
| 105 | + $this->query=$this->query->from( |
|
| 106 | 106 | $this->table, |
| 107 | 107 | $this->content |
| 108 | 108 | ); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | { |
| 136 | 136 | if ($filter != "") $filter.=' OR '; |
| 137 | 137 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
| 138 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
| 138 | + $filter.=$column." LIKE '%".$this->filterString."%'"; |
|
| 139 | 139 | } |
| 140 | 140 | //echo $filter; |
| 141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | public function setFilter(string $filter, array $filterCol) |
| 148 | 148 | { |
| 149 | - $this->filterString = $filter; |
|
| 150 | - $this->filterColumn = $filterCol; |
|
| 149 | + $this->filterString=$filter; |
|
| 150 | + $this->filterColumn=$filterCol; |
|
| 151 | 151 | return $this; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | if (isset($getVars['f'])) |
| 171 | 171 | { |
| 172 | - $this->filterQuery = $getVars['f']; |
|
| 172 | + $this->filterQuery=$getVars['f']; |
|
| 173 | 173 | $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
| 174 | 174 | } |
| 175 | 175 | } |
@@ -193,16 +193,16 @@ discard block |
||
| 193 | 193 | { |
| 194 | 194 | if ($orderSQL != "") $orderSQL.=','; |
| 195 | 195 | |
| 196 | - $orderSQL .= $column . ' ' . $direction; |
|
| 196 | + $orderSQL.=$column.' '.$direction; |
|
| 197 | 197 | } |
| 198 | - $this->query = $this->query->order($orderSQL); |
|
| 198 | + $this->query=$this->query->order($orderSQL); |
|
| 199 | 199 | |
| 200 | 200 | return $this; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | public function setOrder(array $order) |
| 204 | 204 | { |
| 205 | - $this->order = $order; |
|
| 205 | + $this->order=$order; |
|
| 206 | 206 | return $this; |
| 207 | 207 | } |
| 208 | 208 | |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | if (isset($getVars['o'])) |
| 212 | 212 | { |
| 213 | - $this->orderQuery = $getVars['o']; |
|
| 214 | - $match = array(); |
|
| 215 | - if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match)) |
|
| 213 | + $this->orderQuery=$getVars['o']; |
|
| 214 | + $match=array(); |
|
| 215 | + if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery, $match)) |
|
| 216 | 216 | { |
| 217 | 217 | $orderArray=array($match[1] => $match[2]); |
| 218 | 218 | echo "$match[1] => $match[2]"; |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | public function countQuery() |
| 233 | 233 | { |
| 234 | - $this->query = $this->dbConn->select(); |
|
| 235 | - $this->query = $this->query |
|
| 234 | + $this->query=$this->dbConn->select(); |
|
| 235 | + $this->query=$this->query |
|
| 236 | 236 | ->from( |
| 237 | 237 | $this->table, |
| 238 | 238 | array('COUNT(*)') |
@@ -248,14 +248,14 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | public function setMaxPerPage(int $max) |
| 250 | 250 | { |
| 251 | - $this->maxPerPage = $max; |
|
| 251 | + $this->maxPerPage=$max; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | protected function getPagingQuery(array $getVars) |
| 255 | 255 | { |
| 256 | 256 | if (isset($getVars['page'])) |
| 257 | 257 | { |
| 258 | - $this->currentPage = $getVars['page']; |
|
| 258 | + $this->currentPage=$getVars['page']; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
@@ -267,22 +267,22 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | public function renderPagingHeader() |
| 269 | 269 | { |
| 270 | - $count = $this->count(); |
|
| 271 | - if ($count <= $this->maxPerPage ) |
|
| 270 | + $count=$this->count(); |
|
| 271 | + if ($count <= $this->maxPerPage) |
|
| 272 | 272 | { |
| 273 | - return 'count : ' . $this->count() . '<br>'; |
|
| 273 | + return 'count : '.$this->count().'<br>'; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 276 | + if ($this->currentPage == 0) $this->currentPage=1; |
|
| 277 | 277 | |
| 278 | - $numPages = intdiv($count , $this->maxPerPage); |
|
| 279 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 278 | + $numPages=intdiv($count, $this->maxPerPage); |
|
| 279 | + if ($count % $this->maxPerPage != 0) $numPages++; |
|
| 280 | 280 | |
| 281 | - $html = '<div class="pagination-control" role="navigation">'; |
|
| 282 | - $html .= '<ul class="nav tab-nav">'; |
|
| 283 | - if ($this->currentPage <=1) |
|
| 281 | + $html='<div class="pagination-control" role="navigation">'; |
|
| 282 | + $html.='<ul class="nav tab-nav">'; |
|
| 283 | + if ($this->currentPage <= 1) |
|
| 284 | 284 | { |
| 285 | - $html .= ' |
|
| 285 | + $html.=' |
|
| 286 | 286 | <li class="nav-item disabled" aria-hidden="true"> |
| 287 | 287 | <span class="previous-page"> |
| 288 | 288 | <span class="sr-only">Previous page</span> |
@@ -293,24 +293,24 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | else |
| 295 | 295 | { |
| 296 | - $html .= ' |
|
| 296 | + $html.=' |
|
| 297 | 297 | <li class="nav-item"> |
| 298 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
|
| 298 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" > |
|
| 299 | 299 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
| 300 | 300 | </a> |
| 301 | 301 | </li> |
| 302 | 302 | '; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - for ($i=1; $i <= $numPages ; $i++) |
|
| 305 | + for ($i=1; $i <= $numPages; $i++) |
|
| 306 | 306 | { |
| 307 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
| 308 | - $first = ($i-1)*$this->maxPerPage+1; |
|
| 309 | - $last = $i * $this->maxPerPage; |
|
| 310 | - if ($last > $count) $last = $count; |
|
| 311 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
| 312 | - $html .= '<li class="' . $active . ' nav-item"> |
|
| 313 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
|
| 307 | + $active=($this->currentPage == $i) ? 'active' : ''; |
|
| 308 | + $first=($i - 1) * $this->maxPerPage + 1; |
|
| 309 | + $last=$i * $this->maxPerPage; |
|
| 310 | + if ($last > $count) $last=$count; |
|
| 311 | + $display='Show rows '.$first.' to '.$last.' of '.$count; |
|
| 312 | + $html.='<li class="'.$active.' nav-item"> |
|
| 313 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'"> |
|
| 314 | 314 | '.$i.' |
| 315 | 315 | </a> |
| 316 | 316 | </li>'; |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | if ($this->currentPage == $numPages) |
| 320 | 320 | { |
| 321 | - $html .= ' |
|
| 321 | + $html.=' |
|
| 322 | 322 | <li class="nav-item disabled" aria-hidden="true"> |
| 323 | 323 | <span class="previous-page"> |
| 324 | 324 | <span class="sr-only">Previous page</span> |
@@ -329,23 +329,23 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | else |
| 331 | 331 | { |
| 332 | - $html .= ' |
|
| 332 | + $html.=' |
|
| 333 | 333 | <li class="nav-item"> |
| 334 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
|
| 334 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page"> |
|
| 335 | 335 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
| 336 | 336 | </a> |
| 337 | 337 | </li> |
| 338 | 338 | '; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - $html .= '</ul> </div>'; |
|
| 341 | + $html.='</ul> </div>'; |
|
| 342 | 342 | |
| 343 | 343 | return $html; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | public function applyPaging() |
| 347 | 347 | { |
| 348 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
| 348 | + $this->query->limitPage($this->currentPage, $this->maxPerPage); |
|
| 349 | 349 | return $this; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -358,10 +358,10 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | public function renderTitles() |
| 360 | 360 | { |
| 361 | - $html = "<thead>\n<tr>\n"; |
|
| 361 | + $html="<thead>\n<tr>\n"; |
|
| 362 | 362 | foreach ($this->titles as $name => $values) |
| 363 | 363 | { |
| 364 | - $titleOrder = $this->titleOrder($name); |
|
| 364 | + $titleOrder=$this->titleOrder($name); |
|
| 365 | 365 | if ($titleOrder != NULL) |
| 366 | 366 | { |
| 367 | 367 | if (isset($this->order[$titleOrder])) |
@@ -379,56 +379,56 @@ discard block |
||
| 379 | 379 | { |
| 380 | 380 | $titleOrder.='ASC'; |
| 381 | 381 | } |
| 382 | - $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
| 383 | - $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>'; |
|
| 382 | + $actionURL=$this->getCurrentURLAndQS('order').'o='.$titleOrder; |
|
| 383 | + $html.='<th><a href="'.$actionURL.'">'.$values.'</a></th>'; |
|
| 384 | 384 | } |
| 385 | 385 | else |
| 386 | 386 | { |
| 387 | - $html .= '<th>' . $values . '</th>'; |
|
| 387 | + $html.='<th>'.$values.'</th>'; |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | - $html .= "</tr>\n</thead>\n"; |
|
| 390 | + $html.="</tr>\n</thead>\n"; |
|
| 391 | 391 | return $html; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - public function renderLine( $value) |
|
| 394 | + public function renderLine($value) |
|
| 395 | 395 | { |
| 396 | - $html = ''; |
|
| 397 | - $titleNames = array_keys($this->titles); |
|
| 398 | - foreach ($titleNames as $name ) |
|
| 396 | + $html=''; |
|
| 397 | + $titleNames=array_keys($this->titles); |
|
| 398 | + foreach ($titleNames as $name) |
|
| 399 | 399 | { |
| 400 | - $html .= '<td>'; |
|
| 401 | - $html .= $value->$name; |
|
| 402 | - $html .= "</td>\n"; |
|
| 400 | + $html.='<td>'; |
|
| 401 | + $html.=$value->$name; |
|
| 402 | + $html.="</td>\n"; |
|
| 403 | 403 | } |
| 404 | 404 | return $html; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | public function renderTable(array $values) |
| 408 | 408 | { |
| 409 | - $html = '<tbody id="obj_table_body">'; |
|
| 410 | - foreach($values as $value) |
|
| 409 | + $html='<tbody id="obj_table_body">'; |
|
| 410 | + foreach ($values as $value) |
|
| 411 | 411 | { |
| 412 | - $html .= "<tr>\n"; |
|
| 413 | - $html .= $this->renderLine($value); |
|
| 414 | - $html .= "</tr>\n"; |
|
| 412 | + $html.="<tr>\n"; |
|
| 413 | + $html.=$this->renderLine($value); |
|
| 414 | + $html.="</tr>\n"; |
|
| 415 | 415 | } |
| 416 | - $html .= '</tbody>'; |
|
| 416 | + $html.='</tbody>'; |
|
| 417 | 417 | return $html; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | public function render() |
| 421 | 421 | { |
| 422 | - $html = ''; |
|
| 422 | + $html=''; |
|
| 423 | 423 | |
| 424 | 424 | |
| 425 | - $values = $this->fullQuery(); |
|
| 425 | + $values=$this->fullQuery(); |
|
| 426 | 426 | |
| 427 | 427 | $html.="<table class='simple common-table table-row-selectable'>\n"; |
| 428 | 428 | |
| 429 | - $html .= $this->renderTitles(); |
|
| 430 | - $html .= $this->renderTable($values); |
|
| 431 | - $html .= '</table>'; |
|
| 429 | + $html.=$this->renderTitles(); |
|
| 430 | + $html.=$this->renderTable($values); |
|
| 431 | + $html.='</table>'; |
|
| 432 | 432 | |
| 433 | 433 | |
| 434 | 434 | return $html; |