From 1bdf3d4ce66910f07842c7be1043938bccf0a462 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 12 Jan 2022 17:07:42 +0100 Subject: [statistics] Make query builder a bit more OOP --- modules-available/statistics/pages/hints.inc.php | 22 ++++++++++++++++++---- modules-available/statistics/pages/machine.inc.php | 2 +- .../statistics/pages/projectors.inc.php | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) (limited to 'modules-available/statistics/pages') diff --git a/modules-available/statistics/pages/hints.inc.php b/modules-available/statistics/pages/hints.inc.php index 278c0e26..67c42a18 100644 --- a/modules-available/statistics/pages/hints.inc.php +++ b/modules-available/statistics/pages/hints.inc.php @@ -19,6 +19,10 @@ class SubPage self::showUnusedSpace($locs); } + /** + * Machines that have less than 8GB of RAM. Highlight those + * that still have free memory slots. + */ private static function showMemoryUpgrade(array $locs) { $q = new HardwareQuery(HardwareInfo::MAINBOARD); @@ -30,7 +34,8 @@ class SubPage $q->addGlobalColumn('Memory Maximum Capacity'); $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); - $q->addWhere(false, 'Memory Installed Capacity', '<', 8 * 1024 * 1024 * 1024); + $col = $q->addLocalColumn('Memory Installed Capacity'); + $col->addCondition('<', 8 * 1024 * 1024 * 1024); $list = []; foreach ($q->query() as $row) { if (HardwareParser::convertSize($row['Memory Installed Capacity'], 'M', false) @@ -47,6 +52,10 @@ class SubPage Render::addTemplate('hints-ram-upgrade', ['list' => $list]); } + /** + * Show machines where RAM modules are running slower + * than their design speed. + */ private static function showMemorySlow(array $locs) { $q = new HardwareQuery(HardwareInfo::RAM_MODULE); @@ -62,11 +71,16 @@ class SubPage $q->addLocalColumn('Serial Number'); $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); - $q->addCompare(true, 'Speed', '>', false, 'Configured Memory Speed'); + $col = $q->addGlobalColumn('Speed'); + $col->addCondition('>', $q->addLocalColumn('Configured Memory Speed')); $list = $q->query()->fetchAll(); Render::addTemplate('hints-ram-underclocked', ['list' => $list]); } + /** + * Show machines that have unpartitioned space available, + * and no ID44 or ID45. + */ private static function showUnusedSpace(array $locs) { $id44 = $id45 = []; @@ -77,7 +91,7 @@ class SubPage } $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); - $q->addWhere(false, 'unused', '>', 2000000000); // 2 GB + $q->addLocalColumn('unused')->addCondition('>', 2000000000); // 2 GB $q->addMachineWhere('id44mb', '<', 20000); // 20 GB foreach ($q->query()->fetchAll() as $row) { $row['unused_s'] = Util::readableFileSize($row['unused']); @@ -91,7 +105,7 @@ class SubPage } $q->addMachineColumn('clientip'); $q->addMachineColumn('hostname'); - $q->addWhere(false, 'unused', '>', 25000000000); // 25 GB + $q->addLocalColumn('unused')->addCondition('>', 25000000000); // 25 GB $q->addMachineWhere('id44mb', '>', 20000); // 20 GB $q->addMachineWhere('id45mb', '<', 20000); // 20 GB foreach ($q->query()->fetchAll() as $row) { diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index 019b0d8d..6ea0ce28 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -229,7 +229,7 @@ class SubPage . " LEFT JOIN machine_x_hw_prop p ON (m.machinehwid = p.machinehwid AND p.prop = 'resolution')" . " LEFT JOIN statistic_hw_prop q ON (m.hwid = q.hwid AND q.prop = 'projector')" . " WHERE m.machineuuid = :uuid", - array('screen' => DeviceType::SCREEN, 'uuid' => $uuid)); + array('screen' => HardwareInfo::SCREEN, 'uuid' => $uuid)); $client['screens'] = array(); $ports = array(); foreach ($res as $row) { diff --git a/modules-available/statistics/pages/projectors.inc.php b/modules-available/statistics/pages/projectors.inc.php index 97a21ebd..91abfe9c 100644 --- a/modules-available/statistics/pages/projectors.inc.php +++ b/modules-available/statistics/pages/projectors.inc.php @@ -49,7 +49,7 @@ class SubPage . " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)" . " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array( 'projector' => 'projector', - 'screen' => DeviceType::SCREEN, + 'screen' => HardwareInfo::SCREEN, )); $data = array( 'projectors' => $res->fetchAll() -- cgit v1.2.3-55-g7522