Mongo.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @see Zend_Paginator_Adapter_Interface
  4. */
  5. require_once 'Zend/Paginator/Adapter/Interface.php';
  6. /**
  7. * @category Thinkopen
  8. * @package Mooses_Paginator
  9. * @copyright Thinkopen s.r.l.
  10. * @license New BSD License
  11. * @author Stefan Heckler
  12. */
  13. class Mooses_Mongodb_Paginator_Adapter_Mongo implements Zend_Paginator_Adapter_Interface
  14. {
  15. /**
  16. * Cursor
  17. *
  18. * @var Mooses_Mongodb_Mongo_Iterator_Cursor
  19. */
  20. protected $_cursor = null;
  21. /**
  22. * Constructor.
  23. *
  24. * @param Mooses_Mongodb_Mongo_Iterator_Cursor $cursor
  25. */
  26. public function __construct(Mooses_Mongodb_Mongo_Iterator_Cursor $cursor)
  27. {
  28. $this->_cursor = $cursor;
  29. }
  30. /**
  31. * Returns an cursor limited to items for a page.
  32. *
  33. * @param integer $offset Page offset
  34. * @param integer $itemCountPerPage Number of items per page
  35. * @return Mooses_Mongodb_Mongo_Iterator_Cursor
  36. */
  37. public function getItems($offset, $itemCountPerPage)
  38. {
  39. $cursor = $this->_cursor->skip($offset)->limit($itemCountPerPage);
  40. return $cursor;
  41. }
  42. /**
  43. * Returns the total number of rows in the cursor.
  44. *
  45. * @return integer
  46. */
  47. public function count()
  48. {
  49. return $this->_cursor->count();
  50. }
  51. }