Conditions | 6 |
Paths | 8 |
Total Lines | 27 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | protected function parserOrderBy() |
||
19 | { |
||
20 | $this->orderBy = $this->request->get(config('repository.criteria.params.orderBy', 'orderBy'), null); |
||
|
|||
21 | $this->sortedBy = $this->request->get(config('repository.criteria.params.sortedBy', 'sortedBy'), 'asc'); |
||
22 | $this->sortedBy = !empty($this->sortedBy) ? $this->sortedBy : 'asc'; |
||
23 | |||
24 | if (isset($this->orderBy) && !empty($this->orderBy)) { |
||
25 | $split = explode('|', $this->orderBy); |
||
26 | if (count($split) > 1) { |
||
27 | $table = $this->model->getModel()->getTable(); |
||
28 | $sortTable = $split[0]; |
||
29 | $sortColumn = $split[1]; |
||
30 | |||
31 | $split = explode(':', $sortTable); |
||
32 | if (count($split) > 1) { |
||
33 | $sortTable = $split[0]; |
||
34 | $keyName = $table.'.'.$split[1]; |
||
35 | } else { |
||
36 | $prefix = Str::singular($sortTable); |
||
37 | $keyName = $table.'.'.$prefix.'_id'; |
||
38 | } |
||
39 | |||
40 | $this->model = $this->model->leftJoin($sortTable, $keyName, '=', $sortTable.'.id') |
||
41 | ->orderBy($sortColumn, $this->sortedBy) |
||
42 | ->addSelect($table.'.*'); |
||
43 | } else { |
||
44 | $this->model = $this->model->orderBy($this->orderBy, $this->sortedBy); |
||
45 | } |
||
48 | } |