aliroPageNav.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * aliroPageNav is a container that actually instantiates either aliroUserPageNav
00038  * or aliroAdminPageNav, depending on whether we are user side or admin side.
00039  * All calls are then passed to the instantiated class.
00040  *
00041  * aliroAbstractPageNav provides a base and does much of the work for both the
00042  * admin and user side classes.
00043  *
00044  * aliroUserPageNav is the actual class for user side page navigation.
00045  *
00046  */
00047 
00048 class aliroPageNav {
00049     protected $realPageNav = null;
00050 
00051     public function __construct ($total, $limitstart, $limit) {
00052         $info = criticalInfo::getInstance();
00053         if ($info->isAdmin) $this->realPageNav = new aliroAdminPageNav ($total, $limitstart, $limit);
00054         else $this->realPageNav = new aliroUserPageNav ($total, $limitstart, $limit);
00055     }
00056 
00057     public function __get ($property) {
00058         return $this->realPageNav->$property;
00059     }
00060 
00061     public function __call ($method, $args) {
00062         return call_user_func_array(array($this->realPageNav, $method), $args);
00063     }
00064 
00065 }
00066 
00067 class mosPageNav extends aliroPageNav {
00068     //  Actually just an alias for backwards compatibility
00069 }
00070 
00071 abstract class aliroAbstractPageNav {
00072     public $limitstart = null;
00073     public $limit = null;
00074     public $total = null;
00075 
00076     public function __construct ( $total, $limitstart, $limit ) {
00077         $this->total = max($total, 0);
00078         $this->limit = max($limit, 1);
00079         if ($this->limit > $this->total) $this->limitstart = '0';
00080         else {
00081             while ($limitstart > $this->total) $limitstart -= $this->limit;
00082             $this->limitstart = ($limitstart > 0) ? $limitstart : '0';
00083         }
00084     }
00085 
00086     protected function makeLimitSteps () {
00087         $steps = array ('5', '10', '15', '20', '25', '30', '50');
00088         $alirohtml = aliroHTML::getInstance();
00089         foreach ($steps as $step) $limits[] = $alirohtml->makeOption($step);
00090         return $limits;
00091     }
00092 
00093     // SEF is not used admin side
00094     protected function fixLink ($link) {
00095         if ($this->isAdmin) return $link;
00096         $sef = aliroSEF::getInstance();
00097         return $sef->sefRelToAbs($link);
00098     }
00099 
00103     public function getPagesCounter() {
00104         $html = '';
00105         $to_result = min ($this->limitstart + $this->limit, $this->total);
00106         if ($this->total) $html .= sprintf(T_("Results %d to %d of %d"), $this->limitstart+1, $to_result, $this->total);
00107         else $html .= T_('No records found.');
00108         return $html;
00109     }
00110 
00114     // The link parameter is actually mandatory but has to be shown as if optional for compatibility with admin version
00115     public function writePagesLinks($link='') {
00116         $html = '';
00117         $total_pages = ceil( $this->total / $this->limit );
00118         $this_page = ceil( ($this->limitstart+1) / $this->limit );
00119         $start_loop = (floor(($this_page-1)/_ALIRO_PAGE_NAV_DISPLAY_PAGES))*_ALIRO_PAGE_NAV_DISPLAY_PAGES+1;
00120         $stop_loop = min($total_pages, $start_loop + _ALIRO_PAGE_NAV_DISPLAY_PAGES - 1);
00121         $link .= '&amp;limit='. $this->limit;
00122         if ($this_page > 1) {
00123             $page = ($this_page - 2) * $this->limit;
00124             $html .= '<a href="'.$this->fixLink ($link.'&amp;limitstart=0').'" class="pagenav" title="'.T_('first page').'">&lt;&lt; '. T_('Start') .'</a> ';
00125             $html .= '<a href="'.$this->fixLink ($link.'&amp;limitstart='.$page).'" class="pagenav" title="'.T_('previous page').'">&lt; '. T_('Previous') .'</a> ';
00126         } else {
00127             $html .= '<span class="pagenav">&lt;&lt; '. T_('Start') .'</span> ';
00128             $html .= '<span class="pagenav">&lt; '. T_('Previous') .'</span> ';
00129         }
00130         for ($i=$start_loop; $i <= $stop_loop; $i++) {
00131             $page = ($i - 1) * $this->limit;
00132             if ($i == $this_page) $html .= '<span class="pagenav">'. $i .'</span> ';
00133             else $html .= '<a href="'.$this->fixLink ($link.'&amp;limitstart='.$page).'" class="pagenav"><strong>'. $i .'</strong></a> ';
00134         }
00135         if ($this_page < $total_pages) {
00136             $page = $this_page * $this->limit;
00137             $end_page = ($total_pages-1) * $this->limit;
00138             $html .= '<a href="'.$this->fixLink ($link.'&amp;limitstart='.$page).' " class="pagenav" title="'.T_('next page').'">'. T_('Next') .' &gt;</a> ';
00139             $html .= '<a href="'.$this->fixLink ($link.'&amp;limitstart='.$end_page).' " class="pagenav" title="'.T_('end page').'">'. T_('End') .' &gt;&gt;</a>';
00140         } else {
00141             $html .= '<span class="pagenav">'. T_('Next') .' &gt;</span> ';
00142             $html .= '<span class="pagenav">'. T_('End') .' &gt;&gt;</span>';
00143         }
00144         return $html;
00145     }
00146 
00147 }
00148 
00149 class aliroUserPageNav extends aliroAbstractPageNav {
00150     protected $isAdmin = false;
00156     public function getLimitBox ($link) {
00157         // build the html select list
00158         $link = aliroSEF::getInstance()->sefRelToAbs($link.'&limit=\' + this.options[selectedIndex].value + \'&limitstart='.$this->limitstart);
00159         return aliroHTML::getInstance()->selectList($this->makeLimitSteps(), 'limit',
00160         'class="inputbox" size="1" onchange="document.location.href=\''.$link.'\';"',
00161         'value', 'text', $this->limit);
00162     }
00167     public function writeLimitBox ( $link ) {
00168         echo $this->getLimitBox( $link );
00169     }
00173     public function writePagesCounter() {
00174         return parent::getPagesCounter();
00175     }
00176 
00180     public function writeLeafsCounter() {
00181         $txt = '';
00182         $page = $this->limitstart+1;
00183         if ($this->total > 0) {
00184             $txt .= sprintf(T_('Page %d of %d'), $page, $this->total);
00185         }
00186         return $txt;
00187     }
00188 
00189 }

Generated on Thu Apr 17 13:03:27 2008 for ALIRO by  doxygen 1.5.5