@@ -30,7 +30,10 @@ class Collection extends Base {
3030 $ itemclass ,
3131 $ itemlist =array (),
3232 $ pointer =0 ,
33- $ sortkey ;
33+ $ sortkey ,
34+ $ next_page_class ,
35+ $ next_page_callback ,
36+ $ next_page_url ;
3437
3538 /**
3639 * A Collection is an array of objects
@@ -44,6 +47,7 @@ class Collection extends Base {
4447 $ this ->service = $ service ;
4548 $ this ->debug ('Collection:service=%s, class=%s, array=%s ' ,
4649 get_class ($ service ), $ itemclass , print_r ($ arr ,TRUE ));
50+ $ this ->next_page_class = $ itemclass ;
4751 $ p = strrpos ($ itemclass , '\\' );
4852 if ($ p !== FALSE )
4953 $ this ->itemclass = substr ($ itemclass , $ p +1 );
@@ -171,6 +175,51 @@ class Collection extends Base {
171175 unset($ this ->itemlist [$ index ]);
172176 }
173177 }
178+
179+ /**
180+ * returns the Collection object for the next page of results, or
181+ * FALSE if there are no more pages
182+ *
183+ * Generally, the structure for a multi-page collection will look like
184+ * this:
185+ *
186+ * $coll = $obj->Collection();
187+ * do {
188+ * while($item = $coll->Next()) {
189+ * // do something with the item
190+ * |
191+ * } while ($coll = $coll->NextPage());
192+ *
193+ * @api
194+ * @return Collection if there are more pages of results, otherwise FALSE
195+ */
196+ public function NextPage () {
197+ if (isset ($ this ->next_page_url )) {
198+ return call_user_func (
199+ $ this ->next_page_callback ,
200+ $ this ->next_page_class ,
201+ $ this ->next_page_url );
202+ }
203+ return FALSE ;
204+ }
205+
206+ /**
207+ * for paginated collection, sets the callback function and URL for
208+ * the next page
209+ *
210+ * The callback function should have the signature:
211+ * function Whatever($class, $url, $parent)
212+ * and the `$url` should be the URL of the next page of results
213+ *
214+ * @param callable $callback the name of the function (or array of
215+ * object, function name)
216+ * @param string $url the URL of the next page of results
217+ * @return void
218+ */
219+ public function SetNextPageCallback ($ callback , $ url ) {
220+ $ this ->next_page_callback = $ callback ;
221+ $ this ->next_page_url = $ url ;
222+ }
174223
175224 /********** PRIVATE METHODS **********/
176225
0 commit comments