summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/statisticshooks.inc.php
blob: 746bdabf94684b8fab0c30fc8e21706d0347661e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

class StatisticsHooks
{

	private static $row = false;

	private static function getRow($machineuuid)
	{
		if (self::$row !== false)
			return;
		self::$row = Database::queryFirst('SELECT hostname, clientip, locationid FROM machine WHERE machineuuid = :machineuuid',
			['machineuuid' => $machineuuid]);
	}

	public static function getBaseconfigName($machineuuid)
	{
		self::getRow($machineuuid);
		if (self::$row === false)
			return false;
		return self::$row['hostname'] ? self::$row['hostname'] : self::$row['clientip'];
	}

	public static function baseconfigLocationResolver($machineuuid)
	{
		self::getRow($machineuuid);
		if (self::$row === false)
			return 0;
		return (int)self::$row['locationid'];
	}

	/**
	 * Hook to get inheritance tree for all config vars
	 * @param int $machineuuid MachineUUID currently being edited
	 */
	public static function baseconfigInheritance($machineuuid)
	{
		self::getRow($machineuuid);
		if (self::$row === false)
			return [];
		BaseConfig::prepareWithOverrides([
			'locationid' => self::$row['locationid']
		]);
		return ConfigHolder::getRecursiveConfig(true);
	}

}