1111use Traversable ;
1212
1313
14+ class PageInfo {
15+
16+ public function __construct ()
17+ {
18+ $ this ->startIndex = 0 ;
19+ $ this ->endIndex = 0 ;
20+ }
21+
22+ public function setNextPage ($ index ){
23+ if ($ index == 0 )
24+ return ;
25+
26+ if ($ this ->endIndex < $ index ){
27+ $ this ->startIndex = $ this ->endIndex ;
28+ $ this ->endIndex = $ index ;
29+ }
30+ }
31+
32+ public function __toString ()
33+ {
34+ return "$ this ->endIndex " ;
35+ }
36+
37+ /**
38+ * @var int
39+ */
40+ public $ startIndex ;
41+
42+ /**
43+ * @var int
44+ */
45+ public $ endIndex ;
46+
47+ }
48+
49+
1450/**
1551 * Client objects collection (represents EntitySet in terms of OData)
1652 */
@@ -44,6 +80,11 @@ class ClientObjectCollection extends ClientObject implements IteratorAggregate,
4480 */
4581 protected $ pageLoaded ;
4682
83+ /**
84+ * @var PageInfo
85+ */
86+ protected $ pageInfo ;
87+
4788
4889 /**
4990 * @param ClientRuntimeContext $ctx
@@ -57,6 +98,7 @@ public function __construct(ClientRuntimeContext $ctx,ResourcePath $resourcePath
5798 $ this ->NextRequestUrl = null ;
5899 $ this ->itemTypeName = $ itemTypeName ;
59100 $ this ->pagedMode = false ;
101+ $ this ->pageInfo = new PageInfo ();
60102 $ this ->pageLoaded = new EventHandler ();
61103 }
62104
@@ -164,6 +206,7 @@ public function getItem($index)
164206 }
165207
166208 /**
209+ * Returns total items count
167210 * @return int
168211 * @throws Exception
169212 */
@@ -345,7 +388,8 @@ protected function hasNext(){
345388 public function get ()
346389 {
347390 $ this ->getContext ()->getPendingRequest ()->afterExecuteRequest (function (){
348- $ this ->pageLoaded ->triggerEvent (array (count ($ this ->data )));
391+ $ this ->pageInfo ->setNextPage (count ($ this ->data ));
392+ $ this ->pageLoaded ->triggerEvent (array ($ this ));
349393 });
350394 return parent ::get ();
351395 }
@@ -440,4 +484,8 @@ public function offsetUnset($offset): void
440484 unset($ this ->data [$ offset ]);
441485 }
442486 }
487+
488+ public function getPageInfo (){
489+ return $ this ->pageInfo ;
490+ }
443491}
0 commit comments