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.

53 lines
1.2 KiB

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