Skip to content

Commit 4b0e573

Browse files
committed
Merge pull request #671 from LearningLocker/issue/voiding
Adds bulk voiding API.
2 parents ee960a1 + 34179c0 commit 4b0e573

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

app/controllers/api/Statements.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,12 @@ public function index(){
7979

8080
return $this->returnJson($data);
8181
}
82+
83+
public function void() {
84+
$match = json_decode(
85+
\LockerRequest::getParam('match'),
86+
true
87+
) ?: [];
88+
return \Response::json($this->query->void($match, $this->getOptions()));
89+
}
8290
}

app/locker/repository/Query/EloquentQueryRepository.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Locker\Repository\Query;
22
use \Locker\Helpers\Helpers as Helpers;
3+
use \Locker\Repository\Statement\EloquentRepository as StatementsRepo;
34

45
class EloquentQueryRepository implements QueryRepository {
56

@@ -120,6 +121,37 @@ public function aggregateObject($lrsId, array $match) {
120121
]]);
121122
}
122123

124+
public function void(array $match, array $opts) {
125+
$data = $this->aggregate($opts['lrs_id'], [[
126+
'$match' => $match
127+
], [
128+
'$project' => [
129+
'_id' => 0,
130+
'statement.id' => 1,
131+
]
132+
]]);
133+
134+
$statements = array_map(function ($result) use ($opts) {
135+
return [
136+
'actor' => $opts['client']['authority'],
137+
'verb' => [
138+
'id' => 'http://adlnet.gov/expapi/verbs/voided',
139+
'display' => [
140+
'en' => 'voided'
141+
]
142+
],
143+
'object' => [
144+
'objectType' => 'StatementRef',
145+
'id' => $result['statement']['id']
146+
]
147+
];
148+
}, $data['result']);
149+
150+
$opts['authority'] = json_decode(json_encode($opts['client']['authority']));
151+
152+
return (new StatementsRepo())->store(json_decode(json_encode($statements)), [], $opts);
153+
}
154+
123155
/**
124156
* Query to grab the required data based on type
125157
*

app/routes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@
389389

390390
});
391391

392+
Route::group(['prefix' => 'api/v2', 'before' => 'auth.statement'], function () {
393+
Route::get('statements/void', ['uses' => 'Controllers\API\Statements@void']);
394+
});
395+
392396
/*
393397
|------------------------------------------------------------------
394398
| Learning Locker RESTful API

0 commit comments

Comments
 (0)