|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace FiveamCode\LaravelNotionApi\Entities\Properties; |
| 4 | + |
| 5 | +use DateTime; |
| 6 | +use FiveamCode\LaravelNotionApi\Entities\Entity; |
| 7 | +use FiveamCode\LaravelNotionApi\Entities\PropertyItems\SelectItem; |
| 8 | +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; |
| 9 | +use FiveamCode\LaravelNotionApi\Notion; |
| 10 | +use Illuminate\Support\Arr; |
| 11 | +use Illuminate\Support\Collection; |
| 12 | + |
| 13 | +class MultiSelect extends Property |
| 14 | +{ |
| 15 | + protected function fillFromRaw(): void |
| 16 | + { |
| 17 | + parent::fillFromRaw(); |
| 18 | + if (!is_array($this->rawContent)) |
| 19 | + throw HandlingException::instance("The property-type is multi_select, however the raw data-structure does not represent this type (= array of items). Please check the raw response-data."); |
| 20 | + |
| 21 | + $itemCollection = new Collection(); |
| 22 | + |
| 23 | + foreach ($this->rawContent as $item) { |
| 24 | + $itemCollection->add(new SelectItem($item)); |
| 25 | + } |
| 26 | + |
| 27 | + $this->content = $itemCollection; |
| 28 | + } |
| 29 | + |
| 30 | + public function getContent(): Collection |
| 31 | + { |
| 32 | + return $this->getItems(); |
| 33 | + } |
| 34 | + |
| 35 | + public function getItems(): Collection |
| 36 | + { |
| 37 | + return $this->content; |
| 38 | + } |
| 39 | + |
| 40 | + public function getNames(): array |
| 41 | + { |
| 42 | + $names = []; |
| 43 | + foreach ($this->getItems() as $item) { |
| 44 | + array_push($names, $item->getName()); |
| 45 | + } |
| 46 | + return $names; |
| 47 | + } |
| 48 | + |
| 49 | + public function getColors(): array |
| 50 | + { |
| 51 | + $colors = []; |
| 52 | + foreach ($this->getItems() as $item) { |
| 53 | + array_push($colors, $item->getColor()); |
| 54 | + } |
| 55 | + return $colors; |
| 56 | + } |
| 57 | +} |
0 commit comments