Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
CompilationDataService | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getOutputFileType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
writeCompilationData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
readCompilationData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
writeCompilationMetadata | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
readCompilationMetadata | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace oat\taoQtiTest\models; |
4 | |
5 | use oat\oatbox\service\ConfigurableService; |
6 | use qtism\data\AssessmentTest; |
7 | use qtism\data\QtiComponent; |
8 | |
9 | /** |
10 | * Compilation Data Service |
11 | * |
12 | * An abstract Compilation Data Service. Its implementation aim |
13 | * at providing a way to compile Delivery data in various ways. |
14 | */ |
15 | abstract class CompilationDataService extends ConfigurableService |
16 | { |
17 | public const SERVICE_ID = 'taoQtiTest/CompilationDataService'; |
18 | |
19 | /** |
20 | * Create a new CompilationDataService object. |
21 | * |
22 | * @param $options |
23 | */ |
24 | public function __construct($options = []) |
25 | { |
26 | parent::__construct($options); |
27 | } |
28 | |
29 | /** |
30 | * @return string |
31 | */ |
32 | abstract public function getOutputFileType(); |
33 | |
34 | /** |
35 | * Write Compilation Data |
36 | * |
37 | * Write a QtiComponent $object into a given $compilationDirectory at a given $path. |
38 | * |
39 | * @param \tao_models_classes_service_StorageDirectory $compilationDirectory |
40 | * @param string $path |
41 | * @param \qtism\data\QtiComponent $object |
42 | */ |
43 | abstract public function writeCompilationData( |
44 | \tao_models_classes_service_StorageDirectory $compilationDirectory, |
45 | $path, |
46 | QtiComponent $object |
47 | ); |
48 | |
49 | |
50 | /** |
51 | * Read Compilation Data |
52 | * |
53 | * Read a QtiComponent object from a given $compilationDirectory at a given $path. |
54 | * |
55 | * @param \tao_models_classes_service_StorageDirectory $compilationDirectory |
56 | * @param string $path |
57 | * @param string $cacheInfo (optional) A context string possibly used by implementations for caching purpose. |
58 | * @return \qtism\data\QtiComponent |
59 | * @throws \common_Exception In case of error. |
60 | */ |
61 | abstract public function readCompilationData( |
62 | \tao_models_classes_service_StorageDirectory $compilationDirectory, |
63 | $path, |
64 | $cacheInfo = '' |
65 | ); |
66 | |
67 | /** |
68 | * Write Compilation Metadata |
69 | * |
70 | * @param \tao_models_classes_service_StorageDirectory $compilationDirectory |
71 | * @param AssessmentTest $test |
72 | * @throws \common_Exception |
73 | */ |
74 | public function writeCompilationMetadata( |
75 | \tao_models_classes_service_StorageDirectory $compilationDirectory, |
76 | AssessmentTest $test |
77 | ) { |
78 | try { |
79 | $filename = \taoQtiTest_models_classes_QtiTestService::TEST_COMPILED_META_FILENAME . '.json'; |
80 | $meta = \taoQtiTest_helpers_TestCompilerUtils::testMeta($test); |
81 | $compilationDirectory->write($filename, json_encode($meta)); |
82 | } catch (\Exception $e) { |
83 | throw new \common_Exception("Unable to write file '${filename}'."); |
84 | } |
85 | } |
86 | |
87 | /** |
88 | * Read Compilation Metadata |
89 | * |
90 | * @param \tao_models_classes_service_StorageDirectory $compilationDirectory |
91 | * @return mixed |
92 | * @throws \common_Exception |
93 | */ |
94 | public function readCompilationMetadata(\tao_models_classes_service_StorageDirectory $compilationDirectory) |
95 | { |
96 | try { |
97 | $data = $compilationDirectory->read( |
98 | \taoQtiTest_models_classes_QtiTestService::TEST_COMPILED_META_FILENAME . '.json' |
99 | ); |
100 | return json_decode($data, true); |
101 | } catch (\Exception $e) { |
102 | // Legacy compilation support. |
103 | try { |
104 | $filename = \taoQtiTest_models_classes_QtiTestService::TEST_COMPILED_META_FILENAME . '.php'; |
105 | $data = $compilationDirectory->read($filename); |
106 | $data = str_replace('<?php', '', $data); |
107 | $data = str_replace('?>', '', $data); |
108 | return eval($data); |
109 | } catch (\Exception $e) { |
110 | throw new \common_Exception("Unable to read file '${filename}'."); |
111 | } |
112 | } |
113 | } |
114 | } |