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 / Entry / GetEntryController.php

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

67 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 reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Entry;
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\Entry\EntryService;
16 use IvyForms\Services\Translations\BackendStrings;
17 use WP_REST_Request;
18 use WP_REST_Response;
19
20 /**
21 * Class GetEntryController
22 *
23 * @package IvyForms\Controllers\Entry
24 */
25 class GetEntryController extends Controller
26 {
27 private EntryService $entryService;
28
29 public function __construct(EntryService $entryService)
30 {
31 $this->entryService = $entryService;
32 }
33
34 /**
35 * @param WP_REST_Request $data
36 *
37 * @return WP_REST_Response
38 *
39 * @throws NotFoundException
40 * @throws InvalidArgumentException|ForbiddenException
41 */
42 public function handle(WP_REST_Request $data): WP_REST_Response
43 {
44 // Verify the nonce
45 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
46
47 // Check if the entry ID is provided
48 if (empty($data->get_params())) {
49 throw new InvalidArgumentException(
50 BackendStrings::getExceptionStrings()['entry_id_required']
51 );
52 }
53
54 $entryId = Sanitizer::sanitizeId($data->get_param('id'));
55
56 $entry = $this->entryService->getEntryManager()->getEntry($entryId);
57 $entryArray = $entry->toArray();
58
59 $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields([$entryArray]);
60
61 return new WP_REST_Response([
62 'entry' => $entryArray,
63 'fields' => $entryFields,
64 ], 200);
65 }
66 }
67