3
3
namespace FiveamCode \LaravelNotionApi \Entities ;
4
4
5
5
use DateTime ;
6
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Checkbox ;
7
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Date ;
8
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Email ;
9
+ use FiveamCode \LaravelNotionApi \Entities \Properties \MultiSelect ;
10
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Number ;
11
+ use FiveamCode \LaravelNotionApi \Entities \Properties \People ;
12
+ use FiveamCode \LaravelNotionApi \Entities \Properties \PhoneNumber ;
6
13
use Illuminate \Support \Arr ;
7
14
use Illuminate \Support \Collection ;
8
15
use FiveamCode \LaravelNotionApi \Entities \Properties \Property ;
16
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Relation ;
17
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Select ;
18
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Text ;
19
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Title ;
20
+ use FiveamCode \LaravelNotionApi \Entities \Properties \Url ;
9
21
use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
10
22
11
23
/**
@@ -55,6 +67,19 @@ class Page extends Entity
55
67
protected DateTime $ lastEditedTime ;
56
68
57
69
70
+ /**
71
+ * Page constructor.
72
+ * @param array|null $responseData
73
+ * @throws HandlingException
74
+ * @throws NotionException
75
+ */
76
+ public function __construct (array $ responseData = null )
77
+ {
78
+ $ this ->properties = new Collection ();
79
+ parent ::__construct ($ responseData );
80
+ }
81
+
82
+
58
83
/**
59
84
* @param array $responseData
60
85
* @throws HandlingException
@@ -72,10 +97,10 @@ protected function setResponseData(array $responseData): void
72
97
*/
73
98
private function fillFromRaw (): void
74
99
{
75
- $ this ->fillId ();
100
+ $ this ->fillId ();
76
101
$ this ->fillObjectType ();
77
102
$ this ->fillProperties ();
78
- $ this ->fillTitle (); //!Warning: call after ' fillProperties' , since title is included within properties
103
+ $ this ->fillTitle (); // This has to be called after fillProperties() , since title is provided by properties
79
104
$ this ->fillCreatedTime ();
80
105
$ this ->fillLastEditedTime ();
81
106
}
@@ -126,6 +151,171 @@ private function fillTitle(): void
126
151
}
127
152
}
128
153
154
+ /**
155
+ * @param $propertyTitle
156
+ * @param $property
157
+ * @return Page
158
+ */
159
+ public function set (string $ propertyKey , Property $ property ): Page
160
+ {
161
+ $ property ->setTitle ($ propertyKey );
162
+ $ this ->properties ->add ($ property );
163
+ $ this ->propertyMap [$ propertyKey ] = $ property ;
164
+
165
+ if ($ property instanceof Title) {
166
+ $ this ->title = $ property ->getPlainText ();
167
+ }
168
+
169
+ return $ this ;
170
+ }
171
+
172
+ /**
173
+ * @param $propertyTitle
174
+ * @param $number
175
+ * @return Page
176
+ */
177
+ public function setNumber (string $ propertyTitle , float $ number ): Page
178
+ {
179
+ $ this ->set ($ propertyTitle , Number::value ($ number ));
180
+
181
+ return $ this ;
182
+ }
183
+
184
+ /**
185
+ * @param $propertyTitle
186
+ * @param $text
187
+ * @return Page
188
+ */
189
+ public function setTitle (string $ propertyTitle , string $ text ): Page
190
+ {
191
+ $ this ->set ($ propertyTitle , Title::value ($ text ));
192
+
193
+ return $ this ;
194
+ }
195
+
196
+ /**
197
+ * @param $propertyTitle
198
+ * @param $text
199
+ * @return Page
200
+ */
201
+ public function setText (string $ propertyTitle , string $ text ): Page
202
+ {
203
+ $ this ->set ($ propertyTitle , Text::value ($ text ));
204
+
205
+ return $ this ;
206
+ }
207
+
208
+ /**
209
+ * @param $propertyTitle
210
+ * @param $name
211
+ * @return Page
212
+ */
213
+ public function setSelect (string $ propertyTitle , string $ name ): Page
214
+ {
215
+ $ this ->set ($ propertyTitle , Select::value ($ name ));
216
+
217
+ return $ this ;
218
+ }
219
+
220
+ /**
221
+ * @param $propertyTitle
222
+ * @param $url
223
+ * @return Page
224
+ */
225
+ public function setUrl (string $ propertyTitle , string $ url ): Page
226
+ {
227
+ $ this ->set ($ propertyTitle , Url::value ($ url ));
228
+
229
+ return $ this ;
230
+ }
231
+
232
+ /**
233
+ * @param $propertyTitle
234
+ * @param $phoneNumber
235
+ * @return Page
236
+ */
237
+ public function setPhoneNumber (string $ propertyTitle , string $ phoneNumber ): Page
238
+ {
239
+ $ this ->set ($ propertyTitle , PhoneNumber::value ($ phoneNumber ));
240
+
241
+ return $ this ;
242
+ }
243
+
244
+ /**
245
+ * @param $propertyTitle
246
+ * @param $email
247
+ * @return Page
248
+ */
249
+ public function setEmail (string $ propertyTitle , string $ email ): Page
250
+ {
251
+ $ this ->set ($ propertyTitle , Email::value ($ email ));
252
+
253
+ return $ this ;
254
+ }
255
+
256
+ /**
257
+ * @param $propertyTitle
258
+ * @param $names
259
+ * @return Page
260
+ */
261
+ public function setMultiSelect (string $ propertyTitle , array $ names ): Page
262
+ {
263
+ $ this ->set ($ propertyTitle , MultiSelect::value ($ names ));
264
+
265
+ return $ this ;
266
+ }
267
+
268
+ /**
269
+ * @param $propertyTitle
270
+ * @param $checked
271
+ * @return Page
272
+ */
273
+ public function setCheckbox (string $ propertyTitle , bool $ checked ): Page
274
+ {
275
+ $ this ->set ($ propertyTitle , Checkbox::value ($ checked ));
276
+
277
+ return $ this ;
278
+ }
279
+
280
+
281
+ /**
282
+ * @param $propertyTitle
283
+ * @param $start
284
+ * @param $end
285
+ * @return Page
286
+ */
287
+ public function setDate (string $ propertyTitle , DateTime $ start , ?DateTime $ end = null ): Page
288
+ {
289
+ $ this ->set ($ propertyTitle , Date::value ($ start , $ end ));
290
+
291
+ return $ this ;
292
+ }
293
+
294
+ /**
295
+ * @param $propertyTitle
296
+ * @param $relationIds
297
+ * @return Page
298
+ */
299
+ public function setRelation (string $ propertyTitle , array $ relationIds ): Page
300
+ {
301
+ $ this ->set ($ propertyTitle , Relation::value ($ relationIds ));
302
+
303
+ return $ this ;
304
+ }
305
+
306
+ /**
307
+ * @param $propertyTitle
308
+ * @param $userIds
309
+ * @return Page
310
+ */
311
+ public function setPeople (string $ propertyTitle , array $ userIds ): Page
312
+ {
313
+ $ this ->set ($ propertyTitle , People::value ($ userIds ));
314
+
315
+ return $ this ;
316
+ }
317
+
318
+
129
319
/**
130
320
* @return string
131
321
*/
@@ -148,7 +338,7 @@ public function getProperties(): Collection
148
338
*/
149
339
public function getProperty (string $ propertyKey ): ?Property
150
340
{
151
- if (!isset ($ this ->propertyMap [$ propertyKey ])){
341
+ if (!isset ($ this ->propertyMap [$ propertyKey ])){
152
342
return null ;
153
343
}
154
344
return $ this ->propertyMap [$ propertyKey ];
0 commit comments