← All changes
|
backend/src/Controllers/Entry/GetEntryController.php
+11
-15
0.4
→
1.5.1
View file →
| @@ -1,23 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See COPYING.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Controllers\Entry; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | 10 | use IvyForms\Common\Exceptions\ForbiddenException; |
| 16 | 11 | use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 17 | 12 | use IvyForms\Common\Exceptions\NotFoundException; |
| 18 | 13 | use IvyForms\Common\Sanitizer\Sanitizer; |
| 19 | 14 | use IvyForms\Controllers\Controller; |
| 15 | +use IvyForms\Services\Amelia\AmeliaService; | |
| 20 | 16 | use IvyForms\Services\Entry\EntryService; |
| 21 | 17 | use IvyForms\Services\Translations\BackendStrings; |
| 22 | 18 | use WP_REST_Request; |
| 23 | 19 | use WP_REST_Response; |
| @@ -29,12 +25,14 @@ | ||
| 29 | 25 | */ |
| 30 | 26 | class GetEntryController extends Controller |
| 31 | 27 | { |
| 32 | 28 | private EntryService $entryService; |
| 29 | + private AmeliaService $ameliaService; | |
| 33 | 30 | |
| 34 | - public function __construct(EntryService $entryService) | |
| 31 | + public function __construct(EntryService $entryService, AmeliaService $ameliaService) | |
| 35 | 32 | { |
| 36 | 33 | $this->entryService = $entryService; |
| 34 | + $this->ameliaService = $ameliaService; | |
| 37 | 35 | } |
| 38 | 36 | |
| 39 | 37 | /** |
| 40 | 38 | * @param WP_REST_Request $data |
| @@ -57,18 +55,16 @@ | ||
| 57 | 55 | } |
| 58 | 56 | |
| 59 | 57 | $entryId = Sanitizer::sanitizeId($data->get_param('id')); |
| 60 | 58 | |
| 61 | - $entry = $this->entryService->getEntry($entryId); | |
| 59 | + $entry = $this->entryService->getEntryManager()->getEntry($entryId); | |
| 60 | + $entryArray = $entry->toArray(); | |
| 61 | + $entryArray['ameliaBookingUrls'] = $this->ameliaService->getBookingUrlsByEntryId($entryId); | |
| 62 | 62 | |
| 63 | - $fields = $this->entryService->getFieldsByEntryId($entryId); | |
| 64 | - $fieldsMap = []; | |
| 65 | - foreach ($fields as $field) { | |
| 66 | - $fieldsMap[] = $field->toArray(); | |
| 67 | - } | |
| 63 | + $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields([$entryArray]); | |
| 68 | 64 | |
| 69 | 65 | return new WP_REST_Response([ |
| 70 | - 'entry' => $entry->toArray(), | |
| 71 | - 'fields' => $fieldsMap, | |
| 66 | + 'entry' => $entryArray, | |
| 67 | + 'fields' => $entryFields, | |
| 72 | 68 | ], 200); |
| 73 | 69 | } |
| 74 | 70 | } |