diff --git a/src/Entities/Page.php b/src/Entities/Page.php index 77e6609..08d03d1 100644 --- a/src/Entities/Page.php +++ b/src/Entities/Page.php @@ -55,6 +55,16 @@ class Page extends Entity */ private string $coverType = ''; + /** + * @var string + */ + private string $parentId = ''; + + /** + * @var string + */ + private string $parentType = ''; + /** * @var string */ @@ -122,6 +132,7 @@ protected function setResponseData(array $responseData): void private function fillFromRaw(): void { $this->fillId(); + $this->fillParent(); $this->fillObjectType(); $this->fillProperties(); $this->fillTitle(); // This has to be called after fillProperties(), since title is provided by properties @@ -205,6 +216,20 @@ private function fillPageUrl(): void } } + private function fillParent(): void + { + if (Arr::exists($this->responseData, 'parent')) { + $this->parentType = $this->responseData['parent']['type']; + if (Arr::exists($this->responseData['parent'], 'database_id')) { + $this->parentId = $this->responseData['parent']['database_id']; + } elseif (Arr::exists($this->responseData['parent'], 'page_id')) { + $this->parentId = $this->responseData['parent']['page_id']; + } elseif (Arr::exists($this->responseData['parent'], 'workspace')) { + $this->parentId = $this->responseData['parent']['workspace']; + } + } + } + /** * @param $propertyTitle * @param $property @@ -458,6 +483,22 @@ public function getObjectType(): string return $this->objectType; } + /** + * @return string + */ + public function getParentId(): string + { + return $this->parentId; + } + + /** + * @return string + */ + public function getParentType(): string + { + return $this->parentType; + } + /** * @return array */ diff --git a/src/Entities/Properties/Date.php b/src/Entities/Properties/Date.php index 5a7fc1f..332d1f2 100644 --- a/src/Entities/Properties/Date.php +++ b/src/Entities/Properties/Date.php @@ -97,7 +97,7 @@ protected function fillDate(): void $richDate->setHasTime($this->isIsoTimeString($startAsIsoString)); } - if (Arr::exists($this->rawContent, 'end')) { + if (Arr::exists($this->rawContent, 'end') && $this->rawContent['end'] !== null) { $endAsIsoString = $this->rawContent['end']; $richDate->setEnd(new DateTime($endAsIsoString)); } diff --git a/src/Entities/Properties/Text.php b/src/Entities/Properties/Text.php index 7fad01c..84df2e4 100644 --- a/src/Entities/Properties/Text.php +++ b/src/Entities/Properties/Text.php @@ -77,6 +77,14 @@ public function getContent(): RichText return $this->getRichText(); } + /** + * @return string + */ + public function asText(): string + { + return $this->getPlainText(); + } + /** * @return RichText */ diff --git a/src/Entities/Properties/Title.php b/src/Entities/Properties/Title.php index 4962a06..5d7e502 100644 --- a/src/Entities/Properties/Title.php +++ b/src/Entities/Properties/Title.php @@ -76,6 +76,14 @@ public function getContent(): RichText return $this->getRichText(); } + /** + * @return string + */ + public function asText(): string + { + return $this->getPlainText(); + } + /** * @return RichText */ diff --git a/tests/EndpointPagesTest.php b/tests/EndpointPagesTest.php index cd33a19..770e62c 100644 --- a/tests/EndpointPagesTest.php +++ b/tests/EndpointPagesTest.php @@ -72,6 +72,8 @@ public function it_returns_page_entity_with_filled_properties() $this->assertCount(9, $pageResult->getRawProperties()); $this->assertCount(9, $pageResult->getProperties()); $this->assertCount(9, $pageResult->getPropertyKeys()); + $this->assertSame('database_id', $pageResult->getParentType()); + $this->assertSame('f2939732-f694-4ce2-b613-f28db6ded673', $pageResult->getParentId()); // check date and datetime properties $this->assertTrue($pageResult->getProperty('DateWithTime')->hasTime()); diff --git a/tests/PagePropertyTest.php b/tests/PagePropertyTest.php index bf02ace..739dbf2 100644 --- a/tests/PagePropertyTest.php +++ b/tests/PagePropertyTest.php @@ -99,6 +99,7 @@ public function it_checks_if_specific_page_property_is_a_valid_text_property() $this->assertSame('text', $text->getType()); $this->assertSame('|Zt@', $text->getId()); $this->assertSame('this is a nice Text :-)', $text->getPlainText()); + $this->assertSame('this is a nice Text :-)', $text->asText()); $this->assertInstanceOf(RichText::class, $text->getRichText()); $this->assertInstanceOf(RichText::class, $text->getContent()); $this->assertSame('this is a nice Text :-)', $text->getRichText()->getPlainText()); @@ -149,6 +150,7 @@ public function it_checks_if_specific_page_property_is_a_valid_title_property() $this->assertSame('title', $title->getType()); $this->assertSame('title', $title->getId()); $this->assertSame('Notion Is Awesome', $title->getPlainText()); + $this->assertSame('Notion Is Awesome', $title->asText()); $this->assertInstanceOf(RichText::class, $title->getContent()); $this->assertSame('Notion Is Awesome', $title->getContent()->getPlainText()); }