diff options
author | Simon Rettberg | 2017-06-23 15:58:40 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-06-23 15:58:40 +0200 |
commit | c22a394095460c79c802ce91480242d38805eb95 (patch) | |
tree | d5221ff6dcb7553c9f438ba878b28c635e8866be /modules-available/statistics | |
parent | [install.php] Add functions for getting and deleting constraints (diff) | |
download | slx-admin-c22a394095460c79c802ce91480242d38805eb95.tar.gz slx-admin-c22a394095460c79c802ce91480242d38805eb95.tar.xz slx-admin-c22a394095460c79c802ce91480242d38805eb95.zip |
[statistics] Helper for getting machine as object from DB (to be extended)
Diffstat (limited to 'modules-available/statistics')
-rw-r--r-- | modules-available/statistics/inc/machine.inc.php | 73 | ||||
-rw-r--r-- | modules-available/statistics/inc/statistics.inc.php | 40 |
2 files changed, 113 insertions, 0 deletions
diff --git a/modules-available/statistics/inc/machine.inc.php b/modules-available/statistics/inc/machine.inc.php new file mode 100644 index 00000000..8cb5e884 --- /dev/null +++ b/modules-available/statistics/inc/machine.inc.php @@ -0,0 +1,73 @@ +<?php + +class Machine +{ + const NO_DATA = 0; + const RAW_DATA = 1; + + /** + * @var string UUID + */ + public $machineuuid; + + /** + * @var int|null locationid machine belongs to + */ + public $locationid; + + /** + * @var string mac address + */ + public $macaddr; + + /** + * @var string client's ip address + */ + public $clientip; + + /** + * @var string client's host name + */ + public $hostname; + + /** + * @var int timestamp of when this machine booted from this server for the first time + */ + public $firstseen; + + /** + * @var int last time this machine was seen active + */ + public $lastseen; + + /** + * @var int timestamp of when the machine was booted, 0 if machine is powered off + */ + public $lastboot; + + /** + * @var int timestamp of when the current user logged in, 0 if machine is idle + */ + public $logintime; + + /** + * @var string json data of position inside room (if any), null/empty otherwise + */ + public $position; + + /** + * @var string|null UUID or name of currently running lecture/session + */ + public $currentsession; + + /** + * @var string|null name of currently logged in user + */ + public $currentuser; + + /** + * @var string|null raw data of machine, if requested + */ + public $data; + +} diff --git a/modules-available/statistics/inc/statistics.inc.php b/modules-available/statistics/inc/statistics.inc.php new file mode 100644 index 00000000..1c9ebf07 --- /dev/null +++ b/modules-available/statistics/inc/statistics.inc.php @@ -0,0 +1,40 @@ +<?php + + + +class Statistics +{ + + private static $machineFields = false; + + /** + * @param string $machineuuid + * @param int $returnData + * @return \Machine|false + */ + public static function getMachine($machineuuid, $returnData) + { + if (self::$machineFields === false) { + $r = new ReflectionClass('Machine'); + $props = $r->getProperties(ReflectionProperty::IS_PUBLIC); + self::$machineFields = array_flip(array_map(function($e) { return $e->getName(); }, $props)); + } + if ($returnData === Machine::NO_DATA) { + unset(self::$machineFields['data']); + } elseif ($returnData === Machine::RAW_DATA) { + self::$machineFields['data'] = true; + } else { + Util::traceError('Invalid $returnData option passed'); + } + $fields = implode(',', array_keys(self::$machineFields)); + $row = Database::queryFirst("SELECT * FROM machine WHERE machineuuid = :machineuuid", compact('machineuuid')); + if ($row === false) + return false; + $m = new Machine(); + foreach ($row as $key => $val) { + $m->{$key} = $val; + } + return $m; + } + +} |