PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 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 All 27 releases
← All changes | backend/src/Controllers/Notification/SearchNotificationsController.php +57 -0 0.6.1 → 1.5 View file →
@@ -1,0 +1,57 @@
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 +use IvyForms\Common\Exceptions\ForbiddenException;
11 +use IvyForms\Common\Sanitizer\Sanitizer;
12 +use IvyForms\Controllers\Controller;
13 +use IvyForms\Services\Notification\NotificationService;
14 +use WP_REST_Request;
15 +use WP_REST_Response;
16 +use IvyForms\Services\Translations\BackendStrings;
17 +
18 +class SearchNotificationsController extends Controller
19 +{
20 + private NotificationService $notificationService;
21 +
22 + public function __construct(
23 + NotificationService $notificationService
24 + ) {
25 + $this->notificationService = $notificationService;
26 + }
27 +
28 + /**
29 + * @param WP_REST_Request $data
30 + *
31 + * @return WP_REST_Response
32 + * @throws ForbiddenException
33 + */
34 + public function handle(WP_REST_Request $data): WP_REST_Response
35 + {
36 + // Verify the nonce
37 + Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
38 +
39 + // Sanitize the filtering data
40 + $params = Sanitizer::sanitizeSearchParams($data->get_query_params());
41 +
42 + // Call the searchNotifications method
43 + $notificationsArr = $this->notificationService->searchNotifications($params);
44 +
45 + // Map the data to an array format
46 + $notifications = array_map(fn($notification) => (array) $notification, $notificationsArr['data']);
47 +
48 + // Return the response with data and meta
49 + return new WP_REST_Response([
50 + 'message' => BackendStrings::getCommonStrings()['ok'],
51 + 'data' => [
52 + 'data' => $notifications,
53 + 'meta' => $notificationsArr['meta'],
54 + ],
55 + ], 200);
56 + }
57 +}