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.

49 lines
1.1 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. $page = (int) Env::Get('p');
  27. $this->last_page = ceil($this->count/$this->limit);
  28. $this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
  29. $this->offset = $this->limit * ($this->page - 1);
  30. }
  31. public function getOffset()
  32. {
  33. return $this->offset;
  34. }
  35. public function getLimit()
  36. {
  37. return $this->limit;
  38. }
  39. protected function getTemplate()
  40. {
  41. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
  42. return '/actions/' . $template;
  43. }
  44. }