PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 1.2 1.3
ivyforms / backend / src / Controllers / Notification / SearchNotificationsController.php

SearchNotificationsController.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Controllers/Notification/SearchNotificationsController.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Notification;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ForbiddenException;
16 use IvyForms\Common\Sanitizer\Sanitizer;
17 use IvyForms\Controllers\Controller;
18 use IvyForms\Services\Notification\NotificationService;
19 use WP_REST_Request;
20 use WP_REST_Response;
21 use IvyForms\Services\Translations\BackendStrings;
22
23 class SearchNotificationsController extends Controller
24 {
25 private NotificationService $notificationService;
26
27 public function __construct(
28 NotificationService $notificationService
29 ) {
30 $this->notificationService = $notificationService;
31 }
32
33 /**
34 * @param WP_REST_Request $data
35 *
36 * @return WP_REST_Response
37 * @throws ForbiddenException
38 */
39 public function handle(WP_REST_Request $data): WP_REST_Response
40 {
41 // Verify the nonce
42 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
43
44 // Sanitize the filtering data
45 $params = Sanitizer::sanitizeSearchParams($data->get_query_params());
46
47 // Call the searchNotifications method
48 $notificationsArr = $this->notificationService->searchNotifications($params);
49
50 // Map the data to an array format
51 $notifications = array_map(fn($notification) => (array) $notification, $notificationsArr['data']);
52
53 // Return the response with data and meta
54 return new WP_REST_Response([
55 'message' => BackendStrings::getCommonStrings()['ok'],
56 'data' => [
57 'data' => $notifications,
58 'meta' => $notificationsArr['meta'],
59 ],
60 ], 200);
61 }
62 }
63