diff options
Diffstat (limited to 'modules-available/statistics/inc/statisticsfilterset.inc.php')
-rw-r--r-- | modules-available/statistics/inc/statisticsfilterset.inc.php | 67 |
1 files changed, 20 insertions, 47 deletions
diff --git a/modules-available/statistics/inc/statisticsfilterset.inc.php b/modules-available/statistics/inc/statisticsfilterset.inc.php index c2642850..a96102dc 100644 --- a/modules-available/statistics/inc/statisticsfilterset.inc.php +++ b/modules-available/statistics/inc/statisticsfilterset.inc.php @@ -3,11 +3,9 @@ class StatisticsFilterSet { /** - * @var \StatisticsFilter[] + * @var \DatabaseFilter[] */ private $filters; - private $sortDirection; - private $sortColumn; private $cache = false; @@ -16,34 +14,17 @@ class StatisticsFilterSet $this->filters = $filters; } - public function setSort($col, $direction) - { - $direction = ($direction === 'DESC' ? 'DESC' : 'ASC'); - - if (!is_string($col) || !array_key_exists($col, StatisticsFilter::$columns)) { - /* default sorting column is clientip */ - $col = 'clientip'; - } - if ($col === $this->sortColumn && $direction === $this->sortDirection) - return; - $this->cache = false; - $this->sortDirection = $direction; - $this->sortColumn = $col; - } - - public function makeFragments(&$where, &$join, &$sort, &$args) + public function makeFragments(&$where, &$join, &$args) { if ($this->cache !== false) { $where = $this->cache['where']; $join = $this->cache['join']; - $sort = $this->cache['sort']; $args = $this->cache['args']; return; } /* generate where clause & arguments */ $where = ''; $joins = []; - $sort = ""; $args = []; if (empty($this->filters)) { $where = ' 1 '; @@ -54,18 +35,7 @@ class StatisticsFilterSet } } $join = implode(' ', array_unique($joins)); - - $col = $this->sortColumn; - $isMapped = array_key_exists('map_sort', StatisticsFilter::$columns[$col]); - $concreteCol = ($isMapped ? StatisticsFilter::$columns[$col]['map_sort'] : $col) ; - - if ($concreteCol === 'clientip') { - $concreteCol = "INET_ATON(clientip)"; - } - - $sort = " ORDER BY " . $concreteCol . " " . $this->sortDirection - . ", machineuuid ASC"; - $this->cache = compact('where', 'join', 'sort', 'args'); + $this->cache = compact('where', 'join', 'args'); } public function isNoId44Filter() @@ -74,33 +44,23 @@ class StatisticsFilterSet return $filter !== false && $filter->argument == 0; } - public function getSortDirection() - { - return $this->sortDirection; - } - - public function getSortColumn() - { - return $this->sortColumn; - } - public function filterNonClients() { if (Module::get('runmode') === false || $this->hasFilter('IsClientFilter') !== false) return; $this->cache = false; // Runmode module exists, add filter - $this->filters[] = new IsClientStatisticsFilter(true); + $this->filters[] = (new IsClientStatisticsFilter())->bind('=', true); } /** * @param string $type filter type (class name) - * @return false|StatisticsFilter The filter, false if not found + * @return false|DatabaseFilter The filter, false if not found */ public function hasFilter($type) { foreach ($this->filters as $filter) { - if (get_class($filter) === $type) { + if ($filter->isClass($type)) { return $filter; } } @@ -108,6 +68,17 @@ class StatisticsFilterSet } /** + * @param string $type filter type key/id + * @return false|DatabaseFilter The filter, false if not found + */ + public function hasFilterKey($type) + { + if (isset($this->filters[$type])) + return $this->filters[$type]; + return false; + } + + /** * Add a location filter based on the allowed permissions for the given permission. * Returns false if the user doesn't have the given permission for any location. * @@ -116,6 +87,8 @@ class StatisticsFilterSet */ public function setAllowedLocationsFromPermission($permission) { + if (!Module::isAvailable('locations')) + return true; $locs = User::getAllowedLocations($permission); if (empty($locs)) return false; @@ -124,7 +97,7 @@ class StatisticsFilterSet return true; unset($this->filters['permissions']); } else { - $this->filters['permissions'] = new LocationStatisticsFilter('=', $locs); + $this->filters['permissions'] = StatisticsFilter::$columns['location']->bind('=', $locs); } $this->cache = false; return true; |