1 | <?php |
||
17 | class ElasticaQuerySorter |
||
18 | { |
||
19 | |||
20 | protected $session; |
||
21 | protected $request; |
||
22 | protected $sessionData; |
||
23 | |||
24 | const NO_LIMIT = 99999; |
||
25 | |||
26 | public function __construct(RequestStack $requestStack, Session $session, $configuration) |
||
27 | { |
||
28 | $this->session = $session; |
||
29 | $this->request = $requestStack->getCurrentRequest(); |
||
30 | $this->configuration['item_per_page'] = $configuration; |
||
|
|||
31 | |||
32 | if (isset($this->request) && isset($this->request->query)) { |
||
33 | if ($this->request->query->has('clear_sort')) { |
||
34 | $this->session->remove('elastica_query_sorter'); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | //Initializing the data in session |
||
39 | if (!$this->session->has('elastica_query_sorter')) { |
||
40 | $this->sessionData = []; |
||
41 | } else { |
||
42 | $this->sessionData = $this->session->get('elastica_query_sorter'); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | public function sort(Repository $repository, Query $query, $nbPerPage = null) |
||
67 | |||
68 | protected function getCurrentPage() |
||
78 | |||
79 | protected function getPage() |
||
92 | |||
93 | |||
94 | protected function addSort(Query &$query) |
||
115 | |||
116 | public function fetchData($key) |
||
142 | |||
143 | public function storeSessionData() |
||
147 | |||
148 | /** |
||
149 | * Gets the value of session. |
||
150 | * |
||
151 | * @return mixed |
||
152 | */ |
||
153 | public function getSession() |
||
157 | |||
158 | /** |
||
159 | * Gets the value of request. |
||
160 | * |
||
161 | * @return mixed |
||
162 | */ |
||
163 | public function getRequest() |
||
167 | |||
168 | /** |
||
169 | * Gets the value of sessionData. |
||
170 | * |
||
171 | * @return mixed |
||
172 | */ |
||
173 | public function getSessionData() |
||
177 | |||
178 | public function getItemPerPage() |
||
182 | } |
||
183 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: