PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
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 +35 -11 0.1.2 → 1.5.1 View file →
@@ -1,23 +1,22 @@
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;
18 +use IvyForms\Services\Translations\BackendStrings;
20 19 use WP_REST_Request;
21 20 use WP_REST_Response;
22 21
23 22 class SearchFormsController extends Controller
@@ -22,12 +21,21 @@
22 21
23 22 class SearchFormsController extends Controller
24 23 {
25 24 private FormService $formService;
25 +
26 + private EntryService $entryService;
27 +
28 + private AdminFormListPermissionService $adminFormListPermissionService;
29 +
26 30 public function __construct(
27 - FormService $formService
31 + FormService $formService,
32 + EntryService $entryService,
33 + AdminFormListPermissionService $adminFormListPermissionService
28 34 ) {
29 - $this->formService = $formService;
35 + $this->formService = $formService;
36 + $this->entryService = $entryService;
37 + $this->adminFormListPermissionService = $adminFormListPermissionService;
30 38 }
31 39
32 40 /**
33 41 * @param WP_REST_Request $data
@@ -32,10 +40,10 @@
32 40 /**
33 41 * @param WP_REST_Request $data
34 42 *
35 43 * @return WP_REST_Response
44 + * @throws ForbiddenException
36 45 * @throws InvalidArgumentException
37 - * @throws ForbiddenException
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
@@ -49,14 +65,22 @@
49 65
50 66 // Map the data to an array format
51 67 $forms = array_map(fn($form) => (array) $form, $formsArr['data']);
52 68
53 - // Return the response with data and meta
69 + $filterCount = $this->formService->getFilterCount($params['shouldGetCount']);
70 +
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
54 76 return new WP_REST_Response([
55 - 'message' => 'OK',
77 + 'message' => BackendStrings::getCommonStrings()['ok'],
56 78 'data' => [
57 79 'data' => $forms,
58 80 'meta' => $formsArr['meta'],
81 + 'filterCount' => $filterCount,
82 + 'entryCounts' => $entryCounts,
59 83 ],
60 84 ], 200);
61 85 }
62 86 }