@@ -37,11 +37,11 @@ class GraphCollectionRequest extends GraphRequest
3737 */
3838 protected $ pageSize ;
3939 /**
40- * The skip token to use in calling a new page of results
40+ * The next link to use in calling a new page of results
4141 *
4242 * @var string
4343 */
44- protected $ skipToken ;
44+ protected $ nextLink ;
4545 /**
4646 * True if the user has reached the end of the collection
4747 *
@@ -54,12 +54,6 @@ class GraphCollectionRequest extends GraphRequest
5454 * @var string
5555 */
5656 protected $ originalEndpoint ;
57- /**
58- * The return type that the user specified
59- *
60- * @var string
61- */
62- protected $ originalReturnType ;
6357
6458 /**
6559 * Constructs a new GraphCollectionRequest object
@@ -107,7 +101,6 @@ public function count()
107101 /* The $count query parameter for the Graph API
108102 is available on several models but not all */
109103 trigger_error ('Count unavailable for this collection ' );
110- return null ;
111104 }
112105
113106 /**
@@ -136,9 +129,9 @@ public function setPageSize($pageSize)
136129 *
137130 * @return array of objects of class $returnType
138131 */
139- public function getPage ($ prev = false )
132+ public function getPage ()
140133 {
141- $ this ->setPageCallInfo ($ prev );
134+ $ this ->setPageCallInfo ();
142135 $ response = $ this ->execute ();
143136
144137 return $ this ->processPageCallReturn ($ response );
@@ -151,31 +144,28 @@ public function getPage($prev = false)
151144 *
152145 * @return GraphCollectionRequest
153146 */
154- public function setPageCallInfo ($ prev )
147+ public function setPageCallInfo ()
155148 {
156149 // Store these to add temporary query data to request
157150 $ this ->originalReturnType = $ this ->returnType ;
158- $ this ->originalEndpoint = $ this ->endpoint ;
159151
160152 /* This allows processPageCallReturn to receive
161153 all of the response data, not just the objects */
162154 $ this ->returnType = null ;
163155
164156 if ($ this ->end ) {
165157 trigger_error ('Reached end of collection ' );
166- return null ;
167158 }
168159
169- // Build the page navigation query string
170- $ query = '$top= ' . $ this ->pageSize ;
171- if ($ this ->skipToken ) {
172- $ query .='&$skiptoken= ' . $ this ->skipToken ;
160+ if ($ this ->nextLink ) {
161+ $ baseLength = strlen ($ this ->baseUrl ) + strlen ($ this ->apiVersion );
162+ $ this ->endpoint = substr ($ this ->nextLink , $ baseLength );
163+ } else {
164+ // This is the first request to the endpoint
165+ if ($ this ->pageSize ) {
166+ $ this ->endpoint .= $ this ->getConcatenator () . '$top= ' . $ this ->pageSize ;
167+ }
173168 }
174- if ($ prev ) {
175- $ query .='&previous-page=true ' ;
176- }
177-
178- $ this ->endpoint = $ this ->endpoint . $ this ->getConcatenator () . $ query ;
179169 return $ this ;
180170 }
181171
@@ -190,11 +180,11 @@ public function setPageCallInfo($prev)
190180 */
191181 public function processPageCallReturn ($ response )
192182 {
193- $ this ->skipToken = $ response ->getSkipToken ();
183+ $ this ->nextLink = $ response ->getNextLink ();
194184
195185 /* If no skip token is returned, we have reached the end
196186 of the collection */
197- if (!$ this ->skipToken ) {
187+ if (!$ this ->nextLink ) {
198188 $ this ->end = true ;
199189 }
200190
@@ -206,23 +196,11 @@ public function processPageCallReturn($response)
206196 }
207197
208198 // Restore user-defined parameters
209- $ this ->endpoint = $ this ->originalEndpoint ;
210199 $ this ->returnType = $ this ->originalReturnType ;
211200
212201 return $ result ;
213202 }
214203
215- /**
216- * Gets the previous page of results from the collection
217- *
218- * @return array of objects of class $returnType
219- */
220- public function getPrevPage ()
221- {
222- $ this ->end = false ;
223- return $ this ->getPage (true );
224- }
225-
226204 /**
227205 * Gets whether the user has reached the end of the collection
228206 *
0 commit comments