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 / Confirmation / GetConfirmationsController.php

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

69 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.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Confirmation;
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\Translations\BackendStrings;
22 use WP_REST_Request;
23 use WP_REST_Response;
24
25 /**
26 * Class GetConfirmationsController
27 *
28 * @package IvyForms\Controllers\Confirmation
29 */
30 class GetConfirmationsController extends Controller
31 {
32 private ConfirmationService $confirmationService;
33
34 public function __construct(
35 ConfirmationService $confirmationService
36 ) {
37 $this->confirmationService = $confirmationService;
38 }
39
40 /**
41 * @param WP_REST_Request $data
42 *
43 * @return WP_REST_Response
44 *
45 * @throws InvalidArgumentException
46 * @throws NotFoundException
47 * @throws ForbiddenException
48 */
49 public function handle(WP_REST_Request $data): WP_REST_Response
50 {
51 // Verify the nonce
52 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
53 $formId = Sanitizer::sanitizeId($data->get_param('id'));
54
55 $confirmationsArr = $this->confirmationService->getConfirmationsById($formId);
56
57 $confirmations = [];
58
59 foreach ($confirmationsArr as $confirmation) {
60 $confirmations[] = $confirmation->toArray();
61 }
62
63 return new WP_REST_Response([
64 'message' => BackendStrings::getCommonStrings()['ok'],
65 $confirmations
66 ], 200);
67 }
68 }
69