source: trunk/Common/VCL/Database.php

Last change on this file was 887, checked in by chronos, 4 years ago
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
File size: 2.3 KB
Line 
1<?php
2
3class DbPageListView extends PageListView
4{
5 var $SQL;
6 var $Table;
7 var $Database;
8 var $ShowTotal;
9 var $Filter;
10 var $OnRowDraw;
11 var $OrderDirSQL;
12
13 function __construct()
14 {
15 parent::__construct();
16 $this->ShowTotal = true;
17 $this->SQL = '';
18 $this->OrderDirSQL = array('ASC', 'DESC');
19 }
20
21 function Show(): string
22 {
23 // Get total item count in database
24 $Query = 'SELECT COUNT(*) FROM '.$this->SQL;
25 $DbResult = $this->Database->query($Query);
26 $DbRow = $DbResult->fetch_assoc();
27 $TotalCount = $DbRow['COUNT(*)'];
28
29 $ColumnSQL = array();
30 foreach ($this->Columns as $Column)
31 {
32 $ColumnSQL[] = $Column->Name;
33 }
34 $ColumnSQL = implode(', ', $ColumnSQL);
35
36 // Get total filtered item count in database
37 if ($this->Filter != '')
38 {
39 $Query = 'SELECT COUNT(*) FROM (SELECT '.$ColumnSQL.' FROM '.$this->SQL.') AS `TS` '.$this->Filter;
40 $DbResult = $this->Database->query($Query);
41 $DbRow = $DbResult->fetch_row();
42 $TotalFilteredCount = $DbRow[0];
43 } else $TotalFilteredCount = $TotalCount;
44 $this->PageSelect->Count = $TotalFilteredCount;
45
46 $this->Rows = array();
47 $VisibleItemCount = 0;
48 if (($this->SortOrder != 0) and ($this->SortOrder != 1)) $this->SortOrder = 0;
49 //if ($this->SortColumn)
50 $this->SortColumn = $this->Columns[0]->Name;
51 $this->OrderSQL = ' ORDER BY `'.$this->SortColumn.'` '.$this->OrderDirSQL[$this->SortOrder];
52 $SQLLimit = ' LIMIT '.$this->PageSelect->Position * $this->PageSelect->PageSize.', '.$this->PageSelect->PageSize;
53 $Query = 'SELECT * FROM (SELECT '.$ColumnSQL.' FROM '.$this->SQL.') AS `TS` '.
54 $this->Filter.' '.$this->OrderSQL.$SQLLimit;
55 $DbResult = $this->Database->query($Query);
56 while ($DbRow = $DbResult->fetch_assoc())
57 {
58 if (method_exists($this->OnRowDraw[0], $this->OnRowDraw[1]))
59 $DbRow = call_user_func($this->OnRowDraw, $DbRow);
60 $this->Rows[] = $DbRow;
61 $VisibleItemCount = $VisibleItemCount + 1;
62 }
63 $Row = '<td colspan="'.count($this->Columns).'" style="text-align: right;">Zobrazeno <strong>'.$VisibleItemCount.'</strong>';
64 if ($this->Filter != '') $Row .= ' z filtrovaných <strong>'.$TotalFilteredCount.'</strong>';
65 $Row .= ' z celkem <strong>'.$TotalCount.'</strong>';
66 $ListView->Rows[] = $Row;
67 $Output = parent::Show();
68 return $Output;
69 }
70}
Note: See TracBrowser for help on using the repository browser.