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