diff options
author | Simon Rettberg | 2019-07-23 13:57:20 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-07-23 13:57:20 +0200 |
commit | 04828b94e9df8321feae0bfb99daa468c0d3d383 (patch) | |
tree | e3b00490dc14a0f5d6ffda5bab1ce7c82bafee52 /modules-available/roomplanner/inc/simpleroom.inc.php | |
parent | slx-fixes.js: Make .cachedScript more compatible to .getScript (diff) | |
download | slx-admin-04828b94e9df8321feae0bfb99daa468c0d3d383.tar.gz slx-admin-04828b94e9df8321feae0bfb99daa468c0d3d383.tar.xz slx-admin-04828b94e9df8321feae0bfb99daa468c0d3d383.zip |
[roomplanner] Support creating recursive/composed rooms
Diffstat (limited to 'modules-available/roomplanner/inc/simpleroom.inc.php')
-rw-r--r-- | modules-available/roomplanner/inc/simpleroom.inc.php | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/modules-available/roomplanner/inc/simpleroom.inc.php b/modules-available/roomplanner/inc/simpleroom.inc.php new file mode 100644 index 00000000..78db6c4a --- /dev/null +++ b/modules-available/roomplanner/inc/simpleroom.inc.php @@ -0,0 +1,148 @@ +<?php + +class SimpleRoom extends Room +{ + + const CLIENT_SIZE = 4; + + private $machines = []; + + private $bb = false; + + private $tutorIp = false; + + private $managerIp = false; + + public function __construct($row) + { + parent::__construct($row); + $locationId = (int)$row['locationid']; + $ret = Database::simpleQuery( + 'SELECT machineuuid, clientip, position FROM machine WHERE fixedlocationid = :locationid', + ['locationid' => $locationId]); + + while ($clientRow = $ret->fetch(PDO::FETCH_ASSOC)) { + $position = json_decode($clientRow['position'], true); + + if ($position === false || !isset($position['gridRow']) || !isset($position['gridCol'])) + continue; // TODO: Remove entry/set to NULL? + + $rotation = 'north'; + if (preg_match('/(north|east|south|west)/', $position['itemlook'], $out)) { + $rotation = $out[1]; + } + $this->machines[] = array( + 'machineuuid' => $clientRow['machineuuid'], + 'clientip' => $clientRow['clientip'], + 'gridRow' => $position['gridRow'], + 'gridCol' => $position['gridCol'], + 'rotation' => $rotation, + ); + } + // Runmode info overrides IP given + if (Module::isAvailable('runmode')) { + $pc = RunMode::getForMode('roomplanner', $locationId, true); + if (!empty($pc)) { + $pc = array_pop($pc); + $row['managerip'] = $pc['clientip']; + } + } + if (!empty($row['managerip'])) { + $this->managerIp = $row['managerip']; + } + if (!empty($row['tutorip'])) { + $this->tutorIp = $row['tutorip']; + } + } + + public function machineCount() + { + return count($this->machines); + } + + public function getSize(&$width, &$height) + { + if (empty($this->machines)) { + $width = $height = 0; + return; + } + $this->boundingBox($minX, $minY, $maxX, $maxY); + // client's size that cannot be configured as of today + $width = max($maxX - $minX + self::CLIENT_SIZE, 1); + $height = max($maxY - $minY + self::CLIENT_SIZE, 1); + } + + public function getIniClientSection(&$i, $offX = 0, $offY = 0) + { + /* output individual client positions, shift coordinates to requested position */ + $out = ''; + $this->boundingBox($minX, $minY, $maxX, $maxY); + foreach ($this->machines as $pos) { + $i++; + $out .= "client\\$i\\ip={$pos['clientip']}\n" + . "client\\$i\\pos=@Point(" . ($pos['gridCol'] + $offX -$minX) . ' ' . ($pos['gridRow'] + $offY - $minY) . ")\n"; + } + + return $out; + } + + public function getShiftedArray($offX = 0, $offY = 0) + { + /* output individual client positions, shift coordinates to requested position */ + $ret = []; + $this->boundingBox($minX, $minY, $maxX, $maxY); + foreach ($this->machines as $pos) { + $pos['gridCol'] += $offX - $minX; + $pos['gridRow'] += $offY - $minY; + $ret[] = $pos; + } + + return $ret; + } + + private function boundingBox(&$minX, &$minY, &$maxX, &$maxY) + { + if ($this->bb !== false) { + $minX = $this->bb[0]; + $minY = $this->bb[1]; + $maxX = $this->bb[2]; + $maxY = $this->bb[3]; + } else { + $minX = $minY = PHP_INT_MAX; /* PHP_INT_MIN is only available since PHP 7 */ + $maxX = $maxY = ~PHP_INT_MAX; + foreach ($this->machines as $pos) { + $minX = min($minX, $pos['gridCol']); + $maxX = max($maxX, $pos['gridCol']); + $minY = min($minY, $pos['gridRow']); + $maxY = max($maxY, $pos['gridRow']); + } + $this->bb = [$minX, $minY, $maxX, $maxY]; + } + } + + public function getManagerIp() + { + return $this->managerIp; + } + + public function getTutorIp() + { + return $this->tutorIp; + } + + public function isLeaf() + { + return true; + } + + public function shouldSkip() + { + return empty($this->machines); + } + + protected function sanitize() + { + // Nothing + } + +} |