Browse Source

add pager class

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@59 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
ejikharev 16 years ago
parent
commit
f20959e366
  1. 68
      classes/Pager.class.php

68
classes/Pager.class.php

@ -0,0 +1,68 @@
<?php
/**
* PagerAction
*
* @copyright
* @link
* @package Nakon
* @subpackage face
* @since 04.02.2008
* @version SVN$
* @filesource $URL$
*/
class Pager extends Action
{
public $template_dir = '.';
protected $current_page = 1;
protected $max_page_num;
protected $num_rows;
protected $limit;
protected $start_offset = 0;
protected $count = 0;
public function __construct($count, $current_page = 1, $records_limit = 20)
{
parent::__construct();
$this->count = $count;
$this->limit = $records_limit;
$this->max_page_num = ceil($this->count/$this->limit);
$this->current_page = ((int)$current_page <= $this->max_page_num && (int)$current_page > 0) ? (int)$current_page : 1;
$this->start_offset = $this->limit * ($this->current_page - 1);
$this->num_rows = ($this->limit + $this->start_offset) <= $this->count ? ($this->limit + $this->start_offset) : $this->count;
}
public function startOffset()
{
return $this->start_offset;
}
public function limit()
{
return $this->limit;
}
public function setNumRows($num_rows)
{
$this->num_rows = $num_rows;
}
function init()
{
$this->template = "Pager";
}
function prepare()
{
$this->templater->assign('page', $this->current_page);
$this->templater->assign('page_max', $this->max_page_num);
$this->templater->assign('limit', $this->limit);
$this->templater->assign('count', $this->count);
}
}
?>
Loading…
Cancel
Save