From 99a6e96ce9d7710ea4ed2e6aae8509ce25b55f52 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 18 Mar 2019 12:47:39 +0100 Subject: [PATCH] Visual Console Refactor: added a Visual Console model Former-commit-id: e3ae133ce6ab9c5df3c3f9c079af122e9af92e6c --- .../models/VisualConsole/Container.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 pandora_console/include/rest-api/models/VisualConsole/Container.php diff --git a/pandora_console/include/rest-api/models/VisualConsole/Container.php b/pandora_console/include/rest-api/models/VisualConsole/Container.php new file mode 100644 index 0000000000..b27168f370 --- /dev/null +++ b/pandora_console/include/rest-api/models/VisualConsole/Container.php @@ -0,0 +1,119 @@ +extractGroupId($data); + } + + + private function decode(array $data): array + { + return [ + 'id' => (int) $data['id'], + 'name' => $data['name'], + 'groupId' => $this->extractGroupId($data), + 'backgroundURL' => $this->extractBackgroundUrl($data), + 'backgroundColor' => $this->extractBackgroundColor($data), + 'isFavorite' => Model::parseBool($data['is_favourite']) + || Model::parseBool($data['isFavorite']), + 'width' => (int) $data['width'], + 'height' => (int) $data['height'], + ]; + } + + + private function extractGroupId(array $data): number + { + if (isset($data['id_group']) === true + && \is_numeric($data['id_group']) === true + ) { + return $data['id_group']; + } else if (isset($data['groupId']) === true + && \is_numeric($data['groupId']) === true + ) { + return $data['groupId']; + } + + throw new \InvalidArgumentException( + 'the group Id property is required and should be integer' + ); + } + + + private function extractBackgroundUrl(array $data): mixed + { + $backgroundUrl = Model::notEmptyStringOr($data['background'], null); + if ($backgroundUrl !== null) { + return $backgroundUrl; + } + + $backgroundUrl = Model::notEmptyStringOr($data['backgroundURL'], null); + if ($backgroundUrl !== null) { + return $backgroundUrl; + } + + return null; + } + + + private function extractBackgroundColor(array $data): mixed + { + $backgroundColor = Model::notEmptyStringOr($data['background_color'], null); + if ($backgroundColor !== null) { + return $backgroundColor; + } + + $backgroundColor = Model::notEmptyStringOr($data['backgroundColor'], null); + if ($backgroundColor !== null) { + return $backgroundColor; + } + + return null; + } + + +}