1 | <?php |
||
14 | class Configuration |
||
15 | { |
||
16 | /** |
||
17 | * Length of the list of pagination defaults. |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | const DEFAULT_LIST_LENGTH = 5; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | const DEFAULT_PAGE_LINK = '%s'; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $total_pages = 0; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $current_page = 1; |
||
37 | |||
38 | /** |
||
39 | * @var View |
||
40 | */ |
||
41 | protected $view; |
||
42 | |||
43 | /** |
||
44 | * The number of pages displayed in the navigation. |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | protected $max_navigate = self::DEFAULT_LIST_LENGTH; |
||
49 | |||
50 | /** |
||
51 | * @var string|callback |
||
52 | */ |
||
53 | protected $page_link = self::DEFAULT_PAGE_LINK; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $first_page_link = ''; |
||
59 | |||
60 | /** |
||
61 | * @param int $total_pages |
||
62 | * @param int $current_page |
||
63 | */ |
||
64 | 15 | public function __construct($total_pages = 0, $current_page = 1) |
|
65 | { |
||
66 | 15 | $this->setCurrentPage($current_page); |
|
67 | 15 | $this->setTotalPages($total_pages); |
|
68 | 15 | } |
|
69 | |||
70 | /** |
||
71 | * @param int $total_pages |
||
72 | * @param int $current_page |
||
73 | * |
||
74 | * @return Configuration |
||
75 | */ |
||
76 | 2 | public static function create($total_pages = 0, $current_page = 1) |
|
77 | { |
||
78 | 2 | return new static($total_pages, $current_page); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return int |
||
83 | */ |
||
84 | 9 | public function getTotalPages() |
|
85 | { |
||
86 | 9 | return $this->total_pages; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param int $total_pages |
||
91 | * |
||
92 | * @return Configuration |
||
93 | */ |
||
94 | 15 | public function setTotalPages($total_pages) |
|
95 | { |
||
96 | 15 | $this->total_pages = $total_pages; |
|
97 | |||
98 | 15 | return $this; |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * @return int |
||
103 | */ |
||
104 | 9 | public function getCurrentPage() |
|
105 | { |
||
106 | 9 | return $this->current_page; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param int $current_page |
||
111 | * |
||
112 | * @return Configuration |
||
113 | */ |
||
114 | 15 | public function setCurrentPage($current_page) |
|
115 | { |
||
116 | 15 | $this->current_page = $current_page; |
|
117 | |||
118 | 15 | return $this; |
|
119 | } |
||
120 | |||
121 | /** |
||
122 | * @return int |
||
123 | */ |
||
124 | 5 | public function getMaxNavigate() |
|
128 | |||
129 | /** |
||
130 | * @param int $max_navigate |
||
131 | * |
||
132 | * @return Configuration |
||
133 | */ |
||
134 | 5 | public function setMaxNavigate($max_navigate) |
|
140 | |||
141 | /** |
||
142 | * @return string|callback |
||
143 | */ |
||
144 | 2 | public function getPageLink() |
|
145 | { |
||
146 | 2 | return $this->page_link; |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * Set page link. |
||
151 | * |
||
152 | * Basic reference, for example `page_%s.html` where %s page number, or |
||
153 | * callback function which takes one parameter - the number of the page. |
||
154 | * |
||
155 | * <code> |
||
156 | * function ($number) { |
||
157 | * return 'page_'.$number.'.html'; |
||
158 | * } |
||
159 | * </code> |
||
160 | * |
||
161 | * @param string|callback $page_link |
||
162 | * |
||
163 | * @return Configuration |
||
164 | */ |
||
165 | 3 | public function setPageLink($page_link) |
|
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | 1 | public function getFirstPageLink() |
|
176 | { |
||
177 | 1 | return $this->first_page_link; |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param string $first_page_link |
||
182 | * |
||
183 | * @return Configuration |
||
184 | */ |
||
185 | 1 | public function setFirstPageLink($first_page_link) |
|
191 | |||
192 | /** |
||
193 | * @return View |
||
194 | */ |
||
195 | 1 | public function getView() |
|
203 | } |
||
204 |