From 156650b462b66d5cfad35367484e184e6f4c34c8 Mon Sep 17 00:00:00 2001 From: Mikhail Lisnyak Date: Sun, 13 Feb 2022 12:58:18 +0300 Subject: [PATCH 1/2] Implement value get/set functionality for Number and MultiSelect properties --- src/Notion/Properties/MultiSelect.php | 31 +++++++++++++++++++++++++++ src/Notion/Properties/Number.php | 15 +++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/Notion/Properties/MultiSelect.php b/src/Notion/Properties/MultiSelect.php index a062876..f9022c3 100644 --- a/src/Notion/Properties/MultiSelect.php +++ b/src/Notion/Properties/MultiSelect.php @@ -4,4 +4,35 @@ class MultiSelect extends PropertyBase { + + public function value() + { + return $this->config->multi_select->selected_values ?? null; + } + + + public function set($value): void + { + if (!isset($this->config->multi_select)) { + $this->config->multi_select = (object)[]; + } + + if(!is_array($value)) $value = [$value]; + $this->config->multi_select->selected_values = $value; + } + + public function get() + { + if (isset($this->getValue()?->selected_values)) { + return [ + 'multi_select' => array_map(fn($el) => ['name' => (string)$el], $this->getValue()?->selected_values) + ]; + } + return null; + } + + public function getValue() + { + return $this->config->multi_select; + } } diff --git a/src/Notion/Properties/Number.php b/src/Notion/Properties/Number.php index 6f0a1d9..b250d4f 100644 --- a/src/Notion/Properties/Number.php +++ b/src/Notion/Properties/Number.php @@ -4,4 +4,19 @@ class Number extends PropertyBase { + public function value() + { + return $this->config->number; + } + + public function set($value): void + { + + $this->config->number = ($value === (int)$value) ? (int)$value : (float)$value; + } + + public function getValue() + { + return $this->config->number; + } } From 182ac6ac48ef8a18da5686901c63664638d4b425 Mon Sep 17 00:00:00 2001 From: Mikhail Lisnyak Date: Sun, 13 Feb 2022 17:49:39 +0300 Subject: [PATCH 2/2] fix multiselect --- src/Notion/Properties/MultiSelect.php | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/Notion/Properties/MultiSelect.php b/src/Notion/Properties/MultiSelect.php index f9022c3..11922dd 100644 --- a/src/Notion/Properties/MultiSelect.php +++ b/src/Notion/Properties/MultiSelect.php @@ -1,38 +1,24 @@ config->multi_select->selected_values ?? null; - } - - public function set($value): void { if (!isset($this->config->multi_select)) { $this->config->multi_select = (object)[]; } - if(!is_array($value)) $value = [$value]; - $this->config->multi_select->selected_values = $value; - } - - public function get() - { - if (isset($this->getValue()?->selected_values)) { - return [ - 'multi_select' => array_map(fn($el) => ['name' => (string)$el], $this->getValue()?->selected_values) - ]; - } - return null; + if (!is_array($value)) $value = [$value]; + $this->config->multi_select = array_map(fn($el) => (object)['name' => (string)$el], $value); } public function getValue() { - return $this->config->multi_select; + $withoutOptions = Arr::except((array)$this->config->multi_select, 'options'); + return count($withoutOptions) ? (object)$withoutOptions : null; } }