Skip to content

Commit 0ab4d2f

Browse files
authored
Merge pull request #103 from 5am-code/page-and-property-polish
polish page and properties
2 parents 685e73a + ef0daae commit 0ab4d2f

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

src/Entities/Page.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ class Page extends Entity
5555
*/
5656
private string $coverType = '';
5757

58+
/**
59+
* @var string
60+
*/
61+
private string $parentId = '';
62+
63+
/**
64+
* @var string
65+
*/
66+
private string $parentType = '';
67+
5868
/**
5969
* @var string
6070
*/
@@ -122,6 +132,7 @@ protected function setResponseData(array $responseData): void
122132
private function fillFromRaw(): void
123133
{
124134
$this->fillId();
135+
$this->fillParent();
125136
$this->fillObjectType();
126137
$this->fillProperties();
127138
$this->fillTitle(); // This has to be called after fillProperties(), since title is provided by properties
@@ -205,6 +216,20 @@ private function fillPageUrl(): void
205216
}
206217
}
207218

219+
private function fillParent(): void
220+
{
221+
if (Arr::exists($this->responseData, 'parent')) {
222+
$this->parentType = $this->responseData['parent']['type'];
223+
if (Arr::exists($this->responseData['parent'], 'database_id')) {
224+
$this->parentId = $this->responseData['parent']['database_id'];
225+
} elseif (Arr::exists($this->responseData['parent'], 'page_id')) {
226+
$this->parentId = $this->responseData['parent']['page_id'];
227+
} elseif (Arr::exists($this->responseData['parent'], 'workspace')) {
228+
$this->parentId = $this->responseData['parent']['workspace'];
229+
}
230+
}
231+
}
232+
208233
/**
209234
* @param $propertyTitle
210235
* @param $property
@@ -458,6 +483,22 @@ public function getObjectType(): string
458483
return $this->objectType;
459484
}
460485

486+
/**
487+
* @return string
488+
*/
489+
public function getParentId(): string
490+
{
491+
return $this->parentId;
492+
}
493+
494+
/**
495+
* @return string
496+
*/
497+
public function getParentType(): string
498+
{
499+
return $this->parentType;
500+
}
501+
461502
/**
462503
* @return array
463504
*/

src/Entities/Properties/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function fillDate(): void
9797
$richDate->setHasTime($this->isIsoTimeString($startAsIsoString));
9898
}
9999

100-
if (Arr::exists($this->rawContent, 'end')) {
100+
if (Arr::exists($this->rawContent, 'end') && $this->rawContent['end'] !== null) {
101101
$endAsIsoString = $this->rawContent['end'];
102102
$richDate->setEnd(new DateTime($endAsIsoString));
103103
}

src/Entities/Properties/Text.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public function getContent(): RichText
7777
return $this->getRichText();
7878
}
7979

80+
/**
81+
* @return string
82+
*/
83+
public function asText(): string
84+
{
85+
return $this->getPlainText();
86+
}
87+
8088
/**
8189
* @return RichText
8290
*/

src/Entities/Properties/Title.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public function getContent(): RichText
7676
return $this->getRichText();
7777
}
7878

79+
/**
80+
* @return string
81+
*/
82+
public function asText(): string
83+
{
84+
return $this->getPlainText();
85+
}
86+
7987
/**
8088
* @return RichText
8189
*/

tests/EndpointPagesTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function it_returns_page_entity_with_filled_properties()
7272
$this->assertCount(9, $pageResult->getRawProperties());
7373
$this->assertCount(9, $pageResult->getProperties());
7474
$this->assertCount(9, $pageResult->getPropertyKeys());
75+
$this->assertSame('database_id', $pageResult->getParentType());
76+
$this->assertSame('f2939732-f694-4ce2-b613-f28db6ded673', $pageResult->getParentId());
7577

7678
// check date and datetime properties
7779
$this->assertTrue($pageResult->getProperty('DateWithTime')->hasTime());

tests/PagePropertyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function it_checks_if_specific_page_property_is_a_valid_text_property()
9999
$this->assertSame('text', $text->getType());
100100
$this->assertSame('|Zt@', $text->getId());
101101
$this->assertSame('this is a nice Text :-)', $text->getPlainText());
102+
$this->assertSame('this is a nice Text :-)', $text->asText());
102103
$this->assertInstanceOf(RichText::class, $text->getRichText());
103104
$this->assertInstanceOf(RichText::class, $text->getContent());
104105
$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()
149150
$this->assertSame('title', $title->getType());
150151
$this->assertSame('title', $title->getId());
151152
$this->assertSame('Notion Is Awesome', $title->getPlainText());
153+
$this->assertSame('Notion Is Awesome', $title->asText());
152154
$this->assertInstanceOf(RichText::class, $title->getContent());
153155
$this->assertSame('Notion Is Awesome', $title->getContent()->getPlainText());
154156
}

0 commit comments

Comments
 (0)