Files
majestic/app/PagerAction.php
pzinovkin d0630c4240 ViewAction functional merged to Action, Model::inset now returns last insert id if returned or affected rows count, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@125 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
2010-03-14 12:12:17 +00:00

50 lines
1.1 KiB
PHP

<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage app
* @since 2010-03-07
* @version SVN: $Id$
* @filesource $URL$
*/
class PagerAction extends Action
{
public $page;
public $last_page;
protected $offset = 0;
protected $count = 0;
protected $limit;
public function __construct($count, $limit = 20)
{
$this->count = $count;
$this->limit = $limit;
parent::__construct();
}
protected function execute()
{
$page = (int) Env::Get('p');
$this->last_page = ceil($this->count/$this->limit);
$this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
$this->offset = $this->limit * ($this->page - 1);
}
public function getOffset()
{
return $this->offset;
}
public function getLimit()
{
return $this->limit;
}
protected function getTemplate()
{
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
return '/actions/' . $template;
}
}