blob: be4aed7160796bde547e605aa8a7ba4229b54b44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<?php
use Studip\LTI13a\LineItemRepository;
use Studip\LTI13a\RegistrationManager;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\UpdateLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\DeleteLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\GetLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\Result\Server\Handler\ResultServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\Score\Server\Handler\ScoreServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\CreateLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\ListLineItemsServiceServerRequestHandler;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
/**
* ags.php - LTI assignment and grade services controller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Moritz Strohm
* @date 2024
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class Lti_AgsController extends StudipController
{
use \Studip\OAuth2\NegotiatesWithPsr7;
public function __construct(\Trails\Dispatcher $dispatcher)
{
$this->with_session = true;
parent::__construct($dispatcher);
}
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
//All the work is done by the OAT-SA library and
//the implementation of its interfaces in Stud.IP.
//Only the handler changes for the endpoints.
$reg_manager = new RegistrationManager();
$line_item_repo = new LineItemRepository();
$validator = new RequestAccessTokenValidator($reg_manager);
$handler = null;
if ($action === 'line_item') {
if (empty($args)) {
if (Request::isPut()) {
//Update a line item:
$handler = new UpdateLineItemServiceServerRequestHandler($line_item_repo);
} elseif (Request::isDelete()) {
//Delete a line item:
$handler = new DeleteLineItemServiceServerRequestHandler($line_item_repo);
} else {
//Get a line item:
$handler = new GetLineItemServiceServerRequestHandler($line_item_repo);
}
} elseif ($args[0] === 'results') {
$handler = new ResultServiceServerRequestHandler($line_item_repo, new Studip\LTI13a\ResultRepository());
} elseif ($args[0] === 'scores') {
$handler = new ScoreServiceServerRequestHandler($line_item_repo,new \Studip\LTI13a\ScoreRepository());
}
} elseif ($action === 'line_items') {
if (Request::isPost()) {
//Create a line item:
$handler = new CreateLineItemServiceServerRequestHandler($line_item_repo);
} else {
//List line items:
$handler = new ListLineItemsServiceServerRequestHandler($line_item_repo);
}
} else {
//Invalid endpoint.
throw new AccessDeniedException(studip_interpolate('Invalid endpoint: %{endpoint}', ['endpoint' => $action]));
}
if (!$handler) {
throw new \Studip\LTIException('No handler available for this request.');
}
$server = new LtiServiceServer($validator, $handler);
$this->renderPsrResponse($server->handle($this->getPsrRequest()));
}
/**
* This is the endpoint for the LTI AGS lineitem service.
*
* @return void
*/
public function line_item_action(): void
{
//Nothing here. All is done in the before_filter.
}
/**
* This is the endpoint for the LTI AGS lineitems service.
*
* @return void
*/
public function line_items_action(): void
{
//Nothing here. All is done in the before_filter.
}
}
|