1 | <?php |
||
29 | class Pager extends AbstractSingleRequestValueFilter implements FilterInterface, ViewDataFactoryInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $countPerPage; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $maxPages; |
||
40 | |||
41 | /** |
||
42 | * @return int |
||
43 | */ |
||
44 | public function getMaxPages() |
||
48 | |||
49 | /** |
||
50 | * @param int $maxPages |
||
51 | */ |
||
52 | public function setMaxPages($maxPages) |
||
56 | |||
57 | /** |
||
58 | * Sets count per page. |
||
59 | * |
||
60 | * @param int $count |
||
61 | */ |
||
62 | public function setCountPerPage($count) |
||
66 | |||
67 | /** |
||
68 | * Returns count per page. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | public function getCountPerPage() |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function getState(Request $request) |
||
81 | { |
||
82 | $state = parent::getState($request); |
||
83 | // Reset pager with any filter. |
||
84 | $state->setUrlParameters([]); |
||
85 | $page = (integer)$state->getValue(); |
||
86 | $state->setValue($page < 1 ? 1 : $page); |
||
87 | |||
88 | return $state; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
||
95 | { |
||
96 | if ($state && $state->isActive()) { |
||
97 | $search->setFrom($this->countPerPage * ($state->getValue() - 1)); |
||
98 | } |
||
99 | |||
100 | $search->setSize($this->countPerPage); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function preProcessSearch(Search $search, Search $relatedSearch, FilterState $state = null) |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function createViewData() |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function getViewData(DocumentIterator $result, ViewData $data) |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function isRelated() |
||
148 | } |
||
149 |