PHP Classes
elePHPant
Icontem

Paginator Iterator con Smarty-3.0.7

Recommend this page to a friend!

      Paginator Iterator  >  All threads  >  Paginator Iterator con Smarty-3.0.7  >  (Un) Subscribe thread alerts  
Subject:Paginator Iterator con Smarty-3.0.7
Summary:Actualización para Smarty-3.0.7
Messages:1
Author:Raul Peña Giraldo
Date:2011-03-23 02:22:12
 

  1. Paginator Iterator con Smarty-3.0.7   Reply   Report abuse  
Raul Peña Giraldo - 2011-03-23 02:22:12
Este paginador me parece excelente y lo que hay que hacer es poco para que funcione con Smarty-3.0.7

Se necesita adicionar un atributo a la clase

class Smarty_Internal_Template extends Smarty_Internal_Data {

//Atributo para Paginator Iterator
public $_paginator = array();

...

y reescribir unas lineas del plugin smarty_block_p_iterator teniendo en cuenta que Smarty-3.0.7 esta orientado a objetos

function smarty_block_p_iterator($params, $content, &$smarty, &$repeat)
{
static $flag;

if(is_null($content)) {
if(!$smarty->_paginator)
$smarty->_paginator=array();
return;
}

if(!$params['id']) {
$smarty->trigger_error("paginator: missing 'id' attribute.");
}

if(!$params['ds']) {
$smarty->trigger_error("paginator: missing 'ds' attribute.");
}

if(!$params['numrows']) {
$smarty->trigger_error("paginator: missing 'numrows' attribute.");
}

if(!array_key_exists('pageno', $params)) {
$smarty->trigger_error("paginator: missing 'pageno' attribute.");
}

if(!$flag[$params['id']])
{
$smarty->_paginator[$params['id']]['counter']=0;

$paginator=new PaginatorIterator;
$paginator->ds=$params['ds'];

if($params['rowsperpage'])
$paginator->rowsperpage=$params['rowsperpage'];

$paginator->numrows=$params['numrows'];

if($params['numlinks'])
$paginator->numlinks=$params['numlinks'];

$paginator->pageno=$params['pageno'];
$smarty->assign($params['id'], $paginator->paginate());

$smarty->getVariable($params['id'])->value['data'] = $smarty->getVariable($params['id'])->value['ds'][$smarty->_paginator[$params['id']]['counter']];

$smarty->_paginator[$params['id']]['is_alternating']=($smarty->_paginator[$params['id']]['counter']%2==0?false:true);
$flag[$params['id']]=1;
$repeat=true;
return;
}
else
$repeat=false;

$has_more_rows=$smarty->_paginator[$params['id']]['counter']<count($smarty->getVariable($params['id'])->value['ds'])-1;
if($has_more_rows)
{
$smarty->_paginator[$params['id']]['counter']++;
$smarty->getVariable($params['id'])->value['data'] = $smarty->getVariable($params['id'])->value['ds'][$smarty->_paginator[$params['id']]['counter']];
$smarty->_paginator[$params['id']]['is_alternating']=($smarty->_paginator[$params['id']]['counter']%2==0?false:true);
$repeat=true;
return;
}
else
$repeat=false;

if(!@$params['strip'])
{
$_return=$smarty->_paginator[$params['id']]['header'].
($smarty->getVariable($params['id'])->value['numrows']>0?$smarty->_paginator[$params['id']]['content']:$smarty->_paginator[$params['id']]['empty']).
$smarty->_paginator[$params['id']]['footer'];

if(!$has_more_rows)
$smarty->_paginator[$params['id']]=null;

return preg_replace('!\s+!', ' ', $_return);
}
else
{
$_return=$smarty->_paginator[$params['id']]['header'].
($smarty->getVariable($params['id'])->value['numrows']>0?$smarty->_paginator[$params['id']]['content']:$smarty->_paginator[$params['id']]['empty']).
$smarty->_paginator[$params['id']]['footer'];

if(!$has_more_rows)
$smarty->_paginator[$params['id']]=null;

return $_return;
}
}


funciona perfectamente.

saludos.