|
3 | 3 | namespace FiveamCode\LaravelNotionApi\Entities; |
4 | 4 |
|
5 | 5 | use DateTime; |
| 6 | +use FiveamCode\LaravelNotionApi\Entities\Properties\MultiSelect; |
| 7 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Number; |
6 | 8 | use Illuminate\Support\Arr; |
7 | 9 | use Illuminate\Support\Collection; |
8 | 10 | use FiveamCode\LaravelNotionApi\Entities\Properties\Property; |
| 11 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Select; |
| 12 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Text; |
| 13 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Title; |
9 | 14 | use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; |
10 | 15 |
|
11 | 16 | /** |
@@ -55,6 +60,19 @@ class Page extends Entity |
55 | 60 | protected DateTime $lastEditedTime; |
56 | 61 |
|
57 | 62 |
|
| 63 | + /** |
| 64 | + * Page constructor. |
| 65 | + * @param array|null $responseData |
| 66 | + * @throws HandlingException |
| 67 | + * @throws NotionException |
| 68 | + */ |
| 69 | + public function __construct(array $responseData = null) |
| 70 | + { |
| 71 | + $this->properties = new Collection(); |
| 72 | + parent::__construct($responseData); |
| 73 | + } |
| 74 | + |
| 75 | + |
58 | 76 | /** |
59 | 77 | * @param array $responseData |
60 | 78 | * @throws HandlingException |
@@ -126,6 +144,61 @@ private function fillTitle(): void |
126 | 144 | } |
127 | 145 | } |
128 | 146 |
|
| 147 | + /** |
| 148 | + * @param $propertyTitle |
| 149 | + * @param $property |
| 150 | + */ |
| 151 | + public function setProperty(string $propertyTitle, Property $property): void{ |
| 152 | + $property->setTitle($propertyTitle); |
| 153 | + $this->properties->add($property); |
| 154 | + |
| 155 | + if($property instanceof Title){ |
| 156 | + $this->title = $property->getPlainText(); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * @param $propertyTitle |
| 162 | + * @param $number |
| 163 | + */ |
| 164 | + public function setNumber(string $propertyTitle, float $number) : void{ |
| 165 | + $this->setProperty($propertyTitle, Number::instance($number)); |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * @param $propertyTitle |
| 170 | + * @param $text |
| 171 | + */ |
| 172 | + public function setTitle(string $propertyTitle, string $text) : void{ |
| 173 | + $this->setProperty($propertyTitle, Title::instance($text)); |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * @param $propertyTitle |
| 178 | + * @param $text |
| 179 | + */ |
| 180 | + public function setText(string $propertyTitle, string $text) : void{ |
| 181 | + $this->setProperty($propertyTitle, Text::instance($text)); |
| 182 | + } |
| 183 | + |
| 184 | + /** |
| 185 | + * @param $propertyTitle |
| 186 | + * @param $name |
| 187 | + */ |
| 188 | + public function setSelect(string $propertyTitle, string $name) : void{ |
| 189 | + $this->setProperty($propertyTitle, Select::instance($name)); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * @param $propertyTitle |
| 194 | + * @param $names |
| 195 | + */ |
| 196 | + public function setMultiSelect(string $propertyTitle, array $names) : void{ |
| 197 | + $this->setProperty($propertyTitle, MultiSelect::instance($names)); |
| 198 | + } |
| 199 | + |
| 200 | + |
| 201 | + |
129 | 202 | /** |
130 | 203 | * @return string |
131 | 204 | */ |
|
0 commit comments