@@ -49,6 +49,22 @@ public function getAdminFormOptions(FeedSource $feedSource): array
4949 'label ' => 'Sportcenter ID ' ,
5050 'formGroupClasses ' => 'mb-3 ' ,
5151 ],
52+ [
53+ 'key ' => 'brnd-area ' ,
54+ 'input ' => 'input ' ,
55+ 'type ' => 'text ' ,
56+ 'name ' => 'area ' ,
57+ 'label ' => 'Område ' ,
58+ 'formGroupClasses ' => 'mb-3 ' ,
59+ ],
60+ [
61+ 'key ' => 'brnd-facility ' ,
62+ 'input ' => 'input ' ,
63+ 'type ' => 'text ' ,
64+ 'name ' => 'facility ' ,
65+ 'label ' => 'Facilitet ' ,
66+ 'formGroupClasses ' => 'mb-3 ' ,
67+ ],
5268 ];
5369 }
5470
@@ -71,28 +87,68 @@ public function getData(Feed $feed): array
7187
7288 $ baseUri = $ secrets ->apiBaseUri ;
7389 $ sportCenterId = $ configuration ['sport_center_id ' ] ?? null ;
90+ $ areaFilter = $ configuration ['area ' ] ?? '' ;
91+ $ facilityFilter = $ configuration ['facility ' ] ?? '' ;
7492
75- if ('' === $ baseUri || null === $ sportCenterId || '' === $ sportCenterId ) {
93+ if ('' === $ baseUri || ! is_string ( $ sportCenterId) || '' === trim ( $ sportCenterId) ) {
7694 return $ result ;
7795 }
7896
97+ $ areaFilterNormalized = self ::normalizeFilterValue ($ areaFilter );
98+ $ facilityFilterNormalized = self ::normalizeFilterValue ($ facilityFilter );
99+
79100 $ bookings = $ this ->apiClient ->getInfomonitorBookingsDetails ($ feedSource , $ sportCenterId );
80101
81- return array_reduce ($ bookings , function (array $ carry , array $ booking ): array {
102+ $ result ['bookings ' ] = array_reduce ($ bookings , function (array $ carry , mixed $ booking ) use ($ areaFilterNormalized , $ facilityFilterNormalized ): array {
103+ if (!is_array ($ booking )) {
104+ return $ carry ;
105+ }
106+
82107 $ parsedBooking = $ this ->parseBrndBooking ($ booking );
83108
84- // Validate that booking has required fields
85- if (! empty ($ parsedBooking ['bookingcode ' ]) && ! empty ($ parsedBooking ['bookingBy ' ])) {
86- $ carry [] = $ parsedBooking ;
109+ // Bail out if required fields are missing.
110+ if (empty ($ parsedBooking ['bookingcode ' ]) || empty ($ parsedBooking ['bookingBy ' ])) {
111+ return $ carry ;
87112 }
88113
114+ // Bail out if area filter applies and booking area does not match.
115+ if ('' !== $ areaFilterNormalized ) {
116+ $ bookingArea = self ::normalizeFilterValue ($ parsedBooking ['area ' ] ?? '' );
117+ if ($ bookingArea !== $ areaFilterNormalized ) {
118+ return $ carry ;
119+ }
120+ }
121+
122+ // Bail out if facility filter applies and booking facility does not match.
123+ if ('' !== $ facilityFilterNormalized ) {
124+ $ bookingFacility = self ::normalizeFilterValue ($ parsedBooking ['facility ' ] ?? '' );
125+ if ($ bookingFacility !== $ facilityFilterNormalized ) {
126+ return $ carry ;
127+ }
128+ }
129+
130+ $ carry [] = $ parsedBooking ;
131+
89132 return $ carry ;
90133 }, []);
91134 } catch (\Throwable $ throwable ) {
92135 $ this ->logger ->error ($ throwable ->getMessage ());
93136
94137 throw $ throwable ;
95138 }
139+
140+ return $ result ;
141+ }
142+
143+ private static function normalizeFilterValue (mixed $ value ): string
144+ {
145+ if (!is_string ($ value )) {
146+ return '' ;
147+ }
148+
149+ $ value = trim ($ value );
150+
151+ return strtolower ($ value );
96152 }
97153
98154 private function parseBrndBooking (array $ booking ): array
0 commit comments