diff options
Diffstat (limited to 'modules-available/roomplanner/inc')
-rw-r--r-- | modules-available/roomplanner/inc/composedroom.inc.php | 77 | ||||
-rw-r--r-- | modules-available/roomplanner/inc/pvsgenerator.inc.php | 7 |
2 files changed, 81 insertions, 3 deletions
diff --git a/modules-available/roomplanner/inc/composedroom.inc.php b/modules-available/roomplanner/inc/composedroom.inc.php new file mode 100644 index 00000000..11e8455e --- /dev/null +++ b/modules-available/roomplanner/inc/composedroom.inc.php @@ -0,0 +1,77 @@ +<?php + +class ComposedRoom +{ + /** + * @var string How to compose contained rooms. Value is either horizontal or vertical. + */ + public $orientation = 'horizontal'; + + /** + * @var int[] Order in which contained rooms are composed. List of locationid. + */ + public $list; + + /** + * @var bool Whether composed room is active, ie. visible in PVS. + */ + public $enabled; + + /** + * @var int locationid of contained room that is the controlling room; + */ + public $controlRoom; + + public function __construct($data) + { + if ($data instanceof ComposedRoom) { + foreach ($data as $k => $v) { + $this->{$k} = $v; + } + } else { + if (is_array($data) && isset($data['roomplan'])) { + // From DB + $data = json_decode($data['roomplan'], true); + } elseif (is_string($data)) { + // Just JSON + $data = json_decode($data, true); + } + if (is_array($data)) { + foreach ($this as $k => $v) { + if (isset($data[$k])) { + $this->{$k} = $data[$k]; + } + } + } + } + $this->sanitize(); + } + + /** + * Make sure all member vars have the proper type + */ + private function sanitize() + { + $this->orientation = ($this->orientation === 'horizontal' ? 'horizontal' : 'vertical'); + settype($this->enabled, 'bool'); + settype($this->list, 'array'); + settype($this->controlRoom, 'int'); + foreach ($this->list as &$v) { + settype($v, 'int'); + } + $this->list = array_values($this->list); + if (!empty($this->list) && !in_array($this->controlRoom, $this->list)) { + $this->controlRoom = $this->list[0]; + } + } + + /** + * @return false|string JSON + */ + public function serialize() + { + $this->sanitize(); + return json_encode($this); + } + +} diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php index 2a4e2972..cfb38fd2 100644 --- a/modules-available/roomplanner/inc/pvsgenerator.inc.php +++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php @@ -156,7 +156,7 @@ class PvsGenerator * @param int $rotate rotate plan (0-3 for N E S W up, -1 for "auto" if highlightUuid is given) * @return string SVG */ - public static function generateSvg($locationId = false, $highlightUuid = false, $rotate = 0) + public static function generateSvg($locationId = false, $highlightUuid = false, $rotate = 0, $scale = 1) { if ($locationId === false) { $locationId = Database::queryFirst('SELECT fixedlocationid FROM machine @@ -215,8 +215,9 @@ class PvsGenerator self::swap($sizeX, $sizeY); } return Render::parse('svg-plan', [ - 'width' => $sizeX, - 'height' => $sizeY, + 'scale' => $scale, + 'width' => $sizeX * $scale, + 'height' => $sizeY * $scale, 'centerX' => $centerX, 'centerY' => $centerY, 'rotate' => $rotate * 90, |