1 | <?php |
||
15 | class Sorter extends DataComponent { |
||
16 | |||
17 | const SORTING_SEPARATOR = '~'; |
||
18 | const COLUMN_SEPARATOR = '.'; |
||
19 | |||
20 | /** @var array */ |
||
21 | private $_sortFields = []; |
||
22 | |||
23 | /** |
||
24 | * Sorter constructor. |
||
25 | * @param null|array $fields |
||
26 | * @param bool $remember |
||
27 | */ |
||
28 | 10 | public function __construct(array $fields = null, bool $remember = false) |
|
47 | |||
48 | /** |
||
49 | * Sort by this column. |
||
50 | * |
||
51 | * @param string $field |
||
52 | * @param string $direction |
||
53 | * |
||
54 | * @return Sorter |
||
55 | */ |
||
56 | 1 | public function addField(string $field, string $direction = 'asc') : Sorter |
|
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 1 | public function render() : string |
|
70 | |||
71 | /** |
||
72 | * @return Builder |
||
73 | */ |
||
74 | 8 | protected function _shapeData() : Builder |
|
92 | |||
93 | /** |
||
94 | * Stop sorting by this column |
||
95 | * |
||
96 | * @param string $field |
||
97 | * |
||
98 | * @return Sorter |
||
99 | */ |
||
100 | 1 | public function removeField(string $field) : Sorter |
|
109 | |||
110 | /** |
||
111 | * @param string $fieldName |
||
112 | * @param string $direction |
||
113 | */ |
||
114 | private function _sortField(string $fieldName, string $direction) : void |
||
128 | |||
129 | /** |
||
130 | * @param Column $column |
||
131 | */ |
||
132 | 4 | private function _addGroupingForAggregate(Column $column) : void |
|
133 | { |
||
134 | 4 | $relation = $column->getRelation(); |
|
135 | 4 | if ($relation === null || $relation->aggregate === 'first') |
|
136 | { |
||
137 | 4 | return; |
|
138 | } |
||
139 | |||
140 | $this->_dataTable->query()->groupBy($relation->name . '.' . $column->getName()); |
||
141 | } |
||
142 | |||
143 | 1 | protected function _readFromSession() : void |
|
147 | |||
148 | 1 | protected function _storeInSession() : void |
|
152 | |||
153 | 9 | protected function _afterInit() : void |
|
164 | |||
165 | /** |
||
166 | * @param string $fields |
||
167 | */ |
||
168 | 2 | private function _initFields(string $fields) : void |
|
187 | } |