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;
  14. public $last_page;
  15. protected $offset = 0;
  16. protected $count = 0;
  17. protected $limit;
  18. public function __construct($count, $limit = 20)
  19. {
  20. $this->count = $count;
  21. $this->limit = $limit;
  22. parent::__construct();
  23. }
  24. protected function execute()
  25. {
  26. $this->last_page = ceil($this->count / $this->limit);
  27. if (Env::Get('p') == 'last') {
  28. $page = $this->last_page;
  29. } else {
  30. $page = (int) Env::Get('p');
  31. }
  32. $this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
  33. $this->offset = $this->limit * ($this->page - 1);
  34. }
  35. public function getOffset()
  36. {
  37. return $this->offset;
  38. }
  39. public function getLimit()
  40. {
  41. return $this->limit;
  42. }
  43. protected function getTemplate()
  44. {
  45. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
  46. return '/actions/' . $template;
  47. }
  48. }