PluginProbe
The Innovative Form Builder – IvyForms / 0.1.2
The Innovative Form Builder – IvyForms v0.1.2
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
ivyforms / backend / src / Controllers / Notification / GetNotificationsController.php

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

64 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 namespace IvyForms\Controllers\Notification;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\ForbiddenException;
11 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 use IvyForms\Common\Exceptions\NotFoundException;
13 use IvyForms\Common\Sanitizer\Sanitizer;
14 use IvyForms\Controllers\Controller;
15 use IvyForms\Services\Notification\NotificationService;
16 use WP_REST_Request;
17 use WP_REST_Response;
18
19 /**
20 * Class GetNotificationsController
21 *
22 * @package IvyForms\Controllers\Notification
23 */
24 class GetNotificationsController extends Controller
25 {
26 private NotificationService $notificationService;
27
28 public function __construct(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 * @throws InvalidArgumentException|NotFoundException
39 */
40 public function handle(WP_REST_Request $data): WP_REST_Response
41 {
42 // Verify the nonce
43 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
44 $formId = Sanitizer::sanitizeId($data->get_param('id'));
45
46
47 // TODO: Update this logic to only require the form ID after templates.
48 $notificationsArr = $formId
49 ? $this->notificationService->getNotificationsByFormId((int) $formId)
50 : $this->notificationService->getAllNotifications();
51
52 $notifications = [];
53
54 foreach ($notificationsArr as $notification) {
55 $notifications[] = $notification->toArray();
56 }
57
58 return new WP_REST_Response([
59 'message' => 'OK',
60 'data' => $notifications,
61 ], 200);
62 }
63 }
64