# ivyforms/0.9.1/backend/src/Controllers/Entry/SearchEntriesController.php

The Innovative Form Builder – IvyForms, version 0.9.1. 79 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.9.1/code/backend/src/Controllers/Entry/SearchEntriesController.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.9.1/raw/backend/src/Controllers/Entry/SearchEntriesController.php
- Modified: 2025-12-11T16:49:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.9.1/code/backend/src/Controllers/Entry/SearchEntriesController.php#L10-L20`.

```php
<?php

/**
 * @copyright © Melograno Venture Studio. All rights reserved.
 * @licence   See COPYING.md for license details.
 */

namespace IvyForms\Controllers\Entry;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

use IvyForms\Common\Exceptions\ForbiddenException;
use IvyForms\Common\Exceptions\InvalidArgumentException;
use IvyForms\Common\Exceptions\ValidationException;
use IvyForms\Common\Sanitizer\Sanitizer;
use IvyForms\Controllers\Controller;
use IvyForms\Factory\Entry\EntryFactory;
use IvyForms\Services\Entry\EntryService;
use IvyForms\Services\Translations\BackendStrings;
use WP_REST_Request;
use WP_REST_Response;

class SearchEntriesController extends Controller
{
    private EntryService $entryService;

    public function __construct(
        EntryService $entryService
    ) {
        $this->entryService = $entryService;
    }

    /**
     * @param WP_REST_Request $data
     *
     * @return WP_REST_Response
     * @throws ForbiddenException
     * @throws InvalidArgumentException
     * @throws ValidationException
     */
    public function handle(WP_REST_Request $data): WP_REST_Response
    {
        // Verify the nonce
        Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));

        // Sanitize the filtering data
        $params = Sanitizer::sanitizeSearchParams($data->get_query_params());

        // Call the searchEntries method
        $entriesArr = $this->entryService->getEntryManager()->searchEntries($params);

        // Map the data to Entry entities
        $entries = array_map(function ($entryData) {
            $entryEntity = EntryFactory::create($entryData);
            return $entryEntity->toArray();
        }, $entriesArr['data']);

        $filterCount = $this->entryService->getEntryManager()->getFilterCount($params);
        // Pass `true` to retrieve raw field values for the result table.
        $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields($entriesArr['data'], true);
        $formIdToName = $entriesArr['formIdToName'] ?? [];

        // Return the response with data and meta
        return new WP_REST_Response([
            'message' => BackendStrings::getCommonStrings()['ok'],
            'data' => [
                'data' => $entries,
                'meta' => $entriesArr['meta'] ?? [],
                'filterCount' => $filterCount,
                'entryFields' => $entryFields,
                'formIdToName' => $formIdToName,
            ],
        ], 200);
    }
}

```
