BraintreePaginatedCollection

Braintree PaginatedCollection PaginatedCollection is a container object for paginated data.

Defined (1)

The class is defined in the following location(s).

/includes/lib/Braintree/lib/Braintree/PaginatedCollection.php  
  1. class PaginatedCollection implements Iterator 
  2. private $_pager; 
  3. private $_pageSize; 
  4. private $_currentPage; 
  5. private $_index; 
  6. private $_totalItems; 
  7. private $_items; 
  8.  
  9. /** 
  10. * set up the paginated collection 
  11. * expects an array of an object and method to call on it 
  12. * @param array $pager 
  13. */ 
  14. public function __construct($pager) 
  15. $this->_pager = $pager; 
  16. $this->_pageSize = 0; 
  17. $this->_currentPage = 0; 
  18. $this->_totalItems = 0; 
  19. $this->_index = 0; 
  20.  
  21. /** 
  22. * returns the current item when iterating with foreach 
  23. */ 
  24. public function current() 
  25. return $this->_items[($this->_index % $this->_pageSize)]; 
  26.  
  27. public function key() 
  28. return null; 
  29.  
  30. /** 
  31. * advances to the next item in the collection when iterating with foreach 
  32. */ 
  33. public function next() 
  34. ++$this->_index; 
  35.  
  36. /** 
  37. * rewinds the collection to the first item when iterating with foreach 
  38. */ 
  39. public function rewind() 
  40. $this->_index = 0; 
  41. $this->_currentPage = 0; 
  42. $this->_pageSize = 0; 
  43. $this->_totalItems = 0; 
  44. $this->_items = []; 
  45.  
  46. /** 
  47. * returns whether the current item is valid when iterating with foreach 
  48. */ 
  49. public function valid() 
  50. if ($this->_currentPage == 0 || $this->_index % $this->_pageSize == 0) 
  51. $this->_getNextPage(); 
  52.  
  53. return $this->_index < $this->_totalItems; 
  54.  
  55. private function _getNextPage() 
  56. $this->_currentPage++; 
  57. $object = $this->_pager['object']; 
  58. $method = $this->_pager['method']; 
  59. $result = call_user_func( 
  60. [$object, $method],  
  61. $this->_currentPage 
  62. ); 
  63.  
  64. $this->_totalItems= $result->getTotalItems(); 
  65. $this->_pageSize = $result->getPageSize(); 
  66. $this->_items = $result->getCurrentPage();