Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
PreviewLanguageService | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
getPreviewLanguage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
findTestTaker | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
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 | |
21 | namespace oat\taoQtiTestPreviewer\models; |
22 | |
23 | use common_exception_Error; |
24 | use oat\oatbox\service\ConfigurableService; |
25 | use oat\oatbox\user\User; |
26 | use oat\oatbox\user\UserLanguageService; |
27 | use oat\taoResultServer\models\classes\implementation\ResultServerService; |
28 | use tao_models_classes_UserService; |
29 | |
30 | class PreviewLanguageService extends ConfigurableService |
31 | { |
32 | /** |
33 | * @param string $deliveryUri |
34 | * @param string $resultId |
35 | * @return string |
36 | * |
37 | * @throws common_exception_Error |
38 | */ |
39 | public function getPreviewLanguage($deliveryUri, $resultId) |
40 | { |
41 | /** @var UserLanguageService $userLanguageService */ |
42 | $userLanguageService = $this->getServiceLocator()->get(UserLanguageService::class); |
43 | |
44 | return $userLanguageService->getDataLanguage($this->findTestTaker($deliveryUri, $resultId)); |
45 | } |
46 | |
47 | /** |
48 | * @param $deliveryUri |
49 | * @param $resultId |
50 | * @return User |
51 | * |
52 | * @throws common_exception_Error |
53 | */ |
54 | private function findTestTaker($deliveryUri, $resultId) |
55 | { |
56 | /** @var ResultServerService $resultServerService */ |
57 | $resultServerService = $this->getServiceLocator()->get(ResultServerService::SERVICE_ID); |
58 | |
59 | $resultStorage = $resultServerService->getResultStorage($deliveryUri); |
60 | |
61 | $userId = $resultStorage->getTestTaker($resultId); |
62 | |
63 | /** @var tao_models_classes_UserService $userService */ |
64 | $userService = $this->getServiceLocator()->get(tao_models_classes_UserService::SERVICE_ID); |
65 | |
66 | return $userService->getUserById($userId); |
67 | } |
68 | } |