Skip to content

Commit 9612b6d

Browse files
committed
Merge pull request #259 from LearningLocker/develop
Convert timestamp
2 parents a6c576f + d36f517 commit 9612b6d

17 files changed

Lines changed: 133 additions & 60 deletions

app/commands/ConvertTimestamp.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
use Illuminate\Console\Command;
4+
use Symfony\Component\Console\Input\InputOption;
5+
use Symfony\Component\Console\Input\InputArgument;
6+
7+
class ConvertTimestamp extends Command {
8+
9+
/**
10+
* The console command name.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'timestamp:convert';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Create a new key in the document root that is a copy of timestamp in MongoData format.';
22+
23+
/**
24+
* Create a new command instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct()
29+
{
30+
parent::__construct();
31+
}
32+
33+
/**
34+
* Execute the console command.
35+
*
36+
* Loop through all statements and create a new key in the document route.
37+
* This key 'convertedTimestamp' is the same as the statement timestamp but in a
38+
* data format the MongoDB aggregation function needs.
39+
*
40+
* @return string
41+
*/
42+
public function fire()
43+
{
44+
Statement::chunk(1000, function($statements){
45+
foreach ($statements as $s){
46+
$s->timestamp = new \MongoDate(strtotime($s->statement['timestamp']));
47+
$s->save();
48+
}
49+
$this->info(count($statements) . ' converted.');
50+
});
51+
52+
$this->info('All finished, hopefully!');
53+
}
54+
55+
56+
}

app/config/database.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646

4747
'connections' => array(
4848

49-
'sqlite' => array(
50-
'driver' => 'sqlite',
51-
'database' => __DIR__.'/../database/production.sqlite',
52-
'prefix' => '',
53-
),
54-
5549
'mysql' => array(
5650
'driver' => 'mysql',
5751
'host' => 'localhost',
@@ -63,26 +57,6 @@
6357
'prefix' => '',
6458
),
6559

66-
'pgsql' => array(
67-
'driver' => 'pgsql',
68-
'host' => 'localhost',
69-
'database' => 'database',
70-
'username' => 'root',
71-
'password' => '',
72-
'charset' => 'utf8',
73-
'prefix' => '',
74-
'schema' => 'public',
75-
),
76-
77-
'sqlsrv' => array(
78-
'driver' => 'sqlsrv',
79-
'host' => 'localhost',
80-
'database' => 'database',
81-
'username' => 'root',
82-
'password' => '',
83-
'prefix' => '',
84-
),
85-
8660
'mongodb' => array(
8761
'driver' => 'mongodb',
8862
'host' => 'localhost',

app/controllers/LrsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(Lrs $lrs, AnalyticsInterface $analytics, Statement $
5353
*/
5454
public function index(){
5555
$lrs = $this->lrs->all();
56-
return View::make('partials.lrs.list', array('lrs' => $lrs));
56+
return View::make('partials.lrs.list', array('lrs' => $lrs, 'list' => $lrs));
5757
}
5858

5959
/**

app/controllers/RegisterController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(User $user){
1818

1919
$this->user = $user;
2020
$this->beforeFilter('guest');
21-
$this->beforeFilter('registation.status');
21+
$this->beforeFilter('registration.status');
2222

2323
}
2424

@@ -47,7 +47,7 @@ public function store(){
4747
$user = $this->user->create(Input::all());
4848

4949
if($user){
50-
//event hook to fire upon successful regitration
50+
//event hook to fire upon successful registration
5151
Event::fire('user.register', array($user));
5252
// log in new user
5353
Auth::attempt(array(

app/controllers/xapi/StatementController.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
|---------------------------------------------------------------------------
242242
*/
243243

244-
Route::filter('registation.status', function( $route, $request ){
244+
Route::filter('registration.status', function( $route, $request ){
245245
$site = \Site::first();
246246
if( $site ){
247247
if( $site->registration != 'Open' ) return Redirect::to('/');

app/lang/en/apps.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'list' => 'Apps',
1111
'create' => 'Create a new App',
1212
'show' => 'App details',
13+
'no_data' => 'No data available',
1314

1415
//API calls
1516
'api' => array(

app/lang/en/users.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'invite' => 'Invite users',
1414
'email' => 'Email addresses (separate lines)',
1515
'message' => 'Message (optional)',
16-
'sample' => 'I would like to invite you to join this LRS.',
16+
'sample' => 'I would like to invite you to join this Learning Record Store (LRS).',
1717
'invited' => 'Those users have been invited.',
1818
'failed' => 'Inviting that user failed, check the user is not already a member of the LRS and the email is valid.',
1919
'has_invited' => 'has invited you to join',

app/locker/data/analytics/Analytics.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ private function setMongoDate( $date ){
266266
**/
267267
private function buildDates($since='', $until=''){
268268
if( $since != '' && $until != ''){
269-
$dates = array( 'created_at' => array( '$gte' => $since, '$lte' => $until));
269+
$dates = array( 'timestamp' => array( '$gte' => $since, '$lte' => $until));
270270
}elseif( $since != '' ){
271-
$dates = array( 'created_at' => array( '$gte' => $since ));
271+
$dates = array( 'timestamp' => array( '$gte' => $since ));
272272
}elseif( $until != '' ){
273-
$dates = array( 'created_at' => array( '$lte' => $until));
273+
$dates = array( 'timestamp' => array( '$lte' => $until));
274274
}else{
275275
$dates = array();
276276
}

app/locker/data/dashboards/AdminDashboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function userCount(){
7979
private function statementDays(){
8080
$first_day = \DB::collection('statements')->first();
8181
if( $first_day ){
82-
$datetime1 = date_create( gmdate("Y-m-d", $first_day['created_at']->sec) );
82+
$datetime1 = date_create( gmdate("Y-m-d", $first_day['timestamp']->sec) );
8383
$datetime2 = date_create( gmdate("Y-m-d", time()) );
8484
$interval = date_diff($datetime1, $datetime2);
8585
$days = $interval->days;
@@ -139,7 +139,7 @@ public function learnerAvgCount(){
139139
**/
140140
public function getStatementNumbersByDate(){
141141

142-
$set_id = array( '$dayOfYear' => '$created_at' );
142+
$set_id = array( '$dayOfYear' => '$timestamp' );
143143

144144
$statements = $this->db->statements->aggregate(
145145
array('$group' => array(

0 commit comments

Comments
 (0)