Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
LtiAgsScoreService | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
send | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace oat\taoLti\models\classes\LtiAgs; |
25 | |
26 | use OAT\Library\Lti1p3Ags\Factory\Score\ScoreFactoryInterface; |
27 | use OAT\Library\Lti1p3Ags\Service\Score\ScoreServiceInterface; |
28 | use OAT\Library\Lti1p3Core\Exception\LtiException; |
29 | use OAT\Library\Lti1p3Core\Exception\LtiExceptionInterface; |
30 | use OAT\Library\Lti1p3Core\Message\Payload\Claim\AgsClaim; |
31 | use OAT\Library\Lti1p3Core\Registration\RegistrationInterface; |
32 | |
33 | class LtiAgsScoreService implements LtiAgsScoreServiceInterface |
34 | { |
35 | /** @var ScoreServiceInterface */ |
36 | private $scoreServiceClient; |
37 | |
38 | /** @var ScoreFactoryInterface */ |
39 | private $scoreFactory; |
40 | |
41 | public function __construct(ScoreServiceInterface $scoreServiceClient, ScoreFactoryInterface $scoreFactory) |
42 | { |
43 | $this->scoreServiceClient = $scoreServiceClient; |
44 | $this->scoreFactory = $scoreFactory; |
45 | } |
46 | |
47 | public function send(RegistrationInterface $registration, AgsClaim $ags, array $data): void |
48 | { |
49 | $score = $this->scoreFactory->create($data); |
50 | |
51 | try { |
52 | $result = $this->scoreServiceClient ->publishScoreForClaim($registration, $score, $ags); |
53 | |
54 | if (false === $result) { |
55 | throw new LtiException('Failed status has been received during AGS sending'); |
56 | } |
57 | } catch (LtiExceptionInterface $e) { |
58 | $exception = new LtiAgsException('AGS score send failed.', 1, $e); |
59 | |
60 | throw $exception |
61 | ->setAgsClaim($ags) |
62 | ->setRegistration($registration) |
63 | ->setScore($score); |
64 | } |
65 | } |
66 | } |