Making BSPagination an abstract class that people extend instead of using callback...
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 28 Feb 2008 20:11:45 +0000 (15:11 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 28 Feb 2008 20:11:45 +0000 (15:11 -0500)
* Pagination.php

Pagination.php

index 9ab0fdf170e016687d14c9261910328e905ce9ae..ae824258f5cd37a31e01265e46789b9f9a019563 100644 (file)
 * @package             ISSO
 * 
 */
-class BSPagination
+abstract class BSPagination
 {
        /**
        * Current page number
        * @var  integer
        */
-       private $page;
+       protected $page;
        
        /**
        * Per-page value
        * @var  integer
        */
-       private $perpage;
+       protected $perpage;
        
        /**
        * Number of page links
        * @var  integer
        */
-       private $pagelinks;
+       protected $pagelinks;
        
        /**
        * Total number of results
        * @var  integer
        */
-       private $total;
+       protected $total;
        
        /**
        * Total number of pages
        * @var  integer
        */
-       private $pagecount;
-       
-       /**
-       * Name of page variable
-       * @var  array
-       */
-       private $pagevar = 'p';
-       
-       /**
-       * Name of per-page variable
-       * @var  integer
-       */
-       private $perpagevar = 'pp';
+       protected $pagecount;
        
        /**
        * Maximum number of per-page results
        * @var  integer
        */
-       private $maxperpage = 100;
+       protected $maxperpage = 100;
        
        /**
        * Default number of per-page results
        * @var  integer
        */
-       private $defaultperpage = 20;
+       protected $defaultperpage = 20;
        
+       // ###################################################################
        /**
-       * The processing callback public function for individual pagenav bits
-       * @var string
-       */
-       private $bitprocessor = ':undefined:';
+        * Callback public function for the processing of an indivdual page link
+        * 
+        * @param       string  The base link
+        * @param       boolean Wether or not the item is the current page
+        * @param       integer Page number
+        * 
+        * @return      string  Compiled HTML
+        */
+       protected abstract function _bitProcessor($baselink, $isCurrent, $pagenumber);
        
+       // ###################################################################
        /**
-       * The processing callback public function for the entire pagenav system
-       * @var string
-       */
-       private $pagenavprocessor = ':undefined:';
+        * Callback public function for the processing the entire page navigator
+        * 
+        * @param       string  The base link
+        * @param       integer Next page number
+        * @param       integer Previous page number
+        * @param       array   Show options: array('first' => (boolean)first page link, 'last' => boolean, 'prev' => boolean, 'next' => boolean)
+        * @param       string  Bits to process
+        *
+        * @return      string  Compiled HTML
+        */
+       protected abstract function _navigationProcessor($baselink, $next, $prev, $show, $bits);
+       
+       /**
+        * Set the Pagination->perpage and Pagination->page variables
+        */
+       protected abstract function _setVariables();
        
        /**
         * Constructor
@@ -117,32 +124,6 @@ class BSPagination
                }
        }
        
-       // ###################################################################
-       /**
-       * Callback public function for the processing of an indivdual page. Needs
-       * the signature:
-       * public string callback(string $baseLink, boolean $noLink, integer $pageNumber, Pagination $this)
-       *
-       * @param        string  Callback function
-       */
-       public function setBitProcessor($callback)
-       {
-               $this->bitprocessor = $callback;
-       }
-       
-       // ###################################################################
-       /**
-       * Callback public function for the processing the entire page navigator. Needs
-       * the signature:
-       * public string callback(string $baseLink, integer $nextPage, integer $prevPage array $show['first'=>first page, 'last'=>last page, 'prev'=>previous page, 'next'=>next page], string $bits, Pagination $this)
-       *
-       * @param        string  Callback function
-       */
-       public function setNavigatorProcessor($callback)
-       {
-               $this->pagenavprocessor = $callback;
-       }
-       
        // ###################################################################
        /**
        * Returns the current page number
@@ -186,62 +167,7 @@ class BSPagination
        {
                return $this->pagecount;
        }
-       
-       // ###################################################################
-       /**
-       * Sets pagelinks
-       *
-       * @param        integer Number of page links
-       */
-       public function setPageLinks($pagelinks)
-       {
-               $this->pagelinks = $pagelinks;
-       }
-       
-       // ###################################################################
-       /**
-       * Sets pagevar
-       *
-       * @param        string  Page variable
-       */
-       public function setPageVar($pagevar)
-       {
-               $this->pagevar = $pagevar;
-       }
-       
-       // ###################################################################
-       /**
-       * Sets perpagevar
-       *
-       * @param        string  Per-page variable
-       */
-       public function setPerPageVar($perpagevar)
-       {
-               $this->perpagevar = $perpagevar;
-       }
-       
-       // ###################################################################
-       /**
-       * Sets maxperpage
-       *
-       * @param        integer Maximum number per page
-       */
-       public function setMaxPerPage($maxperpage)
-       {
-               $this->maxperpage = $maxperpage;
-       }
-       
-       // ###################################################################
-       /**
-       * Sets defaultperpage
-       *
-       * @param        integer Total number
-       */
-       public function setDefaultPerPage($defaultperpage)
-       {
-               $this->defaultperpage = $defaultperpage;
-       }
-       
+               
        // ###################################################################
        /**
        * Takes all of the information from the set() functions and then
@@ -249,8 +175,9 @@ class BSPagination
        */
        public function processIncomingData()
        {
-               $this->page = BSApp::$input->inputClean($this->pagevar, TYPE_INT);
-               $this->perpage = BSApp::$input->inputClean($this->perpagevar, TYPE_INT);
+               $this->_setVariables();
+               $this->page = BSApp::$input->clean($this->page, TYPE_INT);
+               $this->perpage = BSApp::$input->clean($this->perpage, TYPE_INT);
                $this->pagelinks = BSApp::$input->clean($this->pagelinks, TYPE_INT);
 
                if ($this->page <= 0)
@@ -343,7 +270,7 @@ class BSPagination
                        {
                                $baselink .= '?';
                        }
-                       else if (!preg_match('#\?$#', $baselink) && !preg_match('#(&|&amp;)$#', $baselink))
+                       else if (!strpos($baselink, '#\?$#') && !strpos($baselink, '&'))
                        {
                                $baselink .= '&amp;';
                        }
@@ -407,7 +334,6 @@ class BSPagination
                
                // construct the page bits
                $bits = '';
-               $call = $this->bitprocessor;
                for ($i = $startpage; $i <= $endpage; $i++)
                {
                        if ($i == $this->page)
@@ -419,11 +345,10 @@ class BSPagination
                                $nolink = false;
                        }
                        
-                       $bits .= $call($baselink, $nolink, $i, $this);
+                       $bits .= $this->_bitProcessor($baselink, $nolink, $i);
                }
-                               
-               $call = $this->pagenavprocessor;
-               return $call($baselink, $nextpage, $prevpage, $show, $bits, $this);
+               
+               return $this->_navigationProcessor($baselink, $nextpage, $prevpage, $show, $bits);
        }
 }