@@ -128,35 +128,69 @@ public function getSelf( $params = array() ) {
128
128
* @return void
129
129
*/
130
130
public function calcNextLink ( &$ response ) {
131
- if ( isset ( $ response [Fields::BUSINESS_DISCOVERY ][Fields::MEDIA ][Fields::PAGING ][Fields::CURSORS ][Params::AFTER ] ) ) { // we have another page
132
- $ config = array ( // setup config
133
- 'user_id ' => $ response [Fields::BUSINESS_DISCOVERY ][Fields::ID ],
134
- 'access_token ' => $ this ->accessToken
135
- );
131
+ if ( isset ( $ response [Fields::BUSINESS_DISCOVERY ][Fields::MEDIA ][Fields::PAGING ][Fields::CURSORS ][Params::BEFORE ] ) ) { // we have previous page
132
+ // get fields string
133
+ $ fieldsString = $ this ->getParams ();
134
+
135
+ // calculate after string with cursor
136
+ $ snippet = Fields::MEDIA . '. ' . Params::BEFORE . '( ' . $ response [Fields::BUSINESS_DISCOVERY ][Fields::MEDIA ][Fields::PAGING ][Fields::CURSORS ][Params::BEFORE ] . '){ ' ;
137
+
138
+ // update old fields with cursor
139
+ $ newFieldsParams = str_replace ( Fields::MEDIA . '{ ' , $ snippet , $ fieldsString );
136
140
137
- // create new media
138
- $ media = new Media ( $ config );
141
+ // create our media endpoint
142
+ $ endpoint = '/ ' . $ this ->userId . '/ ' ;
143
+
144
+ // create our request
145
+ $ request = new Request ( Request::METHOD_GET , $ endpoint , $ newFieldsParams , $ this ->graphVersion , $ this ->accessToken );
139
146
140
- // use params from media class
141
- $ params = $ media ->getParams ();
147
+ // set paging next to the url for the next request
148
+ $ response [Fields::PAGING ][Params::PREVIOUS ] = $ request ->getUrl ();
149
+ }
142
150
143
- // need the access token
144
- $ params ['access_token ' ] = $ this ->accessToken ;
151
+ if ( isset ( $ response [Fields::BUSINESS_DISCOVERY ][Fields::MEDIA ][Fields::PAGING ][Fields::CURSORS ][Params::AFTER ] ) ) { // we have another page
152
+ // get fields string
153
+ $ fieldsString = $ this ->getParams ();
145
154
146
- // set the after cursor
147
- $ params [Params::AFTER ] = $ response [Fields::BUSINESS_DISCOVERY ][Fields::MEDIA ][Fields::PAGING ][Fields::CURSORS ][Params::AFTER ];
155
+ // calculate after string with cursor
156
+ $ snippet = Fields::MEDIA . '. ' . Params::AFTER . '( ' . $ response [Fields::BUSINESS_DISCOVERY ][Fields::MEDIA ][Fields::PAGING ][Fields::CURSORS ][Params::AFTER ] . '){ ' ;
157
+
158
+ // update old fields with cursor
159
+ $ newFieldsParams = str_replace ( Fields::MEDIA . '{ ' , $ snippet , $ fieldsString );
148
160
149
161
// create our media endpoint
150
- $ endpoint = '/ ' . $ media ->userId . '/ ' . Media:: ENDPOINT ;
162
+ $ endpoint = '/ ' . $ this ->userId . '/ ' ;
151
163
152
164
// create our request
153
- $ request = new Request ( Request::METHOD_GET , $ endpoint , $ params , $ this ->graphVersion , $ this ->accessToken );
165
+ $ request = new Request ( Request::METHOD_GET , $ endpoint , $ newFieldsParams , $ this ->graphVersion , $ this ->accessToken );
154
166
155
167
// set paging next to the url for the next request
156
168
$ response [Fields::PAGING ][Params::NEXT ] = $ request ->getUrl ();
157
169
}
158
170
}
159
171
172
+ /**
173
+ * Request previous or next page data.
174
+ *
175
+ * @param string $page specific page to request.
176
+ * @return array of previous or next page data..
177
+ */
178
+ public function getMediaPage ( $ page ) {
179
+ // get the page to use
180
+ $ pageUrl = Params::NEXT == $ page ? $ this ->pagingNextLink : $ this ->pagingPreviousLink ;
181
+
182
+ // return the response from the request
183
+ $ mediaPageRequest = $ this ->sendCustomRequest ( $ pageUrl );
184
+
185
+ // calculate the next link for paging
186
+ $ this ->calcNextLink ( $ mediaPageRequest );
187
+
188
+ // set prev and next links
189
+ $ this ->setPrevNextLinks ( $ mediaPageRequest );
190
+
191
+ return $ mediaPageRequest ;
192
+ }
193
+
160
194
/**
161
195
* Get params for the request.
162
196
*
0 commit comments