Skip to content
Merged
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
41 changes: 41 additions & 0 deletions src/Entities/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class Page extends Entity
*/
private string $coverType = '';

/**
* @var string
*/
private string $parentId = '';

/**
* @var string
*/
private string $parentType = '';

/**
* @var string
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Properties/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
8 changes: 8 additions & 0 deletions src/Entities/Properties/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public function getContent(): RichText
return $this->getRichText();
}

/**
* @return string
*/
public function asText(): string
{
return $this->getPlainText();
}

/**
* @return RichText
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Entities/Properties/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public function getContent(): RichText
return $this->getRichText();
}

/**
* @return string
*/
public function asText(): string
{
return $this->getPlainText();
}

/**
* @return RichText
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/EndpointPagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/PagePropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
Expand Down