1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* ページングリンクのhandlerクラス。
* $Id: PagingHandler.inc 81458 2015-03-31 11:24:20Z dongw $
* @author wangk
* @access public
* @package jp.mkpoint.handler
*/
class PagingHandler {
/**
* ページングの範囲を取得。
* @param int $page_num ペイジ
* @param int $page_count 全部頁数
* @param int $show_page_num ペイジ範囲数
*
*/
public static function getPageRange($page_num, $page_count, $show_page_num) {
if ($show_page_num % 2 == 1) {
if ($page_count <= $show_page_num) {
$page_first = 1;
$page_end = $page_count;
} else if ($page_num <= ceil($show_page_num / 2)) {
$page_first = 1;
$page_end = $show_page_num;
} else if (($page_num > ceil($show_page_num / 2)) && ($page_num < ($page_count - ceil($show_page_num / 2) + 2))) {
$page_first = $page_num - ceil($show_page_num / 2) + 1;
$page_end = $page_num + ceil($show_page_num / 2) - 1;
} else if ($page_num >= ($page_count - ceil($show_page_num / 2) + 2)) {
$page_first = $page_count - $show_page_num + 1;
$page_end = $page_count;
}
} else {
if ($page_count <= $show_page_num) {
$page_first = 1;
$page_end = $page_count;
} else if ($page_num <= ($show_page_num / 2)) {
$page_first = 1;
$page_end = $show_page_num;
} else if (($page_num > ($show_page_num / 2)) && ($page_num < ($page_count - ($show_page_num / 2) + 1))) {
$page_first = $page_num - ($show_page_num / 2) + 1;
$page_end = $page_num + ($show_page_num / 2);
} else if ($page_num >= ($page_count - ($show_page_num / 2) + 1)) {
$page_first = $page_count - $show_page_num + 1;
$page_end = $page_count;
}
}
$page_range = array();
array_push($page_range, $page_first);
array_push($page_range, $page_end);
return $page_range;
}
}
?>