Backend\Modules\FormBuilder\Actions\ExportData::buildQuery PHP Method

buildQuery() private method

Builds the query for this datagrid.
private buildQuery ( ) : array
return array An array with two arguments containing the query and its parameters.
    private function buildQuery()
    {
        // init var
        $parameters = array($this->id);
        /*
         * Start query, as you can see this query is build in the wrong place, because of the filter
         * it is a special case wherein we allow the query to be in the actionfile itself
         */
        $query = 'SELECT i.*, UNIX_TIMESTAMP(i.sent_on) AS sent_on, d.*
             FROM forms_data AS i
             INNER JOIN forms_data_fields AS d ON i.id = d.data_id
             WHERE i.form_id = ?';
        // add start date
        if ($this->filter['start_date'] !== '') {
            // explode date parts
            $chunks = explode('/', $this->filter['start_date']);
            // add condition
            $query .= ' AND i.sent_on >= ?';
            $parameters[] = BackendModel::getUTCDate(null, gmmktime(23, 59, 59, $chunks[1], $chunks[0], $chunks[2]));
        }
        // add end date
        if ($this->filter['end_date'] !== '') {
            // explode date parts
            $chunks = explode('/', $this->filter['end_date']);
            // add condition
            $query .= ' AND i.sent_on <= ?';
            $parameters[] = BackendModel::getUTCDate(null, gmmktime(23, 59, 59, $chunks[1], $chunks[0], $chunks[2]));
        }
        return array($query, $parameters);
    }