ArrayAdapter.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ yTnQ2z0Nsi/n2uT0dpFNhSpbTIhz5Lmn+TS+zwwNebU=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * array pagination adapter
  14. */
  15. namespace Cube\Paginator\Adapter;
  16. class ArrayAdapter implements AdapterInterface
  17. {
  18. /**
  19. *
  20. * data to paginate
  21. *
  22. * @var array
  23. */
  24. protected $_data = null;
  25. /**
  26. *
  27. * number of array rows
  28. *
  29. * @var integer
  30. */
  31. protected $_count = null;
  32. /**
  33. *
  34. * class constructor
  35. *
  36. * @param array $data the array to be paginated
  37. */
  38. public function __construct(array $data)
  39. {
  40. $this->_data = $data;
  41. $this->_count = count($this->_data);
  42. }
  43. /**
  44. *
  45. * returns an array of items for the selected page
  46. *
  47. * @param integer $offset page offset
  48. * @param integer $itemCountPerPage number of items per page
  49. * @return array
  50. */
  51. public function getItems($offset, $itemCountPerPage)
  52. {
  53. return array_slice($this->_data, $offset, $itemCountPerPage);
  54. }
  55. /**
  56. *
  57. * return the number of array rows
  58. *
  59. * @return integer
  60. */
  61. public function count()
  62. {
  63. return $this->_count;
  64. }
  65. }