diff options
author | Steffen Ritter | 2019-08-28 11:26:36 +0200 |
---|---|---|
committer | Steffen Ritter | 2019-08-28 11:26:36 +0200 |
commit | 303d633e8a6dddbeee236935b6b21d7f5c27c4dc (patch) | |
tree | 19a1c8c6ba3aec2d12ae7c69cf4a0f95ebbc8bf2 | |
parent | [statistics] Add filter for runtime and lastboot (diff) | |
download | slx-admin-303d633e8a6dddbeee236935b6b21d7f5c27c4dc.tar.gz slx-admin-303d633e8a6dddbeee236935b6b21d7f5c27c4dc.tar.xz slx-admin-303d633e8a6dddbeee236935b6b21d7f5c27c4dc.zip |
[statistics] Make several filters by date actually work
-rw-r--r-- | modules-available/statistics/inc/filter.inc.php | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/modules-available/statistics/inc/filter.inc.php b/modules-available/statistics/inc/filter.inc.php index 46de467b..8f61e44b 100644 --- a/modules-available/statistics/inc/filter.inc.php +++ b/modules-available/statistics/inc/filter.inc.php @@ -106,6 +106,14 @@ class Filter $filters[] = new LocationFilter($operator, $rhs); } elseif ($lhs === 'subnet') { $filters[] = new SubnetFilter($operator, $rhs); + } elseif ($lhs === 'lastboot') { + $filters[] = new ByDateFilter($operator, $rhs, $lhs); + } elseif ($lhs === 'firstseen') { + $filters[] = new ByDateFilter($operator, $rhs, $lhs); + } elseif ($lhs === 'lastseen') { + $filters[] = new ByDateFilter($operator, $rhs, $lhs); + } elseif ($lhs === 'logintime') { + $filters[] = new ByDateFilter($operator, $rhs, $lhs); } else { if (array_key_exists($lhs, Page_Statistics::$columns) && Page_Statistics::$columns[$lhs]['column']) { $filters[] = new Filter($lhs, $operator, $rhs); @@ -160,7 +168,6 @@ class RuntimeFilter extends Filter public function whereClause(&$args, &$joins) { - global $SIZE_RAM; $upper = time() - (int)$this->argument * 3600; $lower = $upper - 3600; $common = "state IN ('OCCUPIED', 'IDLE', 'STANDBY') AND"; @@ -183,6 +190,34 @@ class RuntimeFilter extends Filter } } +class ByDateFilter extends Filter +{ + public function __construct($operator, $argument, $filter) + { + parent::__construct($filter, $operator, $argument); + } + + public function whereClause(&$args, &$joins) + { + if ($this->operator == '=') { + return " DATE(FROM_UNIXTIME($this->column)) = '$this->argument'"; + } elseif ($this->operator == '<') { + return " DATE(FROM_UNIXTIME($this->column)) < '$this->argument'"; + } elseif ($this->operator == '<=') { + return " DATE(FROM_UNIXTIME($this->column)) <= '$this->argument'"; + } elseif ($this->operator == '>') { + return " DATE(FROM_UNIXTIME($this->column)) > '$this->argument'"; + } elseif ($this->operator == '>=') { + return " DATE(FROM_UNIXTIME($this->column)) >= '$this->argument'"; + } elseif ($this->operator == '!=') { + return " DATE(FROM_UNIXTIME($this->column)) != '$this->argument'"; + } else { + error_log("unimplemented operator in ByDateFilter: $this->operator"); + return ' 1'; + } + } +} + class Id44Filter extends Filter { public function __construct($operator, $argument) |