Skip to content

Commit dfcb865

Browse files
committed
Merge pull request #592 from LearningLocker/tidy/statements
Tidies up statement repository.
2 parents 00e3a01 + 2fa72e1 commit dfcb865

File tree

92 files changed

+2347
-3447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2347
-3447
lines changed

app/commands/StatementMigrateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function fire() {
5555
});
5656

5757
// Uses the repository to migrate the statements.
58-
$repo = App::make('Locker\Repository\Statement\EloquentStatementRepository');
58+
$repo = App::make('Locker\Repository\Statement\EloquentVoider');
5959
$repo->updateReferences($statements_array, $lrs);
6060
$repo->voidStatements($statements_array, $lrs);
6161

app/controllers/LrsController.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

33
use \Locker\Repository\Lrs\Repository as LrsRepo;
4-
use \Locker\Repository\Statement\StatementRepository as StatementRepo;
4+
use \Locker\Repository\Statement\Repository as StatementRepo;
5+
use \Locker\Repository\Statement\EloquentIndexer as StatementIndexer;
6+
use \Locker\Repository\Statement\IndexOptions as IndexOptions;
57

68
class LrsController extends BaseController {
79

@@ -66,7 +68,7 @@ public function store() {
6668

6769
//lrs input validation
6870
$rules['title'] = 'required';
69-
$rules['description'] = '';
71+
$rules['description'] = '';
7072
$validator = \Validator::make($data, $rules);
7173
if ($validator->fails()) return \Redirect::back()->withErrors($validator);
7274

@@ -103,7 +105,7 @@ public function update($lrs_id){
103105
$data = \Input::all();
104106

105107
//lrs input validation
106-
$rules['title'] = 'required';
108+
$rules['title'] = 'required';
107109
$validator = \Validator::make($data, $rules);
108110
if ($validator->fails()) {
109111
return \Redirect::back()->withErrors($validator);
@@ -123,7 +125,7 @@ public function update($lrs_id){
123125

124126
/**
125127
* Display the specified resource.
126-
* This is a temp hack until the single page app for
128+
* This is a temp hack until the single page app for
127129
* analytics is ready. v1.0 stable.
128130
* @param String $lrs_id
129131
* @return View
@@ -187,10 +189,13 @@ public function destroy($lrs_id){
187189
* @return View
188190
*/
189191
public function statements($lrs_id){
190-
$statements = $this->statement->index($lrs_id, [], [
192+
$statements = (new StatementIndexer)->index(new IndexOptions([
193+
'lrs_id' => $lrs_id,
191194
'ascending' => false,
192-
'limit' => $this->statement->count($lrs_id)
193-
])->paginate(15);
195+
'limit' => $this->statement->count([
196+
'lrs_id' => $lrs_id
197+
])
198+
]))->paginate(15);
194199

195200
return View::make('partials.statements.list', array_merge($this->getLrs($lrs_id), [
196201
'statements' => $statements,
@@ -240,7 +245,7 @@ public function editCredentials( $lrs_id ){
240245
$message_type = 'error';
241246
$message = trans('update_key_error');
242247
}
243-
248+
244249
return Redirect::back()->with($message_type, $message);
245250
}
246251

@@ -251,7 +256,7 @@ public function editCredentials( $lrs_id ){
251256
*/
252257
public function users($lrs_id) {
253258
$opts = $this->getLrs($lrs_id);
254-
return View::make('partials.users.list', array_merge($opts, [
259+
return View::make('partials.users.list', array_merge($opts, [
255260
'users' => $opts['lrs']->users,
256261
'user_nav' => true
257262
]));
@@ -260,7 +265,7 @@ public function users($lrs_id) {
260265

261266
public function inviteUsersForm($lrs_id) {
262267
$opts = $this->getLrs($lrs_id);
263-
return View::make('partials.lrs.invite', array_merge($opts, [
268+
return View::make('partials.lrs.invite', array_merge($opts, [
264269
'users' => $opts['lrs']->users,
265270
'user_nav' => true
266271
]));

app/controllers/SiteController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Locker\Repository\Site\SiteRepository as SiteRepo;
44
use Locker\Repository\Lrs\Repository as LrsRepo;
5-
use Locker\Repository\Statement\StatementRepository as StatementRepo;
5+
use Locker\Repository\Statement\Repository as StatementRepo;
66
use Locker\Repository\User\UserRepository as UserRepo;
77

88
class SiteController extends BaseController {
@@ -20,7 +20,7 @@ public function __construct(SiteRepo $site, LrsRepo $lrs, UserRepo $user, Statem
2020

2121
$this->beforeFilter('auth');
2222
$this->beforeFilter('auth.super', array('except' => array('inviteUsers')));
23-
$this->beforeFilter('csrf', array('only' => array('update', 'verifyUser', 'inviteUsers')));
23+
$this->beforeFilter('csrf', array('only' => array('update', 'verifyUser', 'inviteUsers')));
2424
}
2525

2626
/**
@@ -35,7 +35,7 @@ public function index(){
3535
$admin_dashboard = new \app\locker\data\dashboards\AdminDashboard();
3636

3737
return View::make('partials.site.dashboard', [
38-
'site' => $site,
38+
'site' => $site,
3939
'list' => $list,
4040
'stats' => $admin_dashboard->getFullStats(),
4141
'graph_data' => $admin_dashboard->getGraphData()
@@ -51,7 +51,7 @@ public function index(){
5151
public function edit($id){
5252
$site = $this->site->find($id);
5353
return View::make('partials.site.edit', [
54-
'site' => $site,
54+
'site' => $site,
5555
'settings_nav' => true
5656
]);
5757
}
@@ -122,7 +122,7 @@ public function lrs(){
122122
$lrss = $this->lrs->index($opts);
123123

124124
return Response::json(array_map(function ($lrs) {
125-
$lrs->statement_total = $this->statement->count($lrs->_id);
125+
$lrs->statement_total = $this->statement->count(['lrs_id' => $lrs->_id]);
126126
return $lrs;
127127
}, $lrss));
128128
}
@@ -148,7 +148,7 @@ public function users() {
148148
*/
149149
public function inviteUsersForm() {
150150
return View::make('partials.site.invite', [
151-
'users_nav' => true,
151+
'users_nav' => true,
152152
'admin_dash' => true
153153
]);
154154
}

app/controllers/StatementController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use Locker\Repository\Statement\StatementRepository as StatementRepo;
3+
use Locker\Repository\Statement\Repository as StatementRepo;
44
use Locker\Repository\Lrs\Repository as LrsRepo;
55

66
class StatementController extends BaseController {

app/controllers/xapi/ActivityController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php namespace Controllers\xAPI;
22

33
use \Locker\Repository\Document\DocumentRepository as Document;
4-
use \Locker\Repository\Activity\ActivityRepository as Activity;
54
use Locker\Repository\Document\DocumentType as DocumentType;
65

76
class ActivityController extends DocumentController {
@@ -22,9 +21,8 @@ class ActivityController extends DocumentController {
2221
* @param Document $document
2322
* @param Activity $activity
2423
*/
25-
public function __construct(Document $document, Activity $activity){
24+
public function __construct(Document $document){
2625
parent::__construct($document);
27-
$this->activity = $activity;
2826
}
2927

3028
/**

app/controllers/xapi/BaseController.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,12 @@ public function setParameters(){
3838
* @return mixed Result of the method.
3939
*/
4040
public function selectMethod() {
41-
try {
42-
switch ($this->method) {
43-
case 'HEAD':
44-
case 'GET': return $this->get();
45-
case 'PUT': return $this->update();
46-
case 'POST': return $this->store();
47-
case 'DELETE': return $this->destroy();
48-
}
49-
} catch (\Exception $ex) {
50-
$code = method_exists($ex, 'getStatusCode') ? $ex->getStatusCode() : 400;
51-
throw new Exceptions\Exception($ex->getMessage(), $code, $ex);
41+
switch ($this->method) {
42+
case 'HEAD':
43+
case 'GET': return $this->get();
44+
case 'PUT': return $this->update();
45+
case 'POST': return $this->store();
46+
case 'DELETE': return $this->destroy();
5247
}
5348
}
5449

0 commit comments

Comments
 (0)