| @@ -1,21 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentForm\App\Modules\Entries; |
| 4 | 4 | |
| 5 | -use FluentForm\App; | |
| 5 | +use FluentForm\App\Helpers\Helper; | |
| 6 | 6 | |
| 7 | +/** | |
| 8 | + * @deprecated Use SubmissionService or direct wpFluent() queries instead. | |
| 9 | + * @todo Remove in next major version. | |
| 10 | + */ | |
| 7 | 11 | class EntryQuery |
| 8 | 12 | { |
| 9 | - /** | |
| 10 | - * @var \FluentForm\Framework\Request\Request $request | |
| 11 | - */ | |
| 12 | 13 | protected $request; |
| 13 | 14 | protected $formModel; |
| 14 | 15 | protected $responseModel; |
| 15 | 16 | |
| 16 | 17 | protected $formId = false; |
| 17 | - | |
| 18 | 18 | protected $per_page = 10; |
| 19 | 19 | protected $page_number = 1; |
| 20 | 20 | protected $status = false; |
| 21 | 21 | protected $is_favourite = null; |
| @@ -20,16 +20,16 @@ | ||
| 20 | 20 | protected $status = false; |
| 21 | 21 | protected $is_favourite = null; |
| 22 | 22 | protected $sort_by = 'ASC'; |
| 23 | 23 | protected $search = false; |
| 24 | - protected $wheres = array(); | |
| 25 | - | |
| 24 | + protected $wheres = []; | |
| 26 | 25 | protected $startDate; |
| 27 | 26 | protected $endDate; |
| 28 | 27 | |
| 29 | 28 | public function __construct() |
| 30 | 29 | { |
| 31 | - $this->request = App::make('request'); | |
| 30 | + _deprecated_function(__CLASS__, '6.2.0', 'FluentForm\App\Models\Submission model or wpFluent() queries'); | |
| 31 | + $this->request = wpFluentForm('request'); | |
| 32 | 32 | $this->formModel = wpFluent()->table('fluentform_forms'); |
| 33 | 33 | $this->responseModel = wpFluent()->table('fluentform_submissions'); |
| 34 | 34 | } |
| 35 | 35 | |
| @@ -36,9 +36,9 @@ | ||
| 36 | 36 | public function getResponses() |
| 37 | 37 | { |
| 38 | 38 | $query = $this->responseModel |
| 39 | 39 | ->where('form_id', $this->formId) |
| 40 | - ->orderBy('id', $this->sort_by); | |
| 40 | + ->orderBy('id', Helper::sanitizeOrderValue($this->sort_by)); | |
| 41 | 41 | |
| 42 | 42 | if ($this->per_page > 0) { |
| 43 | 43 | $query = $query->limit($this->per_page); |
| 44 | 44 | } |
| @@ -58,10 +58,9 @@ | ||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | if ($this->startDate && $this->endDate) { |
| 62 | - $endDate = $this->endDate; | |
| 63 | - $endDate .= ' 23:59:59'; | |
| 62 | + $endDate = $this->endDate . ' 23:59:59'; | |
| 64 | 63 | $query->where('created_at', '>=', $this->startDate); |
| 65 | 64 | $query->where('created_at', '<=', $endDate); |
| 66 | 65 | } |
| 67 | 66 | |
| @@ -86,9 +85,9 @@ | ||
| 86 | 85 | $column = $where[0]; |
| 87 | 86 | $operator = '='; |
| 88 | 87 | $value = $where[1]; |
| 89 | 88 | } |
| 90 | - if(is_array($value)) { | |
| 89 | + if (is_array($value)) { | |
| 91 | 90 | $query->whereIn($column, $value); |
| 92 | 91 | } else { |
| 93 | 92 | $query->where($column, $operator, $value); |
| 94 | 93 | } |
| @@ -97,10 +96,11 @@ | ||
| 97 | 96 | } |
| 98 | 97 | |
| 99 | 98 | $total = $query->count(); |
| 100 | 99 | $responses = $query->get(); |
| 101 | - $responses = apply_filters('fluentform_get_raw_responses', $responses, $this->formId); | |
| 102 | 100 | |
| 101 | + $responses = apply_filters('fluentform/get_raw_responses', $responses, $this->formId); | |
| 102 | + | |
| 103 | 103 | return [ |
| 104 | 104 | 'data' => $responses, |
| 105 | 105 | 'paginate' => [ |
| 106 | 106 | 'total' => $total, |
| @@ -105,91 +105,9 @@ | ||
| 105 | 105 | 'paginate' => [ |
| 106 | 106 | 'total' => $total, |
| 107 | 107 | 'per_page' => $this->per_page, |
| 108 | 108 | 'current_page' => $this->page_number, |
| 109 | - 'last_page' => ceil($total / $this->per_page) | |
| 110 | - ] | |
| 109 | + 'last_page' => ceil($total / $this->per_page), | |
| 110 | + ], | |
| 111 | 111 | ]; |
| 112 | - } | |
| 113 | - | |
| 114 | - public function getResponse($entryId) | |
| 115 | - { | |
| 116 | - return wpFluent()->table('fluentform_submissions')->find($entryId); | |
| 117 | - } | |
| 118 | - | |
| 119 | - public function getNextResponse($entryId) | |
| 120 | - { | |
| 121 | - $query = $this->getNextPrevEntryQuery(); | |
| 122 | - | |
| 123 | - $operator = $this->sort_by == 'ASC' ? '>' : '<'; | |
| 124 | - | |
| 125 | - return $query->select('id') | |
| 126 | - ->where('id', $operator, $entryId) | |
| 127 | - ->orderBy('id', $this->sort_by) | |
| 128 | - ->first(); | |
| 129 | - } | |
| 130 | - | |
| 131 | - public function getPrevResponse($entryId) | |
| 132 | - { | |
| 133 | - $query = $this->getNextPrevEntryQuery(); | |
| 134 | - | |
| 135 | - $operator = $this->sort_by == 'ASC' ? '<' : '>'; | |
| 136 | - | |
| 137 | - $orderBy = $this->sort_by == 'ASC' ? 'DESC' : 'ASC'; | |
| 138 | - | |
| 139 | - return $query->select('id') | |
| 140 | - ->where('id', $operator, $entryId) | |
| 141 | - ->orderBy('id', $orderBy) | |
| 142 | - ->first(); | |
| 143 | - } | |
| 144 | - | |
| 145 | - protected function getNextPrevEntryQuery() | |
| 146 | - { | |
| 147 | - $query = wpFluent()->table('fluentform_submissions')->limit(1); | |
| 148 | - | |
| 149 | - if ($this->is_favourite) { | |
| 150 | - $query->where('is_favourite', $this->is_favourite)->where('status', '!=', 'trashed'); | |
| 151 | - } else { | |
| 152 | - if (!$this->status) { | |
| 153 | - $query->where('status', '!=', 'trashed'); | |
| 154 | - } else { | |
| 155 | - $query->where('status', $this->status); | |
| 156 | - } | |
| 157 | - } | |
| 158 | - | |
| 159 | - if ($this->search) { | |
| 160 | - $query->where('response', 'LIKE', "%{$this->search}%"); | |
| 161 | - } | |
| 162 | - | |
| 163 | - return $query->where('form_id', $this->formId); | |
| 164 | - } | |
| 165 | - | |
| 166 | - public function groupCount($form_id) | |
| 167 | - { | |
| 168 | - $statuses = $this->responseModel | |
| 169 | - ->select($this->responseModel->raw('status, COUNT(*) as count')) | |
| 170 | - ->where('form_id', $form_id) | |
| 171 | - ->groupBy('status') | |
| 172 | - ->get(); | |
| 173 | - | |
| 174 | - $counts = []; | |
| 175 | - foreach ($statuses as $status) { | |
| 176 | - $counts[$status->status] = $status->count; | |
| 177 | - } | |
| 178 | - | |
| 179 | - $counts['all'] = array_sum($counts); | |
| 180 | - if (isset($counts['trashed'])) { | |
| 181 | - $counts['all'] -= $counts['trashed']; | |
| 182 | - } | |
| 183 | - | |
| 184 | - $favorites = wpFluent() | |
| 185 | - ->table('fluentform_submissions') | |
| 186 | - ->where('form_id', $form_id) | |
| 187 | - ->where('is_favourite', 1) | |
| 188 | - ->where('status', '!=', 'trashed') | |
| 189 | - ->count(); | |
| 190 | - | |
| 191 | - $counts['favourites'] = $favorites; | |
| 192 | - | |
| 193 | - return $counts; | |
| 194 | 112 | } |
| 195 | 113 | } |