From 3da096142d44c31e180fb54c02ae9e9ff01b7dda Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 17 Jul 2019 16:52:02 +0200 Subject: [roomplanner] First prototype of composed room editor Saving/loading works, but no entry is generated for pvs.ini. Also this approach fails to meaningfully handle rooms with two removable walls where you also want to use both possible combinations of two combined rooms and a single one. --- .../roomplanner/inc/composedroom.inc.php | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 modules-available/roomplanner/inc/composedroom.inc.php (limited to 'modules-available/roomplanner/inc/composedroom.inc.php') 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 @@ + $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); + } + +} -- cgit v1.2.3-55-g7522