10 define(
'CH_WSB_PAGINATE_PER_PAGE_TYPE_FLOAT',
'float');
11 define(
'CH_WSB_PAGINATE_PER_PAGE_TYPE_STATIC',
'static');
12 define(
'CH_WSB_PAGINATE_PER_PAGE_STEP', 5);
13 define(
'CH_WSB_PAGINATE_PER_PAGE_INTERVAL', 3);
14 define(
'CH_WSB_PAGINATE_PER_PAGE_INTERVAL_MIN', 3);
15 define(
'CH_WSB_PAGINATE_PER_PAGE_VALUES',
'10,20,50,100,200');
16 define(
'CH_WSB_PAGINATE_PER_PAGE_DEFAULT', 10);
17 define(
'CH_WSB_PAGINATE_RANGE', 3);
108 parent::__construct();
111 $this->_iStart = isset($aParams[
'start']) ? (int)$aParams[
'start'] : 0;
112 $this->_iCount = isset($aParams[
'count']) ? (int)$aParams[
'count'] : 0;
114 $this->_sSorting = isset($aParams[
'sorting']) ? $aParams[
'sorting'] :
'';
115 $this->_sPageUrl = isset($aParams[
'page_url']) ? $aParams[
'page_url'] : CH_WSB_URL_ROOT;
117 $this->_iPage = isset($aParams[
'page']) ? (int)$aParams[
'page'] : 0;
119 $this->_sViewAllUrl = isset($aParams[
'view_all_url']) ? $aParams[
'view_all_url'] : CH_WSB_URL_ROOT;
122 if(
empty($this->_iStart) && !
empty($this->_iPage)) {
123 $this->_iStart = ($this->_iPage - 1) * $this->_iPerPage;
128 $this->_sOnChangePage = isset($aParams[
'on_change_page']) ? $aParams[
'on_change_page'] :
'';
129 $this->_sOnChangePerPage = isset($aParams[
'on_change_per_page']) ? $aParams[
'on_change_per_page'] :
'';
130 $this->_sOnChangeSorting = isset($aParams[
'on_change_sorting']) ? $aParams[
'on_change_sorting'] :
'';
136 $this->_sPerPageValues = isset($aParams[
'per_page_values']) ? $aParams[
'per_page_values'] :
'…,'.CH_WSB_PAGINATE_PER_PAGE_VALUES;
139 $this->_bInfo = isset($aParams[
'info']) && $aParams[
'info'] ===
true;
140 $this->_bViewAll = isset($aParams[
'view_all']) && $aParams[
'view_all'] ===
true;
141 $this->_bPageReloader = isset($aParams[
'page_reloader']) && $aParams[
'page_reloader'] ===
true;
142 $this->_bPerPageChanger = isset($aParams[
'per_page_changer']) && $aParams[
'per_page_changer'] ===
true;
143 $this->_bPageLinks = !isset($aParams[
'page_links']) || (isset($aParams[
'page_links']) && $aParams[
'page_links'] ===
true);
144 $this->_bPageLinksFirstLast = $this->_bPageLinks && isset($aParams[
'page_links_first_last']) && $aParams[
'page_links_first_last'] ===
true;
147 $this->_sButtonActiveTmpl =
$GLOBALS[
'oTemplConfig']->sPaginateButtonActiveTmpl;
148 $this->_sButtonActiveTmplMobile =
$GLOBALS[
'oTemplConfig']->sPaginateButtonActiveTmplMobile;
149 $this->_sButtonInactiveTmpl =
$GLOBALS[
'oTemplConfig']->sPaginateButtonInactiveTmpl;
151 $this->_sLinkActiveTmpl =
$GLOBALS[
'oTemplConfig']->sPaginateLinkActiveTmpl;
152 $this->_sLinkInactiveTmpl =
$GLOBALS[
'oTemplConfig']->sPaginateLinkInactiveTmpl;
153 $this->_sSortingTmpl =
$GLOBALS[
'oTemplConfig']->sPaginateSortingTmpl;
157 $this->_iCount = $iCount;
161 $this->_sOnChangePage =
$sCode;
165 $this->_sOnChangePerPage =
$sCode;
169 if(!
empty($sSorting))
170 $this->_sSorting = $sSorting;
173 $sSortingTitle =
_t(
'_Order by');
176 foreach($aValues
as $sKey => $sValue)
177 $sContent .=
'<option value="' . $sKey .
'" ' . ($sKey == $this->_sSorting ?
'selected="selected"' :
'') .
'>' .
_t($sValue) .
'</option>';
181 if(!
empty($this->_sOnChangeSorting))
182 $sOnChangeSorting = $this->
parseHtmlByContent($this->_sOnChangeSorting, $aReplacement, array(
'{',
'}'));
184 $aReplacement[
'page'] = 1;
185 $aReplacement[
'sorting'] =
"' + this.value + '";
186 $sOnChangeSorting =
"window.location='" . $this->
parseHtmlByContent($this->_sPageUrl, $aReplacement, array(
'{',
'}')) .
"'";
188 $aReplacement = array (
189 'title' => $sSortingTitle,
190 'on_click' =>
'onchange="javascript:' . $sOnChangeSorting .
'"',
203 $this->_iStart = $iStart;
206 $this->_iPages = ceil( $this->_iCount / $this->_iPerPage);
208 if( $this->_iPages <= 1)
211 $this->_iPage = round($this->_iStart/$this->_iPerPage) + 1;
213 $this->_iPages = (int)ceil(round($this->_iCount/$this->_iPerPage));
214 $this->_iPages = $this->_iPages * $this->_iPerPage < $this->_iCount ? $this->_iPages + 1 :
$this->_iPages;
216 $iRangeBeg = ($iRangeBeg = $this->_iPage -
$this->_iRange) > 1 ? $iRangeBeg : 1;
217 $iRangeEnd = ($iRangeEnd = $this->_iPage +
$this->_iRange) < $this->_iPages ? $iRangeEnd : $this->_iPages;
220 $sPageCpt =
_t(
'_Page');
221 $sNextCpt =
_t(
'_Next page');
222 $sLastCpt =
_t(
'_Last page');
223 $sPrevCpt =
_t(
'_Previous page');
224 $sFirstCpt =
_t(
'_First page');
226 $sViewAllCpt =
_t(
'_View All');
227 $sReloaderCpt =
_t(
'_Refresh');
234 if($this->_iPage > 1) {
236 if($this->_bPageLinksFirstLast) {
237 $aReplacementLink = array_merge($aReplacement, array(
'start' => 0,
'page' => 1));
239 'icon' =>
'step-backward',
240 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_first.png'),
243 'lnk_title' => $sFirstCpt,
244 'img_title' => $sFirstCpt
249 $aReplacementLink = array_merge($aReplacement, array(
'start' => $this->_iStart - $this->_iPerPage,
'page' => $this->_iPage - 1));
251 'icon' =>
'backward',
252 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_prev.png'),
255 'lnk_title' => $sPrevCpt,
256 'img_title' => $sPrevCpt
260 if($this->_bPageLinksFirstLast) {
262 'icon' =>
'step-backward',
263 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_first.png'),
264 'img_title' => $sFirstCpt
270 'icon' =>
'backward',
271 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_prev.png'),
272 'img_title' => $sPrevCpt
277 if($this->_bPageLinks)
278 for($i = $iRangeBeg; $i <= $iRangeEnd; $i++)
279 if($i == $this->_iPage)
284 $aReplacementLink = array_merge($aReplacement, array(
'start' => ($i - 1) * $this->_iPerPage,
'page' => $i));
293 if($this->_iPage < $this->_iPages) {
295 $aReplacementLink = array_merge($aReplacement, array(
'start' => $this->_iPage * $this->_iPerPage,
'page' => $this->_iPage + 1));
298 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_next.png'),
301 'lnk_title' => $sNextCpt,
302 'img_title' => $sNextCpt
306 if($this->_bPageLinksFirstLast) {
307 $aReplacementLink = array_merge($aReplacement, array(
'start' => ($this->_iPages - 1) * $this->_iPerPage,
'page' => $this->_iPages));
309 'icon' =>
'step-forward',
310 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_last.png'),
313 'lnk_title' => $sLastCpt,
314 'img_title' => $sLastCpt
321 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_next.png'),
322 'img_title' => $sNextCpt
326 if($this->_bPageLinksFirstLast) {
328 'icon' =>
'step-forward',
329 'btn_img_src' => $this->
getIconUrl(
'sys_pgt_last.png'),
330 'img_title' => $sLastCpt
336 $aVariables = array (
337 'class' => $bSimple ?
' paginate_simple' :
'',
338 'ch_if:info' => array (
339 'condition' => $this->_bInfo,
341 'from' => $this->_iStart + 1,
342 'to' => ($iTo = $this->_iStart + $this->_iPerPage) < $this->_iCount ? $iTo : $this->_iCount,
344 'total' => $this->_iCount,
347 'ch_if:view_all' => array(
348 'condition' => $this->_bViewAll,
350 'lnk_url' => $this->_sViewAllUrl,
351 'lnk_title' => $sViewAllCpt,
352 'lnk_content' => $sViewAllCpt .
' (' . $this->_iCount .
')'
355 'ch_if:reloader' => array(
356 'condition' => $this->_bPageReloader,
360 'lnk_title' => $sReloaderCpt,
363 'ch_if:per_page' => array(
364 'condition' => $this->_bPerPageChanger,
370 return $this->
parseHtmlByName($sTemplate ? $sTemplate :
'paginate.html', $aVariables);
374 if(!
empty($sViewAllUrl))
375 $this->_sViewAllUrl = $sViewAllUrl;
377 $this->_bInfo =
false;
378 $this->_bPageReloader =
false;
379 $this->_bPerPageChanger =
false;
380 $this->_bPageLinks =
false;
381 $this->_bViewAll = $bViewAll;
388 $this->_bInfo =
false;
389 $this->_bPageReloader =
false;
390 $this->_bPerPageChanger =
false;
391 $this->_bPageLinks =
false;
392 $this->_bViewAll =
false;
398 $this->_sButtonInactiveTmpl =
'';
402 $this->_sButtonActiveTmpl = $sButtonActiveTmpl;
403 $this->_sButtonInactiveTmpl = $sButtonInactiveTmpl;
411 'start' => $this->_iStart,
412 'count' => $this->_iCount,
413 'page' => $this->_iPage,
414 'pages' => $this->_iPages,
415 'per_page' => $this->_iPerPage,
416 'sorting' => $this->_sSorting
425 return !
empty($this->_sOnChangePage) ?
'onclick="javascript:' . $this->
parseHtmlByContent($this->_sOnChangePage, $aReplacement, array(
'{',
'}')) .
'; return false;"' :
'';
432 $sMethod =
'_getPerPageChanger' . ucfirst($this->_sPerPageType);
433 if(!method_exists($this, $sMethod))
436 return $this->$sMethod();
441 $iInterval = floor($this->_iPerPage / $this->_iPerPageStep);
442 $iInterval = $iInterval > $this->_iPerPageInterval ? $this->_iPerPageInterval : $iInterval;
445 $iCount = 2 * $iInterval + 1;
452 'opt_value' => $iValue,
453 'opt_selected' => ($iValue == $this->_iPerPage ?
' selected="selected"' :
''),
454 'opt_caption' => $iValue,
458 if(!
empty($this->_sOnChangePerPage))
459 $sPerPageOnChange = $this->
parseHtmlByContent($this->_sOnChangePerPage, $aReplacement, array(
'{',
'}'));
461 $sPerPageOnChange =
"window.location='" . $this->
_getPageChangeUrl(array_merge($aReplacement, array(
'page' => 1,
'per_page' =>
"' + this.value + '"))) .
"'";
464 'per_page_caption' =>
_t(
'_Results per page'),
465 'per_page_on_change' => $sPerPageOnChange,
466 'ch_repeat:options' => $aOptions
472 $aValues = explode(
",", $this->_sPerPageValues);
475 foreach($aValues
as $iValue)
476 if($iValue > 0 ||
'…' == $iValue)
478 'opt_value' =>
'…' == $iValue ? $this->_iPerPage : $iValue,
479 'opt_selected' => ($iValue == $this->_iPerPage ?
' selected="selected"' :
''),
480 'opt_caption' => $iValue,
484 if(!
empty($this->_sOnChangePerPage))
485 $sPerPageOnChange = $this->
parseHtmlByContent($this->_sOnChangePerPage, $aReplacement, array(
'{',
'}'));
487 $sPerPageOnChange =
"window.location='" . $this->
_getPageChangeUrl(array_merge($aReplacement, array(
'page' => 1,
'per_page' =>
"' + this.value + '"))) .
"'";
490 'per_page_caption' =>
_t(
'_Results per page'),
491 'per_page_on_change' => $sPerPageOnChange,
492 'ch_repeat:options' => $aOptions