<?php
/**
*
* @author Benjamin Gillissen <hide@address.com>
*
* **************************************************************
Copyright (C) 2009 Benjamin Gillissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class pg_helper {
protected $pageid, $args;
public function __construct($pageid, $args, $pfeats=array(), $ajax=array() ){
$this->pageid = $pageid;
$this->args = $args;
foreach($pfeats as $feat => &$conf){
$func = "pfeat_$feat::implent";
if ( FALSE === call_user_func($func, $pageid, $conf) ){
errors::raise("Active Page could not implent PFeat : ".$feat, CORE_LOG_NOTICE, 'PGEN');
}
}
foreach($ajax as $k => &$cb){ ajax::RegisterFunction($cb); }
}
protected function handle_paged($bp, $count, $active=1){
if ( $bp == 0 ){
errors::raise("ByPage element coult not be set to 0, forcing 10", CORE_LOG_ERROR, 'PGEN');
$bp=10;
}
$totpage = ($count / $bp);
if ( $totpage == 0 ){ $totpage = 1; }
if ( is_float($totpage) ){ $totpage = ceil($totpage); }
if ( $active > $totpage ){ $active = $totpage; }
$o['start'] = (($active-1) * $bp);
$o['end'] = $o['start'] + $bp;
$o['count'] = langs::number($count);
$o['bp'] = langs::number($bp);
$left = $count - $o['start'];
if ( $left < $bp ){
$o['view'] = $left;
} else {
$o['view'] = $o['end'] - $o['start'];
}
unset($left);
$o['totpage'] = langs::number($totpage);
$o['curpage'] = $active;
$o['showprev'] = ( $active != 1);
$o['prevpage'] = ($active-1);
$o['shownext'] = ( $active < $totpage );
$o['nextpage'] = ($active+1);
return $o;
}
}