blob: c73feeefadd32304aed5c8cbf1130d8dbfe15f0f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?php
class FilterSet
{
private $filters;
private $sortDirection;
private $sortColumn;
public function __construct($filters)
{
$this->filters = $filters;
}
public function setSort($col, $direction)
{
$this->sortDirection = $direction === 'DESC' ? 'DESC' : 'ASC';
if (is_string($col) && array_key_exists($col, Page_Statistics::$columns)) {
$this->sortColumn = $col;
} else {
/* default sorting column is clientip */
$this->sortColumn = 'clientip';
}
}
public function makeFragments(&$where, &$join, &$sort, &$args)
{
/* generate where clause & arguments */
$where = '';
$joins = [];
$sort = "";
$args = [];
if (empty($this->filters)) {
$where = ' 1 ';
} else {
foreach ($this->filters as $filter) {
$sep = ($where != '' ? ' AND ' : '');
$where .= $sep . $filter->whereClause($args, $joins);
}
}
$join = implode('', array_unique($joins));
$col = $this->sortColumn;
$isMapped = array_key_exists('map_sort', Page_Statistics::$columns[$col]);
$concreteCol = ($isMapped ? Page_Statistics::$columns[$col]['map_sort'] : $col) ;
if ($concreteCol === 'clientip') {
$concreteCol = "INET_ATON(clientip)";
}
$sort = " ORDER BY " . $concreteCol . " " . $this->sortDirection
. ", machineuuid ASC";
}
public function isNoId44Filter()
{
foreach ($this->filters as $filter) {
if (get_class($filter) === 'Id44Filter' && $filter->argument == 0) {
return true;
}
}
return false;
}
public function getSortDirection()
{
return $this->sortDirection;
}
public function getSortColumn()
{
return $this->sortColumn;
}
}
|