PluginProbe
The Innovative Form Builder – IvyForms / 0.2
The Innovative Form Builder – IvyForms v0.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 / Form / DeleteFormController.php

DeleteFormController.php in The Innovative Form Builder – IvyForms 0.2, at backend/src/Controllers/Form/DeleteFormController.php

87 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Form;
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\Exceptions\InvalidArgumentException;
17 use IvyForms\Common\Exceptions\NotFoundException;
18 use IvyForms\Common\Sanitizer\Sanitizer;
19 use IvyForms\Controllers\Controller;
20 use IvyForms\Services\Confirmation\ConfirmationService;
21 use IvyForms\Services\Field\FieldService;
22 use IvyForms\Services\Form\FormService;
23 use IvyForms\Services\Notification\NotificationService;
24 use WP_REST_Request;
25 use WP_REST_Response;
26
27 /**
28 * Class DeleteFormController
29 *
30 * @package IvyForms\Application\Controllers\Form
31 */
32 class DeleteFormController extends Controller
33 {
34 private FormService $formService;
35 private FieldService $fieldService;
36 private NotificationService $notificationService;
37 private ConfirmationService $confirmationService;
38
39 public function __construct(
40 FormService $formService,
41 FieldService $fieldService,
42 NotificationService $notificationService,
43 ConfirmationService $confirmationService
44 ) {
45 $this->formService = $formService;
46 $this->fieldService = $fieldService;
47 $this->notificationService = $notificationService;
48 $this->confirmationService = $confirmationService;
49 }
50
51 /**
52 * @param WP_REST_Request $data
53 *
54 * @return WP_REST_Response
55 *
56 * @throws NotFoundException
57 * @throws InvalidArgumentException
58 * @throws ForbiddenException
59 */
60 public function handle(WP_REST_Request $data): WP_REST_Response
61 {
62 // Verify the nonce
63 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
64
65 // Check if the form ID is provided
66 if (empty($data->get_param('id'))) {
67 throw new InvalidArgumentException('Form ID is required.');
68 }
69
70 // Sanitize the input data
71 $formId = Sanitizer::sanitizeId($data->get_param('id'));
72
73 $this->formService->deleteForm($formId);
74
75 $this->fieldService->deleteFieldsByFormId($formId);
76
77 $this->notificationService->deleteNotificationsByFormId($formId);
78
79 $this->confirmationService->deleteConfirmationsByFormId($formId);
80
81 return new WP_REST_Response([
82 'message' => 'Successfully deleted form.',
83 'data' => []
84 ], 200);
85 }
86 }
87