11<?php
22
3- declare (strict_types=1 );
4-
5- /*
6- * Aanbod Controller for SoftwareCatalog
3+ /**
4+ * Aanbod Controller for SoftwareCatalog.
75 *
86 * Handles HTTP requests for aanbod (offers) operations including retrieving
97 * aanbod objects (gebruik, dienst, module, koppeling) and accepting or denying them.
1311 * @author Conduction b.v. <info@conduction.nl>
1412 * @copyright 2024 Conduction B.V.
1513 * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
16- * @version 1.0.0
14+ * @version GIT: <git_id>
1715 * @link https://github.com/ConductionNL/SoftwareCatalog
1816 */
1917
18+ declare (strict_types=1 );
19+
2020namespace OCA \SoftwareCatalog \Controller ;
2121
2222use OCP \AppFramework \Controller ;
2727use Psr \Log \LoggerInterface ;
2828
2929/**
30- * Controller for handling aanbod (offers) API operations
30+ * Controller for handling aanbod (offers) API operations.
3131 *
3232 * This controller provides REST API endpoints for managing aanbod objects where
3333 * the active organization is involved either as afnemer (consumer) or aanbieder
3838 * @author Conduction b.v. <info@conduction.nl>
3939 * @copyright 2024 Conduction B.V.
4040 * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
41- * @version 1.0.0
41+ * @version GIT: <git_id>
4242 * @link https://github.com/ConductionNL/SoftwareCatalog
4343 */
4444class AanbodController extends Controller
4545{
4646 /**
47- * Constructor for AanbodController
47+ * Constructor for AanbodController.
4848 *
4949 * @param string $appName The name of the app
5050 * @param IRequest $request The HTTP request object
@@ -63,7 +63,7 @@ public function __construct(
6363 }//end __construct()
6464
6565 /**
66- * Get all aanbod objects (modules, diensten, koppelingen, gebruiks)
66+ * Get all aanbod objects (modules, diensten, koppelingen, gebruiks).
6767 *
6868 * API Endpoint: GET /api/aanbod
6969 *
@@ -77,11 +77,11 @@ public function __construct(
7777 * - offset (int): Number of results to skip for pagination
7878 * - page (int): Page number for pagination
7979 *
80+ * @return JSONResponse JSON response with aanbod objects array
81+ *
8082 * @NoAdminRequired
8183 * @NoCSRFRequired
8284 * @PublicPage
83- *
84- * @return JSONResponse JSON response with aanbod objects array
8585 */
8686 public function getAanbod (): JSONResponse
8787 {
@@ -95,21 +95,25 @@ public function getAanbod(): JSONResponse
9595 );
9696
9797 try {
98- // Parse query parameters for filtering options
98+ // Parse query parameters for filtering options.
9999 $ options = $ this ->parseQueryOptions ();
100100
101- // Get aanbod objects from service
101+ // Get aanbod objects from service.
102102 $ result = $ this ->aanbodService ->getAanbod ($ options );
103103
104- // Determine HTTP status code based on whether there's an error
105- $ statusCode = isset ($ result ['error ' ]) ? 500 : 200 ;
104+ // Determine HTTP status code based on whether there's an error.
105+ if (isset ($ result ['error ' ]) === true ) {
106+ $ statusCode = 500 ;
107+ } else {
108+ $ statusCode = 200 ;
109+ }
106110
107111 $ this ->logger ->info (
108112 'API: Aanbod request completed ' ,
109113 [
110114 'total ' => $ result ['total ' ] ?? 0 ,
111115 'results_count ' => count ($ result ['results ' ] ?? []),
112- 'has_error ' => isset ($ result ['error ' ]),
116+ 'has_error ' => isset ($ result ['error ' ]) === true ,
113117 ]
114118 );
115119
@@ -139,20 +143,21 @@ public function getAanbod(): JSONResponse
139143 }//end getAanbod()
140144
141145 /**
142- * Accept an aanbod object (set @self.organisation to current organisation)
146+ * Accept an aanbod object (set @self.organisation to current organisation).
143147 *
144148 * API Endpoint: PUT /api/aanbod/{uuid}/accept
145149 *
146150 * Sets the '@self.organisation' property of an aanbod object to the active
147151 * organization. This operation is only allowed if the active organization
148152 * is the afnemer (for gebruiks) or aanbieder (for modules, diensten, koppelingen).
149153 *
154+ * @param string $uuid The UUID of the aanbod object to accept
155+ *
156+ * @return JSONResponse JSON response with success status and updated object
157+ *
150158 * @NoAdminRequired
151159 * @NoCSRFRequired
152160 * @PublicPage
153- *
154- * @param string $uuid The UUID of the aanbod object to accept
155- * @return JSONResponse JSON response with success status and updated object
156161 */
157162 public function acceptAanbod (string $ uuid ): JSONResponse
158163 {
@@ -166,8 +171,8 @@ public function acceptAanbod(string $uuid): JSONResponse
166171 );
167172
168173 try {
169- // Validate input
170- if (empty ($ uuid )) {
174+ // Validate input.
175+ if (empty ($ uuid ) === true ) {
171176 return new JSONResponse (
172177 [
173178 'success ' => false ,
@@ -178,25 +183,33 @@ public function acceptAanbod(string $uuid): JSONResponse
178183 );
179184 }
180185
181- // Parse any additional options from request body
186+ // Parse any additional options from request body.
182187 $ options = [];
183188 $ requestBody = $ this ->request ->getParams ();
184- if (! empty ($ requestBody )) {
189+ if (empty ($ requestBody ) === false ) {
185190 $ options = array_filter (
186191 $ requestBody ,
187192 function ($ key ) {
188- return ! in_array ( $ key , [ ' uuid ' ]);
189- // Exclude path parameters
193+ // Exclude path parameters.
194+ return in_array (needle: $ key , haystack: [ ' uuid ' ]) === false ;
190195 },
191196 ARRAY_FILTER_USE_KEY
192197 );
193198 }
194199
195- // Accept aanbod object via service
196- $ result = $ this ->aanbodService ->acceptAanbod ($ uuid , $ options );
197-
198- // Determine appropriate HTTP status code
199- $ statusCode = $ result ['success ' ] ? 200 : ($ result ['error ' ] === 'Aanbod object not found ' ? 404 : (strpos ($ result ['error ' ] ?? '' , 'Operation not allowed ' ) !== false ? 403 : 500 ));
200+ // Accept aanbod object via service.
201+ $ result = $ this ->aanbodService ->acceptAanbod (uuid: $ uuid , options: $ options );
202+
203+ // Determine appropriate HTTP status code.
204+ if ($ result ['success ' ] === true ) {
205+ $ statusCode = 200 ;
206+ } else if ($ result ['error ' ] === 'Aanbod object not found ' ) {
207+ $ statusCode = 404 ;
208+ } else if (strpos (haystack: ($ result ['error ' ] ?? '' ), needle: 'Operation not allowed ' ) !== false ) {
209+ $ statusCode = 403 ;
210+ } else {
211+ $ statusCode = 500 ;
212+ }
200213
201214 $ this ->logger ->info (
202215 'API: Accept aanbod request completed ' ,
@@ -230,20 +243,21 @@ function ($key) {
230243 }//end acceptAanbod()
231244
232245 /**
233- * Deny an aanbod object (delete it)
246+ * Deny an aanbod object (delete it).
234247 *
235248 * API Endpoint: DELETE /api/aanbod/{uuid}/deny
236249 *
237250 * Deletes an aanbod object. This operation is only allowed if the active
238251 * organization is the afnemer (for gebruiks) or aanbieder (for modules,
239252 * diensten, koppelingen).
240253 *
254+ * @param string $uuid The UUID of the aanbod object to deny
255+ *
256+ * @return JSONResponse JSON response with success status and deletion details
257+ *
241258 * @NoAdminRequired
242259 * @NoCSRFRequired
243260 * @PublicPage
244- *
245- * @param string $uuid The UUID of the aanbod object to deny
246- * @return JSONResponse JSON response with success status and deletion details
247261 */
248262 public function denyAanbod (string $ uuid ): JSONResponse
249263 {
@@ -257,8 +271,8 @@ public function denyAanbod(string $uuid): JSONResponse
257271 );
258272
259273 try {
260- // Validate input
261- if (empty ($ uuid )) {
274+ // Validate input.
275+ if (empty ($ uuid ) === true ) {
262276 return new JSONResponse (
263277 [
264278 'success ' => false ,
@@ -269,25 +283,33 @@ public function denyAanbod(string $uuid): JSONResponse
269283 );
270284 }
271285
272- // Parse any additional options from request body
286+ // Parse any additional options from request body.
273287 $ options = [];
274288 $ requestBody = $ this ->request ->getParams ();
275- if (! empty ($ requestBody )) {
289+ if (empty ($ requestBody ) === false ) {
276290 $ options = array_filter (
277291 $ requestBody ,
278292 function ($ key ) {
279- return ! in_array ( $ key , [ ' uuid ' ]);
280- // Exclude path parameters
293+ // Exclude path parameters.
294+ return in_array (needle: $ key , haystack: [ ' uuid ' ]) === false ;
281295 },
282296 ARRAY_FILTER_USE_KEY
283297 );
284298 }
285299
286- // Deny aanbod object via service
287- $ result = $ this ->aanbodService ->denyAanbod ($ uuid , $ options );
288-
289- // Determine appropriate HTTP status code
290- $ statusCode = $ result ['success ' ] ? 200 : ($ result ['error ' ] === 'Aanbod object not found ' ? 404 : (strpos ($ result ['error ' ] ?? '' , 'Operation not allowed ' ) !== false ? 403 : 500 ));
300+ // Deny aanbod object via service.
301+ $ result = $ this ->aanbodService ->denyAanbod (uuid: $ uuid , options: $ options );
302+
303+ // Determine appropriate HTTP status code.
304+ if ($ result ['success ' ] === true ) {
305+ $ statusCode = 200 ;
306+ } else if ($ result ['error ' ] === 'Aanbod object not found ' ) {
307+ $ statusCode = 404 ;
308+ } else if (strpos (haystack: ($ result ['error ' ] ?? '' ), needle: 'Operation not allowed ' ) !== false ) {
309+ $ statusCode = 403 ;
310+ } else {
311+ $ statusCode = 500 ;
312+ }
291313
292314 $ this ->logger ->info (
293315 'API: Deny aanbod request completed ' ,
@@ -322,35 +344,35 @@ function ($key) {
322344 }//end denyAanbod()
323345
324346 /**
325- * Parse query parameters into options array
347+ * Parse query parameters into options array.
326348 *
327349 * @return array Parsed options array
328350 */
329351 private function parseQueryOptions (): array
330352 {
331353 $ options = [];
332354
333- // Parse pagination parameters
355+ // Parse pagination parameters.
334356 $ limit = $ this ->request ->getParam ('_limit ' ) ?? $ this ->request ->getParam ('limit ' );
335- if ($ limit !== null && is_numeric ($ limit )) {
357+ if ($ limit !== null && is_numeric ($ limit ) === true ) {
336358 $ options ['_limit ' ] = (int ) $ limit ;
337- $ options [ ' limit ' ] = ( int ) $ limit ;
338- // Keep both for compatibility
359+ // Keep both for compatibility.
360+ $ options [ ' limit ' ] = ( int ) $ limit ;
339361 }
340362
341363 $ offset = $ this ->request ->getParam ('_offset ' ) ?? $ this ->request ->getParam ('offset ' );
342- if ($ offset !== null && is_numeric ($ offset )) {
364+ if ($ offset !== null && is_numeric ($ offset ) === true ) {
343365 $ options ['_offset ' ] = (int ) $ offset ;
344- $ options [ ' offset ' ] = ( int ) $ offset ;
345- // Keep both for compatibility
366+ // Keep both for compatibility.
367+ $ options [ ' offset ' ] = ( int ) $ offset ;
346368 }
347369
348370 $ page = $ this ->request ->getParam ('_page ' ) ?? $ this ->request ->getParam ('page ' );
349- if ($ page !== null && is_numeric ($ page )) {
371+ if ($ page !== null && is_numeric ($ page ) === true ) {
350372 $ options ['_page ' ] = (int ) $ page ;
351373 }
352374
353- // Force database source for real-time data
375+ // Force database source for real-time data.
354376 $ options ['_source ' ] = 'database ' ;
355377
356378 $ this ->logger ->debug (
0 commit comments