Skip to content

Commit 1a38c3c

Browse files
committed
Merges ubc branch.
2 parents 6610b11 + a5deeba commit 1a38c3c

29 files changed

+339
-231
lines changed

app/controllers/ClientController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ public function edit($lrs_id, $id) {
5151
return View::make('partials.client.edit', [
5252
'client' => $client,
5353
'lrs' => $lrs,
54-
'list' => $lrs_list
54+
'list' => $lrs_list,
55+
'scopes' => [
56+
'all',
57+
'all/read',
58+
'statements/write',
59+
'statements/read',
60+
'statements/read/mine',
61+
'state',
62+
'profile',
63+
],
5564
]);
5665
}
5766

@@ -84,6 +93,7 @@ public function create($lrs_id) {
8493
*/
8594
public function update($lrs_id, $id){
8695
$data = Input::all();
96+
$data['scopes'] = array_values(isset($data['scopes']) ? $data['scopes'] : []);
8797
$authority = [
8898
'name' => $data['name'],
8999
];

app/controllers/api/Base.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Base extends Controller {
2020
*/
2121
public function __construct() {
2222
$this->lrs = Helpers::getLrsFromAuth();
23+
list($username, $password) = Helpers::getUserPassFromAuth();
24+
$this->client = Helpers::getClient($username, $password);
2325
}
2426

2527
/**
@@ -28,7 +30,9 @@ public function __construct() {
2830
*/
2931
protected function getOptions() {
3032
return [
31-
'lrs_id' => $this->lrs->_id
33+
'lrs_id' => $this->lrs->_id,
34+
'scopes' => $this->client->scopes,
35+
'client' => $this->client
3236
];
3337
}
3438

app/controllers/xapi/ActivityController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function full() {
3434
if ($result = $this->checkVersion()) return $result;
3535

3636
$documents = $this->document->all(
37-
$this->lrs->_id,
37+
$this->getOptions(),
3838
$this->document_type,
3939
$this->getIndexData([
4040
'since' => ['string', 'timestamp']

app/controllers/xapi/AgentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function search() {
2626

2727
$agent = (array) $this->getIndexData()[key($this->required)];
2828
$agents = $this->document->all(
29-
$this->lrs->_id,
29+
$this->getOptions(),
3030
$this->document_type,
3131
$this->getIndexData([
3232
'since' => ['string', 'timestamp']

app/controllers/xapi/DocumentController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function index() {
4646

4747
// Gets all documents.
4848
$documents = $this->document->all(
49-
$this->lrs->_id,
49+
$this->getOptions(),
5050
$this->document_type,
5151
$this->getIndexData([
5252
'since' => ['string', 'timestamp']
@@ -89,7 +89,7 @@ public function store() {
8989

9090
// Stores the document.
9191
$document = $this->document->store(
92-
$this->lrs->_id,
92+
$this->getOptions(),
9393
$this->document_type,
9494
$data,
9595
$this->getUpdatedValue(),
@@ -139,7 +139,7 @@ public function destroy(){
139139
protected function completeDelete($data = null, $singleDelete = false) {
140140
// Attempts to delete the document.
141141
$success = $this->document->delete(
142-
$this->lrs->_id,
142+
$this->getOptions(),
143143
$this->document_type,
144144
$data ?: $this->getShowData(),
145145
$singleDelete
@@ -218,7 +218,7 @@ private function checkFormContentType($contentType = '') {
218218
* @return Response
219219
*/
220220
public function documentResponse($data) {
221-
$document = $this->document->find($this->lrs->_id, $this->document_type, $data);
221+
$document = $this->document->find($this->getOptions(), $this->document_type, $data);
222222

223223
if (!$document) {
224224
throw new Exceptions\NotFound($data[$this->identifier], $this->document_type);

app/controllers/xapi/StatementController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function get() {
6060
public function update() {
6161
// Runs filters.
6262
if ($result = $this->checkVersion()) return $result;
63-
return $this->store_controller->update($this->lrs->_id);
63+
return $this->store_controller->update($this->getOptions());
6464
}
6565

6666
/**
@@ -70,15 +70,15 @@ public function update() {
7070
public function store() {
7171
// Runs filters.
7272
if ($result = $this->checkVersion()) return $result;
73-
return $this->store_controller->store($this->lrs->_id);
73+
return $this->store_controller->store($this->getOptions());
7474
}
7575

7676
/**
7777
* Gets an array of statements.
7878
* @return Response
7979
*/
8080
public function index() {
81-
return $this->index_controller->index($this->lrs->_id);
81+
return $this->index_controller->index($this->getOptions());
8282
}
8383

8484
/**
@@ -91,10 +91,9 @@ public function show($id, $voided = false) {
9191
// Runs filters.
9292
if ($result = $this->checkVersion()) return $result;
9393

94-
$statement = $this->statements->show($id, [
95-
'lrs_id' => $this->lrs->_id,
94+
$statement = $this->statements->show($id, array_merge([
9695
'voided' => $voided
97-
]);
96+
], $this->getOptions()));
9897

9998
return \Response::json(Helpers::replaceHtmlEntity($statement), 200);
10099
}

app/controllers/xapi/StatementIndexController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public function __construct(StatementRepo $statement_repo) {
2121
/**
2222
* Gets an array of statements.
2323
* https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#723-getstatements
24-
* @param String $lrs_id
24+
* @param [String => mixed] $options
2525
* @return Response
2626
*/
27-
public function index($lrs_id) {
27+
public function index($options) {
2828
// Gets the acceptable languages.
2929
$langs = LockerRequest::header('Accept-Language', []);
3030
$langs = is_array($langs) ? $langs : explode(',', $langs);
@@ -43,9 +43,8 @@ public function index($lrs_id) {
4343

4444
// Gets an index of the statements with the given options.
4545
list($statements, $count, $opts) = $this->statements->index(array_merge([
46-
'lrs_id' => $lrs_id,
4746
'langs' => $langs
48-
], $params));
47+
], $params, $options));
4948

5049
// Defines the content type and body of the response.
5150
if ($opts['attachments'] === true) {

app/controllers/xapi/StatementStoreController.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,24 @@ private function getParts() {
5555

5656
/**
5757
* Stores (POSTs) a newly created statement in storage.
58-
* @param String $lrs_id
58+
* @param [String => mixed] $options
5959
* @return Response
6060
*/
61-
public function store($lrs_id) {
61+
public function store($options) {
6262
if (LockerRequest::hasParam(StatementController::STATEMENT_ID)) {
6363
throw new Exceptions\Exception('Statement ID parameter is invalid.');
6464
}
6565

66-
return IlluminateResponse::json($this->createStatements($lrs_id), 200, $this->getCORSHeaders());
66+
return IlluminateResponse::json($this->createStatements($options), 200, $this->getCORSHeaders());
6767
}
6868

6969
/**
7070
* Updates (PUTs) Statement with the given id.
71-
* @param String $lrs_id
71+
* @param [String => mixed] $options
7272
* @return Response
7373
*/
74-
public function update($lrs_id) {
75-
$this->createStatements($lrs_id, function ($statements) {
74+
public function update($options) {
75+
$this->createStatements($options, function ($statements) {
7676
$statement_id = \LockerRequest::getParam(StatementController::STATEMENT_ID);
7777

7878
// Returns a error if identifier is not present.
@@ -90,11 +90,11 @@ public function update($lrs_id) {
9090

9191
/**
9292
* Creates statements from the content of the request.
93-
* @param String $lrs_id
93+
* @param [String => mixed] $options
9494
* @param Callable|null $modifier A function that modifies the statements before storing them.
9595
* @return AssocArray Result of storing the statements.
9696
*/
97-
private function createStatements($lrs_id, Callable $modifier = null) {
97+
private function createStatements($options, Callable $modifier = null) {
9898
Helpers::validateAtom(new XApiImt(explode(';', LockerRequest::header('Content-Type'))[0]));
9999

100100
// Gets parts of the request.
@@ -123,21 +123,13 @@ private function createStatements($lrs_id, Callable $modifier = null) {
123123
return $this->statements->store(
124124
$statements,
125125
is_array($parts['attachments']) ? $parts['attachments'] : [],
126-
[
127-
'lrs_id' => $lrs_id,
128-
'authority' => $this->getAuthority()
129-
]
126+
array_merge([
127+
'authority' => $this->getAuthority($options['client'])
128+
], $options)
130129
);
131130
}
132131

133-
private function getAuthority() {
134-
list($username, $password) = Helpers::getUserPassFromAuth();
135-
$client = Helpers::getClient($username, $password);
136-
137-
if ($client === null) {
138-
throw new Exceptions\Exception('No authority.');
139-
}
140-
132+
private function getAuthority($client) {
141133
return json_decode(json_encode($client['authority']));
142134
}
143135

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
use Illuminate\Database\Schema\Blueprint;
3+
use Illuminate\Database\Migrations\Migration;
4+
5+
class AddScopesToClients extends Migration {
6+
7+
public function up() {
8+
(new \Client)->get()->each(function ($client) {
9+
$client->scopes = isset($client->scopes) ? $client->scopes : ['all'];
10+
$client->save();
11+
});
12+
}
13+
14+
public function down() {}
15+
16+
}

app/lang/en/site.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'title' => 'Title',
2424
'name' => 'Name',
2525
'description' => 'Description',
26+
'scopes' => 'Scopes',
2627
'logo' => 'Logo',
2728
'language' => 'Language',
2829
'submit' => 'Submit',

0 commit comments

Comments
 (0)