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.

65 lines
1.5 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 ViewAction
  12. {
  13. public $page;
  14. public $last_page;
  15. //protected $num_rows;
  16. protected $offset = 0;
  17. protected $count = 0;
  18. protected $limit;
  19. public function __construct($count, $limit = 20)
  20. {
  21. $this->count = $count;
  22. $this->limit = $limit;
  23. parent::__construct();
  24. }
  25. protected function execute()
  26. {
  27. $page = (int) Env::Get('p');
  28. $this->last_page = ceil($this->count/$this->limit);
  29. $this->page = ($page <= $this->last_page && $page > 0) ? $page : 1;
  30. $this->offset = $this->limit * ($this->page - 1);
  31. //$this->num_rows = ($this->limit + $this->offset) <= $this->count ? ($this->limit + $this->offset) : $this->count;
  32. }
  33. public function getOffset()
  34. {
  35. return $this->offset;
  36. }
  37. public function getLimit()
  38. {
  39. return $this->limit;
  40. }
  41. protected function getTemplate()
  42. {
  43. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
  44. return '/actions/' . $template;
  45. }
  46. /* public function setNumRows($num_rows)
  47. {
  48. $this->num_rows = $num_rows;
  49. }
  50. */
  51. /*function prepare()
  52. {
  53. $this->templater->assign('page', $this->page);
  54. $this->templater->assign('page_max', $this->max_page_num);
  55. }*/
  56. }