@@ -223,20 +223,61 @@ public function returnArray( $statements=array(), $params=array(), $debug=array(
223223
224224
225225 //replace replace &46; in keys with .
226- //see https ://github.com/LearningLocker/LearningLocker/wiki/A-few- quirks for more info
226+ //see http ://docs.learninglocker.net/docs/statements# quirks for more info
227227 if ( !empty ($ statements ) ){
228228 foreach ( $ statements as &$ s ){
229229 $ s = \app \locker \helpers \Helpers::replaceHtmlEntity ( $ s ['statement ' ] );
230230 }
231231 }
232232
233- //$array['count'] = sizeof($statements);
234233 $ array ['statements ' ] = $ statements ;
235234
236- $ array ['more ' ] = '' ;// @todo if more results available, provide link to access them
235+ //return total available statements
236+ $ array ['total ' ] = $ this ->statement ->count ( $ this ->lrs ->_id , $ this ->params );
237+
238+ //set more link. 100 is our default limit. This should be a value that admins can
239+ //set, not hardcoded.
240+ if ( isset ($ this ->params ['offset ' ]) ){
241+ if ( isset ($ this ->params ['limit ' ]) ){
242+ $ offset = $ this ->params ['offset ' ] + $ this ->params ['limit ' ];
243+ }else {
244+ $ offset = $ this ->params ['offset ' ] + 100 ;
245+ }
246+ }else {
247+ if ( isset ($ this ->params ['limit ' ]) ){
248+ $ offset = $ this ->params ['limit ' ];
249+ }else {
250+ $ offset = 100 ;
251+ }
252+ }
253+
254+ //set the more url
255+ if ( $ array ['total ' ] > $ offset ){
256+ $ url = 'http ' . (isset ($ _SERVER ['HTTPS ' ]) ? 's ' : '' ) . ':// ' . "{$ _SERVER ['HTTP_HOST ' ]}{$ _SERVER ['REQUEST_URI ' ]}" ;
257+ if ( isset ($ this ->params ) ){
258+ if ( isset ($ this ->params ['offset ' ]) && count ($ this ->params ) > 1 ){
259+ $ url = str_replace ('&offset= ' . $ this ->params ['offset ' ], "" , $ url );
260+ $ url = $ url . '&offset= ' . $ offset ;
261+ }elseif (isset ($ this ->params ['offset ' ])) {
262+ $ url = str_replace ('?offset= ' . $ this ->params ['offset ' ], "" , $ url );
263+ $ url = $ url . '?offset= ' . $ offset ;
264+ }else {
265+ $ url = $ url . '&offset= ' . $ offset ;
266+ }
267+ }else {
268+ $ url = $ url . '?offset= ' . $ offset ;
269+ }
270+ $ array ['more ' ] = $ url ;
271+ }
237272
238273 $ response = \Response::make ( $ array , 200 );
239- $ response ->headers ->set ('X-Experience-API-Consistent-Through ' , 'now ' );
274+
275+ //set consistent through data
276+ $ current_date = \DateTime::createFromFormat ('U.u ' , microtime (true ));
277+ $ current_date ->setTimezone (new \DateTimeZone (\Config::get ('app.timezone ' )));
278+ $ current_date = $ current_date ->format ('Y-m-d\TH:i:s.uP ' );
279+
280+ $ response ->headers ->set ('X-Experience-API-Consistent-Through ' , $ current_date );
240281
241282 return $ response ;
242283
0 commit comments