From d6bbb4d57a086dfaf5f0a1ebf8913577568ae887 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 21 Apr 2020 18:16:36 +0200 Subject: [statistics] Refactor filter creation (Part 1) Filter classes are now instances of their respective classes, to move more logic into those classes. A bind method is used for assigning actual operator and argument values. renderFilterBox() is still a little too messy, maybe a clever class for mapping a (bound) filter to data for mustache will come in handy here. --- modules-available/statistics/pages/summary.inc.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'modules-available/statistics/pages/summary.inc.php') diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php index c2e3ac80..ead62a26 100644 --- a/modules-available/statistics/pages/summary.inc.php +++ b/modules-available/statistics/pages/summary.inc.php @@ -17,7 +17,6 @@ class SubPage $filters = StatisticsFilter::parseQuery(); $filterSet = new StatisticsFilterSet($filters); - $filterSet->setSort($sortColumn, $sortDirection); if (!$filterSet->setAllowedLocationsFromPermission('view.summary')) { Message::addError('main.no-permission'); @@ -47,7 +46,7 @@ class SubPage */ private static function showSummary($filterSet) { - $filterSet->makeFragments($where, $join, $sort, $args); + $filterSet->makeFragments($where, $join, $args); $known = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE $where", $args); $on = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE state IN ('IDLE', 'OCCUPIED') AND ($where)", $args); $used = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE state = 'OCCUPIED' AND ($where)", $args); @@ -100,7 +99,7 @@ class SubPage */ private static function showSystemModels($filterSet) { - $filterSet->makeFragments($where, $join, $sort, $args); + $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery('SELECT systemmodel, Round(AVG(realcores)) AS cores, Count(*) AS `count` FROM machine m' . " $join WHERE $where GROUP BY systemmodel ORDER BY `count` DESC, systemmodel ASC", $args); $lines = array(); @@ -130,8 +129,9 @@ class SubPage */ private static function showMemory($filterSet) { - $filterSet->makeFragments($where, $join, $sort, $args); - $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY mbram", $args); + $filterSet->makeFragments($where, $join, $args); + $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join + WHERE $where GROUP BY mbram", $args); $lines = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $gb = (int)ceil($row['mbram'] / 1024); @@ -174,9 +174,10 @@ class SubPage */ private static function showKvmState($filterSet) { - $filterSet->makeFragments($where, $join, $sort, $args); + $filterSet->makeFragments($where, $join, $args); $colors = array('UNKNOWN' => '#666', 'UNSUPPORTED' => '#ea5', 'DISABLED' => '#e55', 'ENABLED' => '#6d6'); - $res = Database::simpleQuery("SELECT kvmstate, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY kvmstate ORDER BY `count` DESC", $args); + $res = Database::simpleQuery("SELECT kvmstate, Count(*) AS `count` FROM machine m $join + WHERE $where GROUP BY kvmstate ORDER BY `count` DESC", $args); $lines = array(); $json = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { @@ -195,7 +196,7 @@ class SubPage */ private static function showId44($filterSet) { - $filterSet->makeFragments($where, $join, $sort, $args); + $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery("SELECT id44mb, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY id44mb", $args); $lines = array(); $total = 0; @@ -245,7 +246,7 @@ class SubPage */ private static function showLatestMachines($filterSet) { - $filterSet->makeFragments($where, $join, $sort, $args); + $filterSet->makeFragments($where, $join, $args); $args['cutoff'] = ceil(time() / 3600) * 3600 - 86400 * 10; $res = Database::simpleQuery("SELECT machineuuid, clientip, hostname, firstseen, mbram, kvmstate, id44mb FROM machine m $join" -- cgit v1.2.3-55-g7522