← All changes
|
backend/src/Controllers/Entry/SearchEntriesController.php
+28
-11
0.3.1
→
1.5.1
View file →
| @@ -1,18 +1,13 @@ | ||
| 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\ValidationException; |
| 18 | 13 | use IvyForms\Common\Sanitizer\Sanitizer; |
| @@ -18,8 +13,11 @@ | ||
| 18 | 13 | use IvyForms\Common\Sanitizer\Sanitizer; |
| 19 | 14 | use IvyForms\Controllers\Controller; |
| 20 | 15 | use IvyForms\Factory\Entry\EntryFactory; |
| 21 | 16 | use IvyForms\Services\Entry\EntryService; |
| 17 | +use IvyForms\Services\Form\FormService; | |
| 18 | +use IvyForms\Services\Permissions\AdminFormListPermissionService; | |
| 19 | +use IvyForms\Services\Permissions\IvyFormsAccess; | |
| 22 | 20 | use IvyForms\Services\Translations\BackendStrings; |
| 23 | 21 | use WP_REST_Request; |
| 24 | 22 | use WP_REST_Response; |
| 25 | 23 | |
| @@ -26,12 +24,20 @@ | ||
| 26 | 24 | class SearchEntriesController extends Controller |
| 27 | 25 | { |
| 28 | 26 | private EntryService $entryService; |
| 29 | 27 | |
| 28 | + private FormService $formService; | |
| 29 | + | |
| 30 | + private AdminFormListPermissionService $adminFormListPermissionService; | |
| 31 | + | |
| 30 | 32 | public function __construct( |
| 31 | - EntryService $entryService | |
| 33 | + EntryService $entryService, | |
| 34 | + FormService $formService, | |
| 35 | + AdminFormListPermissionService $adminFormListPermissionService | |
| 32 | 36 | ) { |
| 33 | - $this->entryService = $entryService; | |
| 37 | + $this->entryService = $entryService; | |
| 38 | + $this->formService = $formService; | |
| 39 | + $this->adminFormListPermissionService = $adminFormListPermissionService; | |
| 34 | 40 | } |
| 35 | 41 | |
| 36 | 42 | /** |
| 37 | 43 | * @param WP_REST_Request $data |
| @@ -48,10 +54,18 @@ | ||
| 48 | 54 | |
| 49 | 55 | // Sanitize the filtering data |
| 50 | 56 | $params = Sanitizer::sanitizeSearchParams($data->get_query_params()); |
| 51 | 57 | |
| 58 | + if (!IvyFormsAccess::hasImplicitElevatedAccess()) { | |
| 59 | + $allIdsUnique = $this->formService->getAllFormIds(); | |
| 60 | + $visibleIds = $this->adminFormListPermissionService->filterFormIdsVisibleInEntryLists($allIdsUnique); | |
| 61 | + if ($visibleIds !== $allIdsUnique) { | |
| 62 | + $params['visibleFormIds'] = $visibleIds; | |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 52 | 66 | // Call the searchEntries method |
| 53 | - $entriesArr = $this->entryService->searchEntries($params); | |
| 67 | + $entriesArr = $this->entryService->getEntryManager()->searchEntries($params); | |
| 54 | 68 | |
| 55 | 69 | // Map the data to Entry entities |
| 56 | 70 | $entries = array_map(function ($entryData) { |
| 57 | 71 | $entryEntity = EntryFactory::create($entryData); |
| @@ -57,10 +71,12 @@ | ||
| 57 | 71 | $entryEntity = EntryFactory::create($entryData); |
| 58 | 72 | return $entryEntity->toArray(); |
| 59 | 73 | }, $entriesArr['data']); |
| 60 | 74 | |
| 61 | - $filterCount = $this->entryService->getFilterCount($params); | |
| 62 | - $entryFields = $this->entryService->getEntryFields($entriesArr['data']); | |
| 75 | + $filterCount = $this->entryService->getEntryManager()->getFilterCount($params); | |
| 76 | + // Pass `true` to retrieve raw field values for the result table. | |
| 77 | + $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields($entriesArr['data'], true); | |
| 78 | + $formIdToName = $entriesArr['formIdToName'] ?? []; | |
| 63 | 79 | |
| 64 | 80 | // Return the response with data and meta |
| 65 | 81 | return new WP_REST_Response([ |
| 66 | 82 | 'message' => BackendStrings::getCommonStrings()['ok'], |
| @@ -68,8 +84,9 @@ | ||
| 68 | 84 | 'data' => $entries, |
| 69 | 85 | 'meta' => $entriesArr['meta'] ?? [], |
| 70 | 86 | 'filterCount' => $filterCount, |
| 71 | 87 | 'entryFields' => $entryFields, |
| 88 | + 'formIdToName' => $formIdToName, | |
| 72 | 89 | ], |
| 73 | 90 | ], 200); |
| 74 | 91 | } |
| 75 | 92 | } |