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; } }