diff options
Diffstat (limited to 'modules-available/statistics/inc/statisticshooks.inc.php')
-rw-r--r-- | modules-available/statistics/inc/statisticshooks.inc.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/modules-available/statistics/inc/statisticshooks.inc.php b/modules-available/statistics/inc/statisticshooks.inc.php new file mode 100644 index 00000000..6b9dfa21 --- /dev/null +++ b/modules-available/statistics/inc/statisticshooks.inc.php @@ -0,0 +1,55 @@ +<?php + +class StatisticsHooks +{ + + private static $row = false; + + private static function getRow(string $machineuuid) + { + if (self::$row !== false) + return; + self::$row = Database::queryFirst('SELECT hostname, clientip, locationid FROM machine WHERE machineuuid = :machineuuid', + ['machineuuid' => $machineuuid]); + } + + /** + * Hook for baseconfig. + * @return false|string Client name, or false if invalid + */ + public static function getBaseconfigName(string $machineuuid) + { + self::getRow($machineuuid); + if (self::$row === false) + return false; + return self::$row['hostname'] ?: self::$row['clientip']; + } + + /** + * Hook for baseconfig. + */ + public static function baseconfigLocationResolver(string $machineuuid): int + { + self::getRow($machineuuid); + if (self::$row === false) + return 0; + return (int)self::$row['locationid']; + } + + /** + * Hook to get inheritance tree for all config vars. + * + * @param string $machineuuid MachineUUID currently being edited + */ + public static function baseconfigInheritance(string $machineuuid): array + { + self::getRow($machineuuid); + if (self::$row === false) + return []; + BaseConfig::prepareWithOverrides([ + 'locationid' => self::$row['locationid'] ?? 0 + ]); + return ConfigHolder::getRecursiveConfig(true); + } + +}
\ No newline at end of file |