JetTableAllClasses
Current view: C:\xampp\htdocs\table\jettable\JetPager.class.php
Date: Fri Dec 1 17:20:38 JST 2006 Executable lines: 102
Code covered: 94.12% Executed lines: 96
Legend: executed not executed dead code


       1                 : <?php                                                                                    
       2                 : /**                                                                                      
       3                 :  * ページング機能出力クラス<br>                                                          
       4                 :  * ページング機能を出力するクラス。                                                      
       5                 :  *                                                                                       
       6                 :  * @package    jettable.framework                                                        
       7                 :  * @author     rds <tk@rasign.jp>                                                        
       8                 :  * @license     http://www.opensource.org/licenses/mit-license.php The MIT License       
       9                 :  * @version    $Revision: 1.4 $ $Date: 2006/12/01 13:41:52 $                             
      10                 :  * @link       http://jettable.rasign.jp/                                                
      11                 :  */                                                                                      
      12                 : class JetPager{                                                                          
      13                 :     private $currentPageNumber;                                                             
      14                 :     private $pageParItems;                                                                  
      15                 :     private $totalItemCount;                                                                
      16                 :     private $viewPageLinks;                                                                 
      17                 :     private $pageParItemType;                                                               
      18                 :     private $scriptName;                                                                    
      19                 :                                                                                          
      20                 :     private $parameterPageString = "page";                                                  
      21                 :     private $parameterPageParString = "pagePar";                                            
      22                 :                                                                                          
      23                 :     /**                                                                                  
      24                 :      * デフォルトコンストラクタ<br>                                                      
      25                 :      * 各変数の初期化を行います。<br>                                                    
      26                 :      *                                                                                   
      27                 :      * @param $currentPageNumber 現在のページ番号                                        
      28                 :      * @param $pageParItems ページ内のアイテム(行)数                                   
      29                 :      * @param $viewPageLinks ページリンク表示数                                          
      30                 :      * @param $scriptName リンク先スクリプト名                                           
      31                 :      * @access public                                                                    
      32                 :      */                                                                                  
      33                 :     public function __construct(                                                            
      34                 :             $currentPageNumber = 1,                                                                
      35                 :             $pageParItems = 10,                                                                    
      36                 :             $viewPageLinks = 10,                                                                  
      37                 :             $scriptName = null){                                                                  
      38              34 :         $this->currentPageNumber = $currentPageNumber;                                         
      39              34 :         $this->pageParItems = $pageParItems;                                                   
      40              34 :         $this->viewPageLinks = $viewPageLinks;                                                 
      41              34 :         $this->scriptName = $scriptName;                                                       
      42                 :                                                                                                  
      43              34 :         $this->pageParItemType = array("10"=>"10", "30"=>"30", "50"=>"50");                    
      44              34 :         $this->setTotalItemCount(0);                                                           
      45              34 :     }                                                                                       
      46                 :                                                                                          
      47                 :     /**                                                                                  
      48                 :      * 総件数設定<br>                                                                    
      49                 :      * アイテムの総件数を設定します。<br>                                                
      50                 :      *                                                                                   
      51                 :      * @param $totalItemCount 総件数                                                     
      52                 :      * @access public                                                                    
      53                 :      */                                                                                  
      54                 :     public function setTotalItemCount($totalItemCount){                                     
      55              34 :         $this->totalItemCount = $totalItemCount;                                               
      56              34 :     }                                                                                       
      57                 :                                                                                          
      58                 :     /**                                                                                  
      59                 :      * 総件数取得<br>                                                                    
      60                 :      * アイテムの総件数を取得します。<br>                                                
      61                 :      *                                                                                   
      62                 :      * @return 総件数                                                                    
      63                 :      * @access public                                                                    
      64                 :      */                                                                                  
      65                 :     public function getTotalItemCount(){                                                    
      66               1 :         return $this->totalItemCount;                                                          
      67                 :     }                                                                                       
      68                 :                                                                                          
      69                 :     /**                                                                                  
      70                 :      * ページ内アイテム数設定<br>                                                        
      71                 :      * 1ページに表示するアイテム(行)の件数を設定します。<br>                          
      72                 :      *                                                                                   
      73                 :      * @param $pageParItems 総件数                                                       
      74                 :      * @access public                                                                    
      75                 :      */                                                                                  
      76                 :     public function setPageParItems($pageParItems){                                         
      77               4 :         $this->pageParItems = $pageParItems;                                                   
      78               4 :     }                                                                                       
      79                 :                                                                                          
      80                 :     /**                                                                                  
      81                 :      * ページ内アイテム数取得<br>                                                        
      82                 :      * 1ページに表示するアイテム(行)の件数を取得します。<br>                          
      83                 :      *                                                                                   
      84                 :      * @return 総件数                                                                    
      85                 :      * @access public                                                                    
      86                 :      */                                                                                  
      87                 :     public function getPageParItems(){                                                      
      88               4 :         return $this->pageParItems;                                                            
      89                 :     }                                                                                       
      90                 :                                                                                          
      91                 :     /**                                                                                  
      92                 :      * 現在ページ設定<br>                                                                
      93                 :      * 現在表示中のページ番号を設定します。<br>                                          
      94                 :      *                                                                                   
      95                 :      * @param $currentPageNumber ページ番号                                              
      96                 :      * @access public                                                                    
      97                 :      */                                                                                  
      98                 :     public function setCurrentPageNumber($currentPageNumber){                               
      99               7 :         $this->currentPageNumber = $currentPageNumber;                                         
     100               7 :     }                                                                                       
     101                 :                                                                                          
     102                 :     /**                                                                                  
     103                 :      * 現在ページ設定<br>                                                                
     104                 :      * 現在表示中のページ番号を取得します。<br>                                          
     105                 :      *                                                                                   
     106                 :      * @return ページ番号                                                                
     107                 :      * @access public                                                                    
     108                 :      */                                                                                  
     109                 :     public function getCurrentPageNumber(){                                                 
     110               5 :         return $this->currentPageNumber;                                                       
     111                 :     }                                                                                       
     112                 :                                                                                          
     113                 :     /**                                                                                  
     114                 :      * 最大ページ番号<br>                                                                
     115                 :      * 最大ページ番号を取得します。<br>                                                  
     116                 :      *                                                                                   
     117                 :      * @return 最大ページ番号                                                            
     118                 :      * @access public                                                                    
     119                 :      */                                                                                  
     120                 :     public function getMaxPage(){                                                        
     121               7 :         return ceil($this->totalItemCount / $this->pageParItems);                              
     122                 :     }                                                                                       
     123                 :                                                                                          
     124                 :     /**                                                                                  
     125                 :      * 表示中の最大ページ番号<br>                                                        
     126                 :      * 表示中の最大ページ番号を取得します。<br>                                          
     127                 :      *                                                                                   
     128                 :      * @return 表示中の最大ページ番号                                                    
     129                 :      * @access public                                                                    
     130                 :      */                                                                                  
     131                 :     public function getViewMaxPage(){                                                       
     132               4 :         $page = $this->currentPageNumber;                                                      
     133               4 :         $totalPageCount = $this->getMaxPage();                                                 
     134               4 :         $startViewPageLink = $page - ceil($this->viewPageLinks / 2) - 1;                       
     135               4 :         $endViewPageLink = $page + ceil($this->viewPageLinks / 2) - 1;                         
     136                 :                                                                                          
     137               4 :         if($startViewPageLink < 1){                                                            
     138               4 :             $sa = 0 - $startViewPageLink;                                                         
     139               4 :             $startViewPageLink = 0;                                                               
     140               4 :             $endViewPageLink += $sa;                                                              
     141                 :         }                                                                                      
     142               4 :         if($endViewPageLink > $totalPageCount){                                                
     143               4 :             $sa = $endViewPageLink - $totalPageCount;                                             
     144               4 :             $endViewPageLink = $totalPageCount;                                                   
     145               4 :             $startViewPageLink -= $sa;                                                            
     146                 :         }                                                                                      
     147               4 :         return $endViewPageLink;                                                               
     148                 :     }                                                                                       
     149                 :                                                                                          
     150                 :     /**                                                                                  
     151                 :      * 表示中の最小ページ番号<br>                                                        
     152                 :      * 表示中の最小ページ番号を取得します。<br>                                          
     153                 :      *                                                                                   
     154                 :      * @return 表示中の最小ページ番号                                                    
     155                 :      * @access public                                                                    
     156                 :      */                                                                                  
     157                 :     public function getViewMinPage(){                                                       
     158               4 :         $page = $this->currentPageNumber;                                                      
     159               4 :         $totalPageCount = $this->getMaxPage();                                                 
     160               4 :         if($totalPageCount < 1){                                                               
     161               2 :             return 0;                                                                             
     162                 :         }                                                                                      
     163               4 :         $startViewPageLink = $page - ceil($this->viewPageLinks / 2) - 1;                       
     164               4 :         $endViewPageLink = $page + ceil($this->viewPageLinks / 2) - 1;                         
     165                 :                                                                                          
     166               4 :         if($endViewPageLink > $totalPageCount){                                                
     167               4 :             $sa = $endViewPageLink - $totalPageCount;                                             
     168               4 :             $endViewPageLink = $totalPageCount;                                                   
     169               4 :             $startViewPageLink -= $sa;                                                            
     170                 :         }                                                                                      
     171               4 :         if($startViewPageLink < 1){                                                            
     172               4 :             $sa = 0 - $startViewPageLink;                                                         
     173               4 :             $startViewPageLink = 0;                                                               
     174               4 :             $endViewPageLink += $sa;                                                              
     175                 :         }                                                                                      
     176               4 :         return $startViewPageLink + 1;                                                         
     177                 :     }                                                                                       
     178                 :                                                                                          
     179                 :     public function getViewPageLinkCount(){                                                 
     180               0 :         return $this->viewPageLinks();                                                         
     181                 :     }                                                                                       
     182                 :                                                                                          
     183                 :     /**                                                                                  
     184                 :      * シンプルなページングリンク取得<br>                                                
     185                 :      * シンプルなページングリンクを出力するためのテキストを取得します。<br>              
     186                 :      * <br>                                                                              
     187                 :      * 例                                                                                
     188                 :      * <pre>                                                                             
     189                 :      * 1 2 3 4 5 6 7 8 9 10                                                              
     190                 :      * </pre>                                                                            
     191                 :      *                                                                                   
     192                 :      * @return ページング表示用文字列(HTMLコード)                                        
     193                 :      * @access public                                                                    
     194                 :      */                                                                                  
     195                 :     public function getBasicPagerHtml($attributeArray = array()){                           
     196               5 :         $page = $this->currentPageNumber;                                                      
     197               5 :         if(!is_numeric($page)){                                                                
     198               1 :             return null;                                                                          
     199                 :         }                                                                                      
     200               5 :         if($page < 1){                                                                         
     201               1 :             return null;                                                                          
     202                 :         }                                                                                      
     203                 :                                                                                          
     204               4 :         $totalPageCount = $this->getMaxPage();                                                 
     205               4 :         if(!is_numeric($totalPageCount)){                                                      
     206               0 :             return null;                                                                          
     207                 :         }                                                                                      
     208               4 :         if($totalPageCount < 1){                                                               
     209               2 :             return null;                                                                          
     210                 :         }                                                                                      
     211                 :                                                                                          
     212               3 :         $startViewPageLink = $this->getViewMinPage();                                          
     213               3 :         if(!is_numeric($startViewPageLink)){                                                   
     214               0 :             return null;                                                                          
     215                 :         }                                                                                      
     216               3 :         if($startViewPageLink < 1){                                                            
     217               0 :             return null;                                                                          
     218                 :         }                                                                                      
     219                 :                                                                                          
     220               3 :         $endViewPageLink = $this->getViewMaxPage();                                            
     221               3 :         if(!is_numeric($endViewPageLink)){                                                     
     222               0 :             return null;                                                                          
     223                 :         }                                                                                      
     224               3 :         if($endViewPageLink < 1){                                                              
     225               0 :             return null;                                                                          
     226                 :         }                                                                                      
     227                 :                                                                                          
     228               3 :         foreach($attributeArray as $attribute){                                                
     229               2 :             if($attribute->key == $this->parameterPageString){                                    
     230               2 :                 continue;                                                                            
     231                 :             }                                                                                     
     232               2 :             if($attribute->key == $this->parameterPageParString){                                 
     233               2 :                 $pageAttributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);  
     234               2 :                 continue;                                                                            
     235                 :             }                                                                                     
     236               1 :             $pageAttributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);   
     237               1 :             $pageParAttributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);
     238               1 :         }                                                                                      
     239                 :                                                                                          
     240               3 :         $text = "Page:";                                                                       
     241               3 :         for($i = $startViewPageLink; $i <= $endViewPageLink; $i++){                            
     242               3 :             if($i == $page){                                                                      
     243               3 :                 $text .= $i;                                                                         
     244               3 :             }else{                                                                                
     245               2 :                 $text .= "<a href=\"" . $this->scriptname . "?";                                     
     246               2 :                 $text .= $this->parameterPageString . "=" . $i . $pageAttributeString ."\">";        
     247               2 :                 $text .= $i;                                                                         
     248               2 :                 $text .= "</a>";                                                                     
     249                 :             }                                                                                     
     250               3 :             if($i != $totalPageCount){                                                            
     251               2 :                 $text .= "&nbsp;";                                                                   
     252                 :             }                                                                                     
     253               2 :         }                                                                                      
     254                 :                                                                                          
     255               3 :         $text .= "&nbsp;";                                                                     
     256               3 :         $text .= "&nbsp;";                                                                     
     257               3 :         $text .= "&nbsp;";                                                                     
     258               3 :         $text .= "Items:";                                                                     
     259               3 :         foreach($this->pageParItemType as $pageParItemKey=>$pageParItemValue){                 
     260               3 :             if($pageParItemValue == $this->pageParItems){                                         
     261               2 :                 $text .= $pageParItemValue . "&nbsp;";                                               
     262               2 :             }else{                                                                                
     263               3 :                 $text .= "<a href=\"" . $this->scriptname . "?";                                     
     264               3 :                 $text .= $this->parameterPageString . "=1" . $pageParAttributeString;                
     265               3 :                 $text .= "&" . $this->parameterPageParString . "=" . $pageParItemValue . "\">";      
     266               3 :                 $text .= $pageParItemKey;                                                            
     267               3 :                 $text .= "</a>&nbsp;";                                                               
     268                 :             }                                                                                     
     269               3 :         }                                                                                      
     270               3 :         return $text;                                                                          
     271                 :     }                                                                                       
     272                 : }                                                                                        
     273                 : ?>                                                                                       

Generated by: PHPUnit 3.0.0 and Xdebug 2.0.0RC1.