[TYPO3-mvc] I proudly present my first TYPO3 MVC Project

Sebastian Gebhard sebastian.gebhard at googlemail.com
Tue Jul 28 22:27:16 CEST 2009


Julian Kleinhans schrieb:
> Hi Sebastian,
Hi :)
> really cool and congrats for the first launch!
Thanks
> The pagebrowser, is that realize over an viewhelper?
True
> I need a good pagebrowser, it would be very cool if you could share it 
> with us  :-)
Of course:

<?php
/**
  * PageBrowserViewHelper for Fluid template Engine
  *
  * @package TYPO3
  * @subpackage Fluid
  * @author Sebastian Gebhard
  */
class Tx_Autoadmin_ViewHelpers_PageBrowserViewHelper extends 
Tx_Fluid_Core_ViewHelper_AbstractViewHelper{

     // TODO: All the properties of this Class should not be hardcoded
     // but should be supplied with TS-Settings

     /**
      * @var integer x pages before and after active page will be shown
      */
     private $pageSchemeAroundAct = 2;

     /**
      * @var integer Each xth page will be shown in the pagebrowser
      */
     private $pageSchemeEach = 10;

     /**
      * @var integer First x pages will be shown in the pagebrowser
      */
     private $pageSchemeFirst = 5;

     /**
      * @var integer Last x pages will be shown in the pagebrowser
      */
     private $pageSchemeLast = 3;

     /**
      * @var string Link Parameter namespace
      */
     private $prefixId = 'tx_autoadmin_pi1';

     /**
      * @param integer $pages
      * @param string $class CSS Class of the Pagebrowser
      */
     public function render($pages, $class = 'pagebrowser'){
	if($pages<2){return;}
	$piVars = t3lib_div::_GP($this->prefixId);
         // Active Page
	$actPage = ($piVars['page'])?$piVars['page']:1;
	// Page List
	$pageList = array();
	
	$pageSchemes = array(
	    // First Pages
	    array(
		'min' => 1,
		'max' => min($pages, $this->pageSchemeFirst)
	    ),
	    // Last 3
	    array(
		'min' => max(1,($pages-($this->pageSchemeLast))),
		'max' => $pages
	    ),
	    // ActPage +- 2
	    array(
		'min' => max(1,($actPage-($this->pageSchemeAroundAct))),
		'max' => min($pages,($actPage+($this->pageSchemeAroundAct)))
	    ),
	    // Each 10
	    array(
		'min' => $this->pageSchemeEach,
		'max' => $pages,
		'iterate' => $this->pageSchemeEach
	    )
	);
	
	foreach($pageSchemes as $pageScheme){
	    $iterate = ($pageScheme['iterate'])?$pageScheme['iterate']:1;
	    for($i=$pageScheme['min'];$i<=$pageScheme['max'];$i=$i+$iterate){
		$pageList[] = $i;
	    }
	}

	$pageList = array_unique($pageList);
	sort($pageList);
	
	$cObj = t3lib_div::makeInstance('tslib_cObj');

	$typolinkConf = array(
	    'parameter' => $GLOBALS['TSFE']->id,
	    'addQueryString' => 1,
	    'addQueryString.' => array(
		'method' => 'GET,POST',
		'exclude' => $this->prefixId.'|page',
	    )
	);
	
	$content = '<ul class="'.$class.'">';
	foreach($pageList as $page){
	    $content .= '<li>';

	    if($page != $actPage){
		$typolinkConf['additionalParams'] = 
$params.'&'.$this->prefixId.'[page]='.$page;
		$uri = $cObj->typolink_URL($typolinkConf);
		$content .= '<a href="'.$uri.'">'.$page.'</a>';
	    }else{
		$content .= '<span class="act">'.$page.'</span>';
	    }

	    $content .= '</li>';
	}
	$content .= '</ul>';
	return $content;
     }
}
?>


More information about the TYPO3-project-typo3v4mvc mailing list