Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app/commands/ConvertTimestamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class ConvertTimestamp extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'timestamp:convert';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new key in the document root that is a copy of timestamp in MongoData format.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* Loop through all statements and create a new key in the document route.
* This key 'convertedTimestamp' is the same as the statement timestamp but in a
* data format the MongoDB aggregation function needs.
*
* @return string
*/
public function fire()
{
Statement::chunk(1000, function($statements){
foreach ($statements as $s){
$s->timestamp = new \MongoDate(strtotime($s->statement['timestamp']));
$s->save();
}
$this->info(count($statements) . ' converted.');
});

$this->info('All finished, hopefully!');
}


}
26 changes: 0 additions & 26 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@

'connections' => array(

'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),

'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
Expand All @@ -63,26 +57,6 @@
'prefix' => '',
),

'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),

'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'prefix' => '',
),

'mongodb' => array(
'driver' => 'mongodb',
'host' => 'localhost',
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/LrsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(Lrs $lrs, AnalyticsInterface $analytics, Statement $
*/
public function index(){
$lrs = $this->lrs->all();
return View::make('partials.lrs.list', array('lrs' => $lrs));
return View::make('partials.lrs.list', array('lrs' => $lrs, 'list' => $lrs));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(User $user){

$this->user = $user;
$this->beforeFilter('guest');
$this->beforeFilter('registation.status');
$this->beforeFilter('registration.status');

}

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

if($user){
//event hook to fire upon successful regitration
//event hook to fire upon successful registration
Event::fire('user.register', array($user));
// log in new user
Auth::attempt(array(
Expand Down
49 changes: 45 additions & 4 deletions app/controllers/xapi/StatementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,61 @@ public function returnArray( $statements=array(), $params=array(), $debug=array(


//replace replace &46; in keys with .
//see https://github.com/LearningLocker/LearningLocker/wiki/A-few-quirks for more info
//see http://docs.learninglocker.net/docs/statements#quirks for more info
if( !empty($statements) ){
foreach( $statements as &$s ){
$s = \app\locker\helpers\Helpers::replaceHtmlEntity( $s['statement'] );
}
}

//$array['count'] = sizeof($statements);
$array['statements'] = $statements;

$array['more'] = '';// @todo if more results available, provide link to access them
//return total available statements
$array['total'] = $this->statement->count( $this->lrs->_id, $this->params );

//set more link. 100 is our default limit. This should be a value that admins can
//set, not hardcoded.
if( isset($this->params['offset']) ){
if( isset($this->params['limit']) ){
$offset = $this->params['offset'] + $this->params['limit'];
}else{
$offset = $this->params['offset'] + 100;
}
}else{
if( isset($this->params['limit']) ){
$offset = $this->params['limit'];
}else{
$offset = 100;
}
}

//set the more url
if( $array['total'] > $offset ){
$url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
if( isset($this->params) ){
if( isset($this->params['offset']) && count($this->params) > 1 ){
$url = str_replace('&offset=' . $this->params['offset'], "", $url);
$url = $url . '&offset=' . $offset;
}elseif(isset($this->params['offset'])) {
$url = str_replace('?offset=' . $this->params['offset'], "", $url);
$url = $url . '?offset=' . $offset;
}else{
$url = $url . '&offset=' . $offset;
}
}else{
$url = $url . '?offset=' . $offset;
}
$array['more'] = $url;
}

$response = \Response::make( $array, 200 );
$response->headers->set('X-Experience-API-Consistent-Through', 'now');

//set consistent through data
$current_date = \DateTime::createFromFormat('U.u', microtime(true));
$current_date->setTimezone(new \DateTimeZone(\Config::get('app.timezone')));
$current_date = $current_date->format('Y-m-d\TH:i:s.uP');

$response->headers->set('X-Experience-API-Consistent-Through', $current_date);

return $response;

Expand Down
2 changes: 1 addition & 1 deletion app/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
|---------------------------------------------------------------------------
*/

Route::filter('registation.status', function( $route, $request ){
Route::filter('registration.status', function( $route, $request ){
$site = \Site::first();
if( $site ){
if( $site->registration != 'Open' ) return Redirect::to('/');
Expand Down
1 change: 1 addition & 0 deletions app/lang/en/apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'list' => 'Apps',
'create' => 'Create a new App',
'show' => 'App details',
'no_data' => 'No data available',

//API calls
'api' => array(
Expand Down
2 changes: 1 addition & 1 deletion app/lang/en/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'invite' => 'Invite users',
'email' => 'Email addresses (separate lines)',
'message' => 'Message (optional)',
'sample' => 'I would like to invite you to join this LRS.',
'sample' => 'I would like to invite you to join this Learning Record Store (LRS).',
'invited' => 'Those users have been invited.',
'failed' => 'Inviting that user failed, check the user is not already a member of the LRS and the email is valid.',
'has_invited' => 'has invited you to join',
Expand Down
6 changes: 3 additions & 3 deletions app/locker/data/analytics/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ private function setMongoDate( $date ){
**/
private function buildDates($since='', $until=''){
if( $since != '' && $until != ''){
$dates = array( 'created_at' => array( '$gte' => $since, '$lte' => $until));
$dates = array( 'timestamp' => array( '$gte' => $since, '$lte' => $until));
}elseif( $since != '' ){
$dates = array( 'created_at' => array( '$gte' => $since ));
$dates = array( 'timestamp' => array( '$gte' => $since ));
}elseif( $until != '' ){
$dates = array( 'created_at' => array( '$lte' => $until));
$dates = array( 'timestamp' => array( '$lte' => $until));
}else{
$dates = array();
}
Expand Down
4 changes: 2 additions & 2 deletions app/locker/data/dashboards/AdminDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function userCount(){
private function statementDays(){
$first_day = \DB::collection('statements')->first();
if( $first_day ){
$datetime1 = date_create( gmdate("Y-m-d", $first_day['created_at']->sec) );
$datetime1 = date_create( gmdate("Y-m-d", $first_day['timestamp']->sec) );
$datetime2 = date_create( gmdate("Y-m-d", time()) );
$interval = date_diff($datetime1, $datetime2);
$days = $interval->days;
Expand Down Expand Up @@ -139,7 +139,7 @@ public function learnerAvgCount(){
**/
public function getStatementNumbersByDate(){

$set_id = array( '$dayOfYear' => '$created_at' );
$set_id = array( '$dayOfYear' => '$timestamp' );

$statements = $this->db->statements->aggregate(
array('$group' => array(
Expand Down
2 changes: 1 addition & 1 deletion app/locker/data/dashboards/LrsDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function learnerAvgCount(){
**/
public function getStatementNumbersByDate(){

$set_id = array( '$dayOfYear' => '$created_at' );
$set_id = array( '$dayOfYear' => '$timestamp' );

$statements = $this->db->statements->aggregate(
array('$match' => $this->getMatch( $this->lrs )),
Expand Down
28 changes: 13 additions & 15 deletions app/locker/repository/Activity/EloquentActivityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,26 @@ public function __construct( Activity $activity ){

}

/**
* This is a temp solution, we need something better depending
* on authority to update activity stored.
*
**/
public function saveActivity( $activity_id, $activity_def ){

$exists = \DB::table('activities')->find( $activity_id );

//if the object activity exists, return details on record.
//if the object activity exists, remove and update with recent
if( $exists ){

//update record
\DB::table('activities')
->where('_id', $activity_id)
->update(array('definition' => $activity_def));

}else{

//save new record
\DB::table('activities')->insert(
array('_id' => $activity_id,
'definition' => $activity_def)
);

\DB::table('activities')->where('_id', $activity_id)->delete();
}

//save record
\DB::table('activities')->insert(
array('_id' => $activity_id,
'definition' => $activity_def)
);

}

public function getActivity( $activity_id ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function setQuerySince($query, $since ){

if( !empty($since) ){
$since_carbon = new Carbon($since);
$query = $query->where('created_at', '>', $since_carbon);
$query = $query->where('timestamp', '>', $since_carbon);
}

return $query;
Expand Down
2 changes: 1 addition & 1 deletion app/locker/repository/Query/EloquentQueryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function timedGrouping( $lrs, $filters, $interval, $type='time' ){

if( $type == 'time' ){
if( !$interval ) $interval = '$dayOfYear';
$set_id = array( $interval => '$created_at' );
$set_id = array( $interval => '$timestamp' );
}else{
switch($type){
case 'user':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public function create( $statements, $lrs, $attachments='' ){
$new_statement->lrs = array( '_id' => $lrs->_id, 'name' => $lrs->title );
$new_statement->statement = $vs;

//now add our MongoData timestamp (based on statement timestamp) to use with Mongo Aggregation Function
$new_statement->timestamp = new \MongoDate(strtotime($vs['timestamp']));

if( $new_statement->save() ){
$saved_ids[] = $new_statement->statement['id'];
} else {
Expand Down
3 changes: 1 addition & 2 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@
$error = array(
'error' => true,
'message' => $exception->getMessage(),
'code' => $exception->getStatusCode(),
'trace' => $exception->getTrace()
'code' => $exception->getStatusCode()
);

return Response::json( $error, $exception->getStatusCode());
Expand Down
1 change: 1 addition & 0 deletions app/start/artisan.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
|
*/

Artisan::add(new ConvertTimestamp);