Help us understand the problem. What is going on with this article?

ページャークラス

More than 5 years have passed since last update.
Pager.class.php
<?php
require_once HOMEPATH. 'models/PagerService.class.php';
require_once HOMEPATH. 'models/PagerFactory.class.php';
//  現在のページの情報をまとめたクラス
class pager {
    private $start; //現在のページの最初の要素番号
    private $item; //1ページの要素数
    private $count; //全要素数
    private $pagenum; //現在のページ番号
    private $lastpage; //最後のページ
    private $nextpage; //次のページがあるかどうか
    private $prevpage; //前のページがあるかどうか
    public function setStart($start){
        $this->start = $start;
    }
    public function setItem($item){
        $this->item = $item;
    }
    public function setCount($count){
        $this->count = $count;
    }
    public function setPagenum($pagenum){
        $this->pagenum = $pagenum;
    }
    public function setLastpage($lastpage){
        $this->lastpage = $lastpage;
    }
    public function setNextpage($nextpage){
        $this->nextpage = $nextpage;
    }
    public function setPrevpage($prevpage){
        $this->prevpage = $prevpage;
    }
    public function setAll($list,$item,$pagenum){
        //開始要素
        $start = ($pagenum - 1) * $item;
        $this->setStart($start);
        //1ページの要素数
        $this->setItem($item);        
        //全要素数
        $count = count($list);
        $this->setCount($count);
        //現在のページ番号
        $this->setPagenum($pagenum);
        //最後のページ
        $lastpage = ceil($count / $item);
        $this->setLastpage($lastpage);
        //次のページがあるかどうか
        if($pagenum == $lastpage){ $this->setNextpage(false); }
        else{ $this->setNextpage(true); }
        //前のページがあるかどうか
        if($pagenum == 1){ $this->setPrevpage(false); }
        else{ $this->setPrevpage(true); }
        //このクラスを返す
        return $this;
    }
    public function getStart(){
        return $this->start;
    }
    public function getItem(){
        return $this->item;
    }
    public function getCount(){
        return $this->count;
    }
    public function getPagenum(){
        return $this->pagenum;
    }
    public function getLastpage(){
        return $this->lastpage;
    }
    public function getNextpage(){
        return $this->nextpage;
    }
    public function getPrevpage(){
        return $this->prevpage;
    }
}
?>
PagerFactory.class.php
<?php
class PagerFactory {
    function __construct() { }
    /*
     * 常にページャークラスを返す
     */
    public function Create($list,$item,$pagenum){           
            $pager = new pager;
            $pager->setAll($list,$item,$pagenum);
            return $pager;
    }
}
?>
PagerService.class.php
<?php
class PagerService {
    public function filter($list,$start,$item){
        $n = 0;
        $end = $start + $item;
        $newlist = array();
        foreach($list as $i){
            if($start <= $n && $n < $end){
                $newlist[$n] = $i;
            }
            $n++;
        }
        return $newlist;
    }
}
?>
hyper_stereo
自分用のメモとして使ってます
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away