PaginationPage.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Grav\Plugin\Pagination;
  3. use Grav\Common\Grav;
  4. class PaginationPage
  5. {
  6. /**
  7. * @var Grav
  8. */
  9. protected $grav;
  10. /**
  11. * @var int
  12. */
  13. public $number;
  14. /**
  15. * @var string
  16. */
  17. public $url;
  18. /**
  19. * @var int
  20. */
  21. protected $delta=0;
  22. /**
  23. * Constructor
  24. *
  25. * @param int $number
  26. * @param string $url
  27. */
  28. public function __construct($number, $url)
  29. {
  30. $this->grav = Grav::instance();
  31. $this->number = $number;
  32. $this->url = $url;
  33. $this->delta = $this->grav['config']->get('plugins.pagination.delta');
  34. }
  35. /**
  36. * Returns true if the page is the current one.
  37. *
  38. * @return bool
  39. */
  40. public function isCurrent()
  41. {
  42. if ($this->grav['uri']->currentPage() == $this->number) {
  43. return true;
  44. }
  45. return false;
  46. }
  47. /**
  48. * Returns true if the page is within a configurable delta of the current one
  49. *
  50. * @return bool
  51. */
  52. public function isInDelta()
  53. {
  54. if (!$this->delta) {
  55. return true;
  56. }
  57. return abs($this->grav['uri']->currentPage() - $this->number) < $this->delta;
  58. }
  59. /**
  60. * Returns true is this page is the last/first one at the border of the delta range
  61. * (Used to display a "gap" li element ...)
  62. *
  63. * @return bool
  64. */
  65. public function isDeltaBorder()
  66. {
  67. if (!$this->delta) {
  68. return false;
  69. }
  70. return abs($this->grav['uri']->currentPage() - $this->number) == $this->delta;
  71. }
  72. }