Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
OverriddenLtiToolsRepository | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
findAllUnfiltered | |
100.00% |
8 / 8 |
|
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) 2020 (original work) Open Assessment Technologies SA; |
19 | * |
20 | * @author Sergei Mikhailov <sergei.mikhailov@taotesting.com> |
21 | */ |
22 | |
23 | declare(strict_types=1); |
24 | |
25 | namespace oat\ltiDeliveryProvider\model\options\DataAccess\Repository; |
26 | |
27 | use oat\ltiDeliveryProvider\model\options\DataAccess\Mapper\OptionCollectionMapper; |
28 | use oat\oatbox\session\SessionService; |
29 | use oat\taoLti\models\classes\TaoLtiSession; |
30 | use oat\taoQtiTest\models\runner\config\Business\Domain\OptionCollection; |
31 | use oat\taoQtiTest\models\runner\toolsStates\DataAccess\Repository\AbstractOverriddenToolsRepository; |
32 | use oat\taoQtiTest\models\TestCategoryPresetProvider; |
33 | |
34 | class OverriddenLtiToolsRepository extends AbstractOverriddenToolsRepository |
35 | { |
36 | private const CUSTOM_LTI_TAO_TOOLS = 'custom_x_tao_tools'; |
37 | |
38 | /** @var SessionService */ |
39 | private $sessionService; |
40 | /** @var OptionCollectionMapper */ |
41 | private $mapper; |
42 | |
43 | public function __construct( |
44 | TestCategoryPresetProvider $presetRepository, |
45 | SessionService $sessionService, |
46 | OptionCollectionMapper $mapper |
47 | ) { |
48 | parent::__construct($presetRepository); |
49 | |
50 | $this->sessionService = $sessionService; |
51 | $this->mapper = $mapper; |
52 | } |
53 | |
54 | protected function findAllUnfiltered(): OptionCollection |
55 | { |
56 | $session = $this->sessionService->getCurrentSession(); |
57 | |
58 | if (!$session instanceof TaoLtiSession) { |
59 | return new OptionCollection(); |
60 | } |
61 | |
62 | $launchData = $session->getLaunchData(); |
63 | |
64 | if (!$launchData->hasVariable(self::CUSTOM_LTI_TAO_TOOLS)) { |
65 | return new OptionCollection(); |
66 | } |
67 | |
68 | /** @noinspection PhpUnhandledExceptionInspection */ |
69 | $toolSettings = (array)json_decode($launchData->getVariable(self::CUSTOM_LTI_TAO_TOOLS), true); |
70 | |
71 | return $this->mapper->toDomain($toolSettings); |
72 | } |
73 | } |