PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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 / DeleteNotificationsController.php

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

55 lines 1.5 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 use IvyForms\Common\Exceptions\ForbiddenException;
6 use IvyForms\Common\Exceptions\InvalidArgumentException;
7 use IvyForms\Controllers\Controller;
8 use IvyForms\Common\Sanitizer\Sanitizer;
9 use IvyForms\Services\Notification\NotificationService;
10 use IvyForms\Services\Translations\BackendStrings;
11 use WP_REST_Request;
12 use WP_REST_Response;
13
14 /**
15 * Class DeleteNotificationsController
16 *
17 * @package IvyForms\Controllers\Notification
18 */
19 class DeleteNotificationsController extends Controller
20 {
21 private NotificationService $notificationService;
22
23 public function __construct(NotificationService $notificationService)
24 {
25 $this->notificationService = $notificationService;
26 }
27
28 /**
29 * @param WP_REST_Request $data
30 *
31 * @return WP_REST_Response
32 *
33 * @throws InvalidArgumentException
34 * @throws ForbiddenException
35 */
36 public function handle(WP_REST_Request $data): WP_REST_Response
37 {
38 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
39 $notificationIds = Sanitizer::sanitizeIds($data->get_param('ids'));
40
41 if (empty($notificationIds)) {
42 throw new InvalidArgumentException(
43 BackendStrings::getExceptionStrings()['notification_ids_required']
44 );
45 }
46
47 $this->notificationService->deleteNotifications($notificationIds);
48
49 return new WP_REST_Response([
50 'message' => BackendStrings::getCommonStrings()['ok'],
51 'data' => []
52 ], 200);
53 }
54 }
55