diff options
Diffstat (limited to 'modules-available/statistics/inc')
4 files changed, 23 insertions, 11 deletions
diff --git a/modules-available/statistics/inc/devicetype.inc.php b/modules-available/statistics/inc/devicetype.inc.php deleted file mode 100644 index a01ec310..00000000 --- a/modules-available/statistics/inc/devicetype.inc.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -class DeviceType -{ - const SCREEN = 'SCREEN'; - -} diff --git a/modules-available/statistics/inc/hardwareinfo.inc.php b/modules-available/statistics/inc/hardwareinfo.inc.php index 9ccf88be..6ca070ee 100644 --- a/modules-available/statistics/inc/hardwareinfo.inc.php +++ b/modules-available/statistics/inc/hardwareinfo.inc.php @@ -12,6 +12,7 @@ class HardwareInfo const PCI_DEVICE = 'PCI_DEVICE'; const HDD = 'HDD'; const CPU = 'CPU'; + const SCREEN = 'SCREEN'; /** * Get a KCL modification string for the given machine, enabling GVT, PCI passthrough etc. diff --git a/modules-available/statistics/inc/hardwarequery.inc.php b/modules-available/statistics/inc/hardwarequery.inc.php index 525e05e8..00a9bbc9 100644 --- a/modules-available/statistics/inc/hardwarequery.inc.php +++ b/modules-available/statistics/inc/hardwarequery.inc.php @@ -131,10 +131,11 @@ class HardwareQuery */ public function buildQuery(string $groupBy = ''): string { + $groupConcat = !empty($groupBy) && $groupBy !== 'mxhw.machinehwid'; $columns = []; foreach ($this->columns as $column) { if ($column instanceof HardwareQueryColumn) { - $column->generate($this->joins, $columns, $this->args); + $column->generate($this->joins, $columns, $this->args, $groupConcat); } else { $columns[] = $column; } diff --git a/modules-available/statistics/inc/hardwarequerycolumn.inc.php b/modules-available/statistics/inc/hardwarequerycolumn.inc.php index 71793008..d073530b 100644 --- a/modules-available/statistics/inc/hardwarequerycolumn.inc.php +++ b/modules-available/statistics/inc/hardwarequerycolumn.inc.php @@ -11,6 +11,7 @@ class HardwareQueryColumn private $alias; private $conditions = []; private $params = []; + private $classId; private static function getId(): string { @@ -19,13 +20,19 @@ class HardwareQueryColumn public function __construct(bool $global, string $column, string $alias = null) { + $this->classId = ++self::$id; $this->global = $global; $this->tableAlias = self::getId(); $this->virtualColumnName = $column; $this->alias = $alias ?? $column; } - public function generate(array &$joins, array &$columns, array &$params) + /** + * Add necessary conditions, joins, columns to final SQL arrays. To be called + * from HardwareQuery::buildQuery(). + * @param bool $groupConcat whether to add distinct GROUP_CONCAT to column. + */ + public function generate(array &$joins, array &$columns, array &$params, bool $groupConcat) { if ($this->global) { $srcTable = 'shw'; @@ -46,7 +53,11 @@ class HardwareQueryColumn // INNER JOIN, so the result will be empty if the condition doesn't match. $type = count($this->conditions) === 1 ? 'LEFT' : 'INNER'; $joins[] = "$type JOIN $table $tid ON (" . implode(' AND ', $this->conditions) . ")"; - $columns[] = "$tid.`value` AS `{$this->alias}`"; + if ($groupConcat) { + $columns[] = "Group_Concat(DISTINCT $tid.`value` SEPARATOR ', ') AS `{$this->alias}`"; + } else { + $columns[] = "$tid.`value` AS `{$this->alias}`"; + } $params += $this->params; } @@ -60,7 +71,13 @@ class HardwareQueryColumn { $valueCol = ($op === '<' || $op === '>' || $op === '<=' || $op === '>=') ? 'numeric' : 'value'; if ($other instanceof HardwareQueryColumn) { - $this->conditions[] = "{$this->tableAlias}.`$valueCol` $op {$other->tableAlias}.`$valueCol`"; + $cond = "{$this->tableAlias}.`$valueCol` $op {$other->tableAlias}.`$valueCol`"; + // Don't reference a column of a table that hasn't been joined yet + if ($this->classId > $other->classId) { + $this->conditions[] = $cond; + } else { + $other->conditions[] = $cond; + } } else { $pid = self::getId(); $this->conditions[] = "{$this->tableAlias}.`$valueCol` $op (:$pid)"; |