ApiPagedCollection.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Opentalent\OtTemplating\Domain\Repository;
  3. /**
  4. * Represents an unserialized api response of 'PagedCollection' type
  5. *
  6. * @package Opentalent\OtTemplating\Domain\Repository
  7. */
  8. class ApiPagedCollection
  9. {
  10. private $totalItems;
  11. private $itemsPerPage;
  12. private $currentPage;
  13. private $members;
  14. /**
  15. * ApiResponse constructor.
  16. * @param int $totalItems
  17. * @param int $itemsPerPage
  18. * @param int $currentPage
  19. * @param array $members
  20. */
  21. public function __construct(
  22. int $totalItems,
  23. int $itemsPerPage,
  24. int $currentPage,
  25. array $members
  26. ) {
  27. $this->totalItems = $totalItems;
  28. $this->itemsPerPage = $itemsPerPage;
  29. $this->currentPage = $currentPage;
  30. $this->members = $members;
  31. }
  32. /**
  33. * @return int
  34. */
  35. public function getTotalItems() {
  36. return $this->totalItems;
  37. }
  38. /**
  39. * @return int
  40. */
  41. public function getItemsPerPage() {
  42. return $this->itemsPerPage;
  43. }
  44. /**
  45. * @return array
  46. */
  47. public function getMembers() {
  48. return $this->members;
  49. }
  50. /**
  51. * @return int
  52. */
  53. public function getCurrentPage() {
  54. return $this->currentPage;
  55. }
  56. /**
  57. * @return int
  58. */
  59. public function getLastPage() {
  60. $nb = intdiv($this->getTotalItems(), $this->getItemsPerPage());
  61. if ($this->getTotalItems() % $this->getItemsPerPage() != 0) {
  62. $nb += 1;
  63. }
  64. return $nb;
  65. }
  66. }