PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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
← All changes | backend/src/Controllers/Form/SearchFormsController.php +30 -9 0.2 → 1.5 View file →
@@ -1,23 +1,21 @@
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\Form;
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\Sanitizer\Sanitizer;
18 13 use IvyForms\Controllers\Controller;
14 +use IvyForms\Services\Entry\EntryService;
19 15 use IvyForms\Services\Form\FormService;
16 +use IvyForms\Services\Permissions\AdminFormListPermissionService;
17 +use IvyForms\Services\Permissions\IvyFormsAccess;
20 18 use IvyForms\Services\Translations\BackendStrings;
21 19 use WP_REST_Request;
22 20 use WP_REST_Response;
23 21
@@ -23,12 +21,21 @@
23 21
24 22 class SearchFormsController extends Controller
25 23 {
26 24 private FormService $formService;
25 +
26 + private EntryService $entryService;
27 +
28 + private AdminFormListPermissionService $adminFormListPermissionService;
29 +
27 30 public function __construct(
28 - FormService $formService
31 + FormService $formService,
32 + EntryService $entryService,
33 + AdminFormListPermissionService $adminFormListPermissionService
29 34 ) {
30 - $this->formService = $formService;
35 + $this->formService = $formService;
36 + $this->entryService = $entryService;
37 + $this->adminFormListPermissionService = $adminFormListPermissionService;
31 38 }
32 39
33 40 /**
34 41 * @param WP_REST_Request $data
@@ -34,8 +41,9 @@
34 41 * @param WP_REST_Request $data
35 42 *
36 43 * @return WP_REST_Response
37 44 * @throws ForbiddenException
45 + * @throws InvalidArgumentException
38 46 */
39 47 public function handle(WP_REST_Request $data): WP_REST_Response
40 48 {
41 49 // Verify the nonce
@@ -43,8 +51,16 @@
43 51
44 52 // Sanitize the filtering data
45 53 $params = Sanitizer::sanitizeSearchParams($data->get_query_params());
46 54
55 + if (!IvyFormsAccess::hasImplicitElevatedAccess()) {
56 + $allIdsUnique = $this->formService->getAllFormIds();
57 + $visibleIds = $this->adminFormListPermissionService->filterFormIdsVisibleInAdminLists($allIdsUnique);
58 + if ($visibleIds !== $allIdsUnique) {
59 + $params['visibleFormIds'] = $visibleIds;
60 + }
61 + }
62 +
47 63 // Call the searchForms method
48 64 $formsArr = $this->formService->searchForms($params);
49 65
50 66 // Map the data to an array format
@@ -51,9 +67,13 @@
51 67 $forms = array_map(fn($form) => (array) $form, $formsArr['data']);
52 68
53 69 $filterCount = $this->formService->getFilterCount($params['shouldGetCount']);
54 70
55 - // Return the response with data and meta
71 + // Collect form IDs for entry count
72 + $formIds = array_column($forms, 'id');
73 + $entryCounts = $this->entryService->getEntryManager()->getEntryCountByFormIds($formIds);
74 +
75 + // Return the response with data, meta, filterCount, and entryCounts
56 76 return new WP_REST_Response([
57 77 'message' => BackendStrings::getCommonStrings()['ok'],
58 78 'data' => [
59 79 'data' => $forms,
@@ -58,8 +78,9 @@
58 78 'data' => [
59 79 'data' => $forms,
60 80 'meta' => $formsArr['meta'],
61 81 'filterCount' => $filterCount,
82 + 'entryCounts' => $entryCounts,
62 83 ],
63 84 ], 200);
64 85 }
65 86 }