2014-06-02 18:58:49 +04:00
|
|
|
<?php namespace Majestic\App;
|
2010-03-13 23:33:46 +00:00
|
|
|
/**
|
|
|
|
* @copyright NetMonsters <team@netmonsters.ru>
|
|
|
|
* @link http://netmonsters.ru
|
|
|
|
* @package Majestic
|
|
|
|
* @subpackage app
|
|
|
|
* @since 2010-03-07
|
|
|
|
*/
|
|
|
|
|
2010-03-14 12:12:17 +00:00
|
|
|
class PagerAction extends Action
|
2010-03-13 23:33:46 +00:00
|
|
|
{
|
2011-10-13 14:55:06 +04:00
|
|
|
public $page = 1;
|
|
|
|
|
2010-05-24 13:54:50 +00:00
|
|
|
public $last_page = 1;
|
2011-10-13 14:55:06 +04:00
|
|
|
|
2010-03-13 23:33:46 +00:00
|
|
|
protected $offset = 0;
|
2011-10-13 14:55:06 +04:00
|
|
|
|
2010-03-13 23:33:46 +00:00
|
|
|
protected $limit;
|
|
|
|
|
2010-05-24 13:54:50 +00:00
|
|
|
public function __construct($limit = 20)
|
2010-03-13 23:33:46 +00:00
|
|
|
{
|
|
|
|
$this->limit = $limit;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2010-05-24 13:54:50 +00:00
|
|
|
protected function execute() {}
|
|
|
|
|
|
|
|
public function setCount($count)
|
2010-03-13 23:33:46 +00:00
|
|
|
{
|
2010-05-24 13:54:50 +00:00
|
|
|
$this->last_page = ceil($count / $this->limit);
|
2010-03-14 16:12:52 +00:00
|
|
|
if (Env::Get('p') == 'last') {
|
|
|
|
$page = $this->last_page;
|
|
|
|
} else {
|
|
|
|
$page = (int) Env::Get('p');
|
|
|
|
}
|
2010-03-13 23:33:46 +00:00
|
|
|
$this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
|
|
|
|
$this->offset = $this->limit * ($this->page - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOffset()
|
|
|
|
{
|
2010-05-24 13:54:50 +00:00
|
|
|
return (int) $this->offset;
|
2010-03-13 23:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getLimit()
|
|
|
|
{
|
2010-05-24 13:54:50 +00:00
|
|
|
return (int) $this->limit;
|
2010-03-13 23:33:46 +00:00
|
|
|
}
|
2011-10-13 14:55:06 +04:00
|
|
|
|
2010-03-13 23:33:46 +00:00
|
|
|
protected function getTemplate()
|
|
|
|
{
|
2011-10-13 14:55:06 +04:00
|
|
|
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6 /*strlen('Action')*/);
|
2010-03-13 23:33:46 +00:00
|
|
|
return '/actions/' . $template;
|
|
|
|
}
|
|
|
|
}
|