You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

11 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. <?php namespace Majestic\App;
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage app
  7. * @since 2010-03-07
  8. */
  9. class PagerAction extends Action
  10. {
  11. public $page = 1;
  12. public $last_page = 1;
  13. protected $offset = 0;
  14. protected $limit;
  15. public function __construct($limit = 20)
  16. {
  17. $this->limit = $limit;
  18. parent::__construct();
  19. }
  20. protected function execute() {}
  21. public function setCount($count)
  22. {
  23. $this->last_page = ceil($count / $this->limit);
  24. if (Env::Get('p') == 'last') {
  25. $page = $this->last_page;
  26. } else {
  27. $page = (int) Env::Get('p');
  28. }
  29. $this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
  30. $this->offset = $this->limit * ($this->page - 1);
  31. }
  32. public function getOffset()
  33. {
  34. return (int) $this->offset;
  35. }
  36. public function getLimit()
  37. {
  38. return (int) $this->limit;
  39. }
  40. protected function getTemplate()
  41. {
  42. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6 /*strlen('Action')*/);
  43. return '/actions/' . $template;
  44. }
  45. }