Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
BookletController | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
getData | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
getBooklet | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** @noinspection PhpUnhandledExceptionInspection */ |
3 | declare(strict_types=1); |
4 | |
5 | // TODO unit tests ! |
6 | |
7 | use Slim\Exception\HttpForbiddenException; |
8 | use Slim\Http\ServerRequest as Request; |
9 | use Slim\Http\Response; |
10 | |
11 | class BookletController extends Controller { |
12 | public static function getData(Request $request, Response $response): Response { |
13 | /* @var $authToken AuthToken */ |
14 | $authToken = $request->getAttribute('AuthToken'); |
15 | $personToken = $authToken->getToken(); |
16 | |
17 | $bookletName = $request->getAttribute('booklet_name'); |
18 | |
19 | if (!self::sessionDAO()->personHasBooklet($personToken, $bookletName) |
20 | and !self::adminDAO()->hasMonitorAccessToWorkspace($personToken, $authToken->getWorkspaceId())) { |
21 | throw new HttpForbiddenException($request, "Booklet with name `$bookletName` is not allowed for $personToken"); |
22 | } |
23 | |
24 | $testStatus = self::sessionDAO()->getTestStatus($personToken, $bookletName); |
25 | return $response->withJson($testStatus); |
26 | } |
27 | |
28 | public static function getBooklet(Request $request, Response $response): Response { |
29 | /* @var $authToken AuthToken */ |
30 | $authToken = $request->getAttribute('AuthToken'); |
31 | $personToken = $authToken->getToken(); |
32 | |
33 | $bookletName = $request->getAttribute('booklet_name'); |
34 | |
35 | if (!self::sessionDAO()->personHasBooklet($personToken, $bookletName) |
36 | and !self::adminDAO()->hasMonitorAccessToWorkspace($personToken, $authToken->getWorkspaceId())) { |
37 | throw new HttpForbiddenException($request, "Booklet with name `$bookletName` is not allowed for $personToken"); |
38 | } |
39 | |
40 | $Workspace = new Workspace($authToken->getWorkspaceId()); |
41 | $booklet = $Workspace->getFileById('Booklet', $bookletName); |
42 | /* @var $booklet XMLFileBooklet */ |
43 | $xml = $booklet->getContent(); |
44 | |
45 | return $response->withHeader('Content-Type', 'application/xml')->write($xml); |
46 | } |
47 | } |