2
2
3
3
namespace FiveamCode \LaravelNotionApi \Entities ;
4
4
5
- use DateTime ;
6
5
use FiveamCode \LaravelNotionApi \Entities \Properties \Property ;
6
+ use FiveamCode \LaravelNotionApi \Entities \PropertyItems \RichText ;
7
7
use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
8
+ use FiveamCode \LaravelNotionApi \Traits \HasArchive ;
9
+ use FiveamCode \LaravelNotionApi \Traits \HasParent ;
10
+ use FiveamCode \LaravelNotionApi \Traits \HasTimestamps ;
8
11
use Illuminate \Support \Arr ;
9
12
use Illuminate \Support \Collection ;
10
13
13
16
*/
14
17
class Database extends Entity
15
18
{
19
+ use HasTimestamps, HasArchive, HasParent;
20
+
16
21
/**
17
22
* @var string
18
23
*/
19
24
protected string $ title = '' ;
20
25
26
+ /**
27
+ * @var string
28
+ */
29
+ protected string $ description = '' ;
30
+
21
31
/**
22
32
* @var string
23
33
*/
@@ -44,14 +54,19 @@ class Database extends Entity
44
54
private string $ url ;
45
55
46
56
/**
47
- * @var string
57
+ * @var ?RichText
48
58
*/
49
- protected string $ objectType = '' ;
59
+ protected ? RichText $ richTitle = null ;
50
60
51
61
/**
52
- * @var array
62
+ * @var ?RichText
53
63
*/
54
- protected array $ rawTitle = [];
64
+ protected ?RichText $ richDescription = null ;
65
+
66
+ /**
67
+ * @var bool
68
+ */
69
+ protected bool $ isInline = false ;
55
70
56
71
/**
57
72
* @var array
@@ -73,16 +88,6 @@ class Database extends Entity
73
88
*/
74
89
protected Collection $ properties ;
75
90
76
- /**
77
- * @var DateTime
78
- */
79
- protected DateTime $ createdTime ;
80
-
81
- /**
82
- * @var DateTime
83
- */
84
- protected DateTime $ lastEditedTime ;
85
-
86
91
protected function setResponseData (array $ responseData ): void
87
92
{
88
93
parent ::setResponseData ($ responseData );
@@ -94,22 +99,39 @@ protected function setResponseData(array $responseData): void
94
99
95
100
private function fillFromRaw ()
96
101
{
97
- $ this -> fillId ();
102
+ parent :: fillEntityBase ();
98
103
$ this ->fillIcon ();
99
104
$ this ->fillCover ();
100
105
$ this ->fillTitle ();
101
- $ this ->fillObjectType ();
106
+ $ this ->fillIsInline ();
107
+ $ this ->fillDescription ();
102
108
$ this ->fillProperties ();
103
109
$ this ->fillDatabaseUrl ();
104
- $ this ->fillCreatedTime ();
105
- $ this ->fillLastEditedTime ();
110
+ $ this ->fillParentAttributes ();
111
+ $ this ->fillArchivedAttributes ();
112
+ $ this ->fillTimestampableAttributes ();
106
113
}
107
114
108
115
private function fillTitle (): void
109
116
{
110
117
if (Arr::exists ($ this ->responseData , 'title ' ) && is_array ($ this ->responseData ['title ' ])) {
111
118
$ 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 ' ]);
113
135
}
114
136
}
115
137
@@ -146,13 +168,6 @@ private function fillCover(): void
146
168
}
147
169
}
148
170
149
- private function fillObjectType (): void
150
- {
151
- if (Arr::exists ($ this ->responseData , 'object ' )) {
152
- $ this ->objectType = $ this ->responseData ['object ' ];
153
- }
154
- }
155
-
156
171
private function fillProperties (): void
157
172
{
158
173
if (Arr::exists ($ this ->responseData , 'properties ' )) {
@@ -184,17 +199,25 @@ public function getProperty(string $propertyKey): ?Property
184
199
/**
185
200
* @return string
186
201
*/
187
- public function getObjectType (): string
202
+ public function getTitle (): string
188
203
{
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 ;
190
213
}
191
214
192
215
/**
193
216
* @return string
194
217
*/
195
- public function getTitle (): string
218
+ public function getDescription (): string
196
219
{
197
- return $ this ->title ;
220
+ return $ this ->description ;
198
221
}
199
222
200
223
/**
@@ -246,42 +269,34 @@ public function getProperties(): Collection
246
269
}
247
270
248
271
/**
249
- * @return array
272
+ * @return ?RichText
250
273
*/
251
- public function getRawTitle (): array
274
+ public function getRichTitle (): ? RichText
252
275
{
253
- return $ this ->rawTitle ;
276
+ return $ this ->richTitle ;
254
277
}
255
278
256
279
/**
257
- * @return array
280
+ * @return ?RichText
258
281
*/
259
- public function getRawProperties (): array
282
+ public function getRichDescription (): ? RichText
260
283
{
261
- return $ this ->rawProperties ;
284
+ return $ this ->richDescription ;
262
285
}
263
286
264
287
/**
265
288
* @return array
266
289
*/
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
276
291
{
277
- return $ this ->createdTime ;
292
+ return $ this ->rawProperties ;
278
293
}
279
294
280
295
/**
281
296
* @return array
282
297
*/
283
- public function getLastEditedTime (): DateTime
298
+ public function getPropertyKeys (): array
284
299
{
285
- return $ this ->lastEditedTime ;
300
+ return $ this ->propertyKeys ;
286
301
}
287
302
}
0 commit comments