22
33namespace FiveamCode \LaravelNotionApi \Entities ;
44
5- use DateTime ;
65use FiveamCode \LaravelNotionApi \Entities \Properties \Property ;
6+ use FiveamCode \LaravelNotionApi \Entities \PropertyItems \RichText ;
77use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
8+ use FiveamCode \LaravelNotionApi \Traits \HasArchive ;
9+ use FiveamCode \LaravelNotionApi \Traits \HasParent ;
10+ use FiveamCode \LaravelNotionApi \Traits \HasTimestamps ;
811use Illuminate \Support \Arr ;
912use Illuminate \Support \Collection ;
1013
1316 */
1417class Database extends Entity
1518{
19+ use HasTimestamps, HasArchive, HasParent;
20+
1621 /**
1722 * @var string
1823 */
1924 protected string $ title = '' ;
2025
26+ /**
27+ * @var string
28+ */
29+ protected string $ description = '' ;
30+
2131 /**
2232 * @var string
2333 */
@@ -44,14 +54,19 @@ class Database extends Entity
4454 private string $ url ;
4555
4656 /**
47- * @var string
57+ * @var ?RichText
4858 */
49- protected string $ objectType = '' ;
59+ protected ? RichText $ richTitle = null ;
5060
5161 /**
52- * @var array
62+ * @var ?RichText
5363 */
54- protected array $ rawTitle = [];
64+ protected ?RichText $ richDescription = null ;
65+
66+ /**
67+ * @var bool
68+ */
69+ protected bool $ isInline = false ;
5570
5671 /**
5772 * @var array
@@ -73,16 +88,6 @@ class Database extends Entity
7388 */
7489 protected Collection $ properties ;
7590
76- /**
77- * @var DateTime
78- */
79- protected DateTime $ createdTime ;
80-
81- /**
82- * @var DateTime
83- */
84- protected DateTime $ lastEditedTime ;
85-
8691 protected function setResponseData (array $ responseData ): void
8792 {
8893 parent ::setResponseData ($ responseData );
@@ -94,22 +99,39 @@ protected function setResponseData(array $responseData): void
9499
95100 private function fillFromRaw ()
96101 {
97- $ this -> fillId ();
102+ parent :: fillEntityBase ();
98103 $ this ->fillIcon ();
99104 $ this ->fillCover ();
100105 $ this ->fillTitle ();
101- $ this ->fillObjectType ();
106+ $ this ->fillIsInline ();
107+ $ this ->fillDescription ();
102108 $ this ->fillProperties ();
103109 $ this ->fillDatabaseUrl ();
104- $ this ->fillCreatedTime ();
105- $ this ->fillLastEditedTime ();
110+ $ this ->fillParentAttributes ();
111+ $ this ->fillArchivedAttributes ();
112+ $ this ->fillTimestampableAttributes ();
106113 }
107114
108115 private function fillTitle (): void
109116 {
110117 if (Arr::exists ($ this ->responseData , 'title ' ) && is_array ($ this ->responseData ['title ' ])) {
111118 $ this ->title = Arr::first ($ this ->responseData ['title ' ], null , ['plain_text ' => '' ])['plain_text ' ];
112- $ this ->rawTitle = $ this ->responseData ['title ' ];
119+ $ this ->richTitle = new RichText ($ this ->responseData ['title ' ]);
120+ }
121+ }
122+
123+ private function fillIsInline (): void
124+ {
125+ if (Arr::exists ($ this ->responseData , 'is_inline ' )) {
126+ $ this ->isInline = $ this ->responseData ['is_inline ' ];
127+ }
128+ }
129+
130+ private function fillDescription (): void
131+ {
132+ if (Arr::exists ($ this ->responseData , 'description ' ) && is_array ($ this ->responseData ['description ' ])) {
133+ $ this ->description = Arr::first ($ this ->responseData ['description ' ], null , ['plain_text ' => '' ])['plain_text ' ];
134+ $ this ->richDescription = new RichText ($ this ->responseData ['description ' ]);
113135 }
114136 }
115137
@@ -146,13 +168,6 @@ private function fillCover(): void
146168 }
147169 }
148170
149- private function fillObjectType (): void
150- {
151- if (Arr::exists ($ this ->responseData , 'object ' )) {
152- $ this ->objectType = $ this ->responseData ['object ' ];
153- }
154- }
155-
156171 private function fillProperties (): void
157172 {
158173 if (Arr::exists ($ this ->responseData , 'properties ' )) {
@@ -184,17 +199,25 @@ public function getProperty(string $propertyKey): ?Property
184199 /**
185200 * @return string
186201 */
187- public function getObjectType (): string
202+ public function getTitle (): string
188203 {
189- return $ this ->objectType ;
204+ return $ this ->title ;
205+ }
206+
207+ /**
208+ * @return bool
209+ */
210+ public function isInline (): bool
211+ {
212+ return $ this ->isInline ;
190213 }
191214
192215 /**
193216 * @return string
194217 */
195- public function getTitle (): string
218+ public function getDescription (): string
196219 {
197- return $ this ->title ;
220+ return $ this ->description ;
198221 }
199222
200223 /**
@@ -246,42 +269,34 @@ public function getProperties(): Collection
246269 }
247270
248271 /**
249- * @return array
272+ * @return ?RichText
250273 */
251- public function getRawTitle (): array
274+ public function getRichTitle (): ? RichText
252275 {
253- return $ this ->rawTitle ;
276+ return $ this ->richTitle ;
254277 }
255278
256279 /**
257- * @return array
280+ * @return ?RichText
258281 */
259- public function getRawProperties (): array
282+ public function getRichDescription (): ? RichText
260283 {
261- return $ this ->rawProperties ;
284+ return $ this ->richDescription ;
262285 }
263286
264287 /**
265288 * @return array
266289 */
267- public function getPropertyKeys (): array
268- {
269- return $ this ->propertyKeys ;
270- }
271-
272- /**
273- * @return DateTime
274- */
275- public function getCreatedTime (): DateTime
290+ public function getRawProperties (): array
276291 {
277- return $ this ->createdTime ;
292+ return $ this ->rawProperties ;
278293 }
279294
280295 /**
281296 * @return array
282297 */
283- public function getLastEditedTime (): DateTime
298+ public function getPropertyKeys (): array
284299 {
285- return $ this ->lastEditedTime ;
300+ return $ this ->propertyKeys ;
286301 }
287302}
0 commit comments