1 | <?php |
||
21 | class SortableHeader implements HeaderFormatter { |
||
22 | |||
23 | const SORTING_SEPARATOR = '~'; |
||
24 | const COLUMN_SEPARATOR = '.'; |
||
25 | |||
26 | /** @var array */ |
||
27 | private $_sortableHeaders; |
||
28 | |||
29 | /** @var array */ |
||
30 | private $_dontSort; |
||
31 | |||
32 | /** @var array */ |
||
33 | private $_sortingSymbols = ['asc' => '▲', 'desc' => '▼', 'none' => '⇵']; |
||
34 | |||
35 | /** |
||
36 | * SortableHeader constructor. |
||
37 | * |
||
38 | * @param array $sortableHeaders |
||
39 | * @param array $dontSort |
||
40 | */ |
||
41 | public function __construct(array $sortableHeaders = [], array $dontSort = []) |
||
47 | |||
48 | /** |
||
49 | * @param array $sortingSymbols |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function sortingSymbols(array $sortingSymbols) |
||
58 | |||
59 | /** |
||
60 | * @param array $array |
||
61 | * @param string $key |
||
62 | */ |
||
63 | private function _removeIndex(array $array, string $key) |
||
71 | |||
72 | /** |
||
73 | * Add a field to the sortable fields. |
||
74 | * |
||
75 | * @param string $header |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function makeSortable(string $header) |
||
85 | |||
86 | /** |
||
87 | * Remove the ability to sort by this column/header. |
||
88 | * |
||
89 | * @param string $header |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function dontSort(string $header) |
||
99 | |||
100 | /** |
||
101 | * @param Request $request |
||
102 | * @return array |
||
103 | */ |
||
104 | private function _extractSortFields(Request $request) |
||
127 | |||
128 | /** |
||
129 | * Get the next sorting direction. |
||
130 | * |
||
131 | * @param string $oldDirection |
||
132 | * @return string |
||
133 | */ |
||
134 | private function _getNewDirection(string $oldDirection): string |
||
150 | |||
151 | /** |
||
152 | * @param Request $request |
||
153 | * @param string $column |
||
154 | * @param string $oldDirection |
||
155 | * @return string |
||
156 | * @throws \RuntimeException |
||
157 | */ |
||
158 | private function _buildSortUrl(Request $request, string $column, string $oldDirection = 'asc') |
||
191 | |||
192 | /** |
||
193 | * Adds a link to sort by this header/column. |
||
194 | * Also indicates how the columns are sorted (when sorted). |
||
195 | * |
||
196 | * @param Header $header |
||
197 | * @param Request $request |
||
198 | * @throws \RuntimeException |
||
199 | */ |
||
200 | public function format(Header $header, Request $request) |
||
213 | } |