Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
CompiledTestConverterService | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
convert | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getNewFile | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
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) 2019 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | namespace oat\taoDeliveryRdf\model\assembly; |
22 | |
23 | use common_Exception; |
24 | use tao_models_classes_service_StorageDirectory; |
25 | use oat\oatbox\filesystem\File; |
26 | use oat\taoQtiTest\models\CompilationDataService; |
27 | |
28 | class CompiledTestConverterService |
29 | { |
30 | /** |
31 | * @var CompilationDataService |
32 | */ |
33 | private $compilationDataReader = null; |
34 | /** |
35 | * @var CompilationDataService |
36 | */ |
37 | private $compilationDataWriter = null; |
38 | /** |
39 | * CompiledTestConverterService constructor. |
40 | * @param CompilationDataService $compilationDataReader |
41 | * @param CompilationDataService $compilationDataWriter |
42 | */ |
43 | public function __construct( |
44 | CompilationDataService $compilationDataReader, |
45 | CompilationDataService $compilationDataWriter |
46 | ) { |
47 | $this->compilationDataReader = $compilationDataReader; |
48 | $this->compilationDataWriter = $compilationDataWriter; |
49 | } |
50 | |
51 | /** |
52 | * @param File $file |
53 | * @param tao_models_classes_service_StorageDirectory $directory |
54 | * @return File |
55 | * @throws common_Exception |
56 | */ |
57 | public function convert(File $file, tao_models_classes_service_StorageDirectory $directory) |
58 | { |
59 | $fileName = pathinfo($file->getBasename(), PATHINFO_FILENAME); |
60 | $resultFile = $this->getNewFile($directory, $fileName); |
61 | $object = $this->compilationDataReader->readCompilationData($directory, $fileName); |
62 | $this->compilationDataWriter->writeCompilationData($directory, $fileName, $object); |
63 | return $resultFile; |
64 | } |
65 | |
66 | /** |
67 | * @param tao_models_classes_service_StorageDirectory $directory |
68 | * @param string $outputFileName |
69 | * @return File |
70 | */ |
71 | private function getNewFile(tao_models_classes_service_StorageDirectory $directory, $outputFileName) |
72 | { |
73 | $outputFileName .= '.' . $this->compilationDataWriter->getOutputFileType(); |
74 | $resultFile = $directory->getFile($outputFileName); |
75 | if ($resultFile->exists()) { |
76 | $resultFile->delete(); |
77 | } |
78 | return $resultFile; |
79 | } |
80 | } |