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.

68 lines
1.6 KiB

  1. <?php
  2. /**
  3. * PagerAction
  4. *
  5. * @copyright netmonsters.ru
  6. * @link
  7. * @package Nakon
  8. * @subpackage face
  9. * @since 04.02.2008
  10. * @version SVN$
  11. * @filesource $URL$
  12. */
  13. class Pager extends Action
  14. {
  15. public $template_dir = '.';
  16. protected $current_page = 1;
  17. protected $max_page_num;
  18. protected $num_rows;
  19. protected $limit;
  20. protected $start_offset = 0;
  21. protected $count = 0;
  22. public function __construct($count, $current_page = 1, $records_limit = 20)
  23. {
  24. parent::__construct();
  25. $this->count = $count;
  26. $this->limit = $records_limit;
  27. $this->max_page_num = ceil($this->count/$this->limit);
  28. $this->current_page = ((int)$current_page <= $this->max_page_num && (int)$current_page > 0) ? (int)$current_page : 1;
  29. $this->start_offset = $this->limit * ($this->current_page - 1);
  30. $this->num_rows = ($this->limit + $this->start_offset) <= $this->count ? ($this->limit + $this->start_offset) : $this->count;
  31. }
  32. public function startOffset()
  33. {
  34. return $this->start_offset;
  35. }
  36. public function limit()
  37. {
  38. return $this->limit;
  39. }
  40. public function setNumRows($num_rows)
  41. {
  42. $this->num_rows = $num_rows;
  43. }
  44. function init()
  45. {
  46. $this->template = "Pager";
  47. }
  48. function prepare()
  49. {
  50. $this->templater->assign('page', $this->current_page);
  51. $this->templater->assign('page_max', $this->max_page_num);
  52. $this->templater->assign('limit', $this->limit);
  53. $this->templater->assign('count', $this->count);
  54. }
  55. }
  56. ?>