From c94d4ca0cc467f1ded417a9fae1f3128a2fdda54 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 7 Dec 2017 17:06:33 +0100 Subject: [statistics] location filter: Support recursive matching by (ab)using ~ and !~ --- modules-available/statistics/inc/filter.inc.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'modules-available/statistics/inc') diff --git a/modules-available/statistics/inc/filter.inc.php b/modules-available/statistics/inc/filter.inc.php index 6e437a71..be6df752 100644 --- a/modules-available/statistics/inc/filter.inc.php +++ b/modules-available/statistics/inc/filter.inc.php @@ -208,15 +208,22 @@ class LocationFilter extends Filter public function whereClause(&$args, &$joins) { + $recursive = (substr($this->operator, -1) === '~'); + $this->operator = str_replace('~', '=', $this->operator); + settype($this->argument, 'int'); + $neg = $this->operator === '=' ? '' : 'NOT'; if ($this->argument === 0) { - $neg = $this->operator === '=' ? '' : 'NOT'; return "machine.locationid IS $neg NULL"; } else { global $unique_key; $key = $this->column . '_arg' . ($unique_key++); - $args[$key] = $this->argument; - return "machine.locationid {$this->operator} :$key"; + if ($recursive) { + $args[$key] = array_keys(Location::getRecursiveFlat($this->argument)); + } else { + $args[$key] = $this->argument; + } + return "machine.locationid $neg IN (:$key)"; } } } -- cgit v1.2.3-55-g7522