← All changes
|
backend/src/Controllers/Entry/SearchEntriesController.php
+24
-9
0.5
→
1.5
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,8 +54,16 @@ | ||
| 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 | 67 | $entriesArr = $this->entryService->getEntryManager()->searchEntries($params); |
| 54 | 68 | |
| 55 | 69 | // Map the data to Entry entities |
| @@ -58,9 +72,10 @@ | ||
| 58 | 72 | return $entryEntity->toArray(); |
| 59 | 73 | }, $entriesArr['data']); |
| 60 | 74 | |
| 61 | 75 | $filterCount = $this->entryService->getEntryManager()->getFilterCount($params); |
| 62 | - $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields($entriesArr['data']); | |
| 76 | + // Pass `true` to retrieve raw field values for the result table. | |
| 77 | + $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields($entriesArr['data'], true); | |
| 63 | 78 | $formIdToName = $entriesArr['formIdToName'] ?? []; |
| 64 | 79 | |
| 65 | 80 | // Return the response with data and meta |
| 66 | 81 | return new WP_REST_Response([ |