66use FiveamCode \LaravelNotionApi \Exceptions \WrapperException ;
77use FiveamCode \LaravelNotionApi \Notion ;
88use Illuminate \Support \Arr ;
9+ use Illuminate \Support \Collection ;
910
1011class Page extends Entity
1112{
13+
1214 protected array $ rawProperties = [];
15+ protected Collection $ propertyCollection ;
1316 protected DateTime $ createdTime ;
1417 protected DateTime $ lastEditedTime ;
1518
@@ -29,18 +32,30 @@ private function fillFromRaw(): void
2932 $ this ->fillLastEditedTime ();
3033 }
3134
32- private function fillProperties () : void
35+ private function fillProperties (): void
3336 {
3437 if (Arr::exists ($ this ->responseData , 'properties ' )) {
3538 $ this ->rawProperties = $ this ->responseData ['properties ' ];
39+ $ this ->propertyCollection = new Collection ();
40+ foreach (array_keys ($ this ->rawProperties ) as $ propertyKey ) {
41+ $ this ->propertyCollection ->add (new Property ($ propertyKey , $ this ->rawProperties [$ propertyKey ]));
42+ }
3643 }
3744 }
3845
39-
40- public function getProperties ()
46+
47+ public function getProperties (): Collection
48+ {
49+ return $ this ->propertyCollection ;
50+ }
51+
52+ public function getProperty (string $ propertyName ): Property
4153 {
42- //TODO: return collection of property-entities (id, type, title)
43- throw new \Exception ("not implemented yet " );
54+ $ property = $ this ->propertyCollection ->filter (function ($ property ) use ($ propertyName ) {
55+ return $ property ->getTitle () == $ propertyName ;
56+ })->first ();
57+
58+ return $ property ;
4459 }
4560
4661 public function getRawProperties (): array
0 commit comments