PagingHandler.inc 1.77 KB
<?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;
	}
}
?>