Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Get/set functionality for Number and MultiSelect properties #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Notion/Properties/MultiSelect.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
<?php namespace Notion\Properties;

use Notion\PropertyBase;
use Illuminate\Support\Arr;

class MultiSelect extends PropertyBase
{

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 = array_map(fn($el) => (object)['name' => (string)$el], $value);
}

public function getValue()
{
$withoutOptions = Arr::except((array)$this->config->multi_select, 'options');
return count($withoutOptions) ? (object)$withoutOptions : null;
}
}
15 changes: 15 additions & 0 deletions src/Notion/Properties/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}