# fluentform/1.2.4/app/Modules/Entries/EntryQuery.php

Fluent Forms – Customizable Contact Forms, Survey, Quiz, &amp; Conversational Form Builder, version 1.2.4. 116 lines.

- Page: https://pluginprobe.com/plugins/fluentform/1.2.4/code/app/Modules/Entries/EntryQuery.php
- Raw: https://pluginprobe.com/plugins/fluentform/1.2.4/raw/app/Modules/Entries/EntryQuery.php
- Modified: 2018-02-03T11:29:32+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/fluentform/1.2.4/code/app/Modules/Entries/EntryQuery.php#L10-L20`.

```php
<?php namespace FluentForm\App\Modules\Entries;
use FluentForm\App;

class EntryQuery {
	/**
	 * @var \FluentForm\Framework\Request\Request $request
	 */
	protected $request;
	protected $formModel;
	protected $responseModel;

	protected $formId = false;

	protected $per_page = 10;
	protected $page_number = 1;
	protected $status = false;
	protected $is_favourite = null;
	protected $sort_by = 'ASC';
	protected $search = false;

	public function __construct() {
		$this->request = App::make( 'request' );
		$this->formModel   = wpFluent()->table( 'fluentform_forms' );
		$this->responseModel   = wpFluent()->table( 'fluentform_submissions' );
	}

	public function getResponses() {
		$query = $this->responseModel
					->where('form_id', $this->formId)
					->limit($this->per_page)
					->orderBy('id', $this->sort_by)
					->offset(( $this->page_number - 1) * $this->per_page );

		if($this->is_favourite) {
			$query->where('is_favourite', $this->is_favourite);
			$query->where('status', '!=', 'trashed');
		} else {
			if(!$this->status) {
				$query->where('status', '!=', 'trashed');
			} else {
				$query->where('status', $this->status);
			}
		}

		if($this->search) {
			$query->where('response', 'LIKE', '%'.$this->search.'%');
		}

		$total = $query->count();
		$responses = $query->get();
		$responses = apply_filters('fluentform_get_raw_responses', $responses, $this->formId);

		return [
			'data' => $responses,
			'paginate' => [
				'total' => $total,
				'per_page' => $this->per_page,
				'current_page' => $this->page_number,
				'last_page' => ceil($total / $this->per_page)
			]
		];
	}

	public function getResponse($entryId, $operator = null, $currentSerialNo = null) {
        $queryString = 'SELECT @rownum:=@rownum + 1 AS myRowSerial, wp_fluentform_submissions.* '.
                       'FROM wp_fluentform_submissions, (SELECT @rownum:=0) AS nothingButSetInitialValue '.
                       'WHERE form_id='.$this->formId;

        if ($this->is_favourite) {
            $queryString .= ' AND is_favourite='.$this->is_favourite.' AND status!="trashed"';
        } else {
            if (! $this->status) {
                $queryString .= ' AND status != "trashed"';
            } else {
                $queryString .= ' AND status='.$this->status;
            }
        }

        if ($this->search) {
            $queryString .= ' AND response LIKE %'.$this->search.'%';
        }

        $queryString .= ' ORDER BY id '.$this->sort_by;

        $queryString = 'SELECT * FROM ('.$queryString.') filtered ';

        if ($operator) {
            $queryString .= 'WHERE filtered.myRowSerial = '.$currentSerialNo.$operator.'1';
        } else {
            $queryString .= 'WHERE filtered.id='.$entryId;
        }

		return wpFluent()->query($queryString)->first();
	}

	public function groupCount($form_id) {
		$statuses = $this->responseModel
			->select($this->responseModel->raw('status, COUNT(*) as count'))
			->where('form_id', $form_id)
			->groupBy('status')
			->get();
		$counts = array();
		foreach ($statuses as $status) {
			$counts[$status->status] = $status->count;
		}

		$counts['all'] = array_sum($counts);
		$favorites = wpFluent()
				->table('fluentform_submissions')
				->where('form_id', $form_id)
				->where('is_favourite', 1)
				->count();
		$counts['favourites'] = $favorites;
		return $counts;
	}
}
```
