summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/filterset.inc.php
diff options
context:
space:
mode:
authorChristian Klinger2016-07-15 14:18:29 +0200
committerChristian Klinger2016-07-15 14:19:27 +0200
commit6e73dfb95b22524322c2de7a09db04af462b50cc (patch)
tree7078ad789cf0ea6f2df3ab35f2d76e1f0486b425 /modules-available/statistics/inc/filterset.inc.php
parent[syslog] API: Write machineuuid to DB (diff)
downloadslx-admin-6e73dfb95b22524322c2de7a09db04af462b50cc.tar.gz
slx-admin-6e73dfb95b22524322c2de7a09db04af462b50cc.tar.xz
slx-admin-6e73dfb95b22524322c2de7a09db04af462b50cc.zip
Merging some refactoring + new filter functionality.
Diffstat (limited to 'modules-available/statistics/inc/filterset.inc.php')
-rw-r--r--modules-available/statistics/inc/filterset.inc.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/modules-available/statistics/inc/filterset.inc.php b/modules-available/statistics/inc/filterset.inc.php
new file mode 100644
index 00000000..ac928ac4
--- /dev/null
+++ b/modules-available/statistics/inc/filterset.inc.php
@@ -0,0 +1,50 @@
+<?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 (array_key_exists($col, Page_Statistics::$columns)) {
+ $isMapped = array_key_exists('map_sort', Page_Statistics::$columns[$col]);
+ $this->sortColumn = $isMapped ? Page_Statistics::$columns[$col]['map_sort'] : $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));
+
+
+ $sort = " ORDER BY " . $this->sortColumn . " " . $this->sortDirection;
+ }
+ public function getSortDirection() {
+ return $this->sortDirection;
+ }
+ public function getSortColumn() {
+ return $this->sortColumn;
+ }
+}