From 04828b94e9df8321feae0bfb99daa468c0d3d383 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 23 Jul 2019 13:57:20 +0200 Subject: [roomplanner] Support creating recursive/composed rooms --- .../roomplanner/inc/simpleroom.inc.php | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 modules-available/roomplanner/inc/simpleroom.inc.php (limited to 'modules-available/roomplanner/inc/simpleroom.inc.php') 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 @@ + $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 + } + +} -- cgit v1.2.3-55-g7522