From 6e73dfb95b22524322c2de7a09db04af462b50cc Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Fri, 15 Jul 2016 14:18:29 +0200 Subject: Merging some refactoring + new filter functionality. --- modules-available/statistics/inc/filterset.inc.php | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 modules-available/statistics/inc/filterset.inc.php (limited to 'modules-available/statistics/inc/filterset.inc.php') 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 @@ +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; + } +} -- cgit v1.2.3-55-g7522