Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.30% |
26 / 27 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
taoQtiTest_helpers_SessionManager | |
96.30% |
26 / 27 |
|
87.50% |
7 / 8 |
14 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
setResultServer | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getResultServer | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setTest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
instantiateAssessmentTestSession | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
7.01 | |||
configureAssessmentTestSession | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
instantiateAssessmentItemSession | |
100.00% |
1 / 1 |
|
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) 2013-2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | */ |
21 | |
22 | use oat\taoResultServer\models\classes\ResultStorageWrapper; |
23 | use qtism\runtime\tests\AbstractSessionManager; |
24 | use qtism\runtime\tests\TestResultsSubmission; |
25 | use qtism\runtime\tests\Route; |
26 | use qtism\runtime\tests\AssessmentTestSession; |
27 | use qtism\runtime\tests\AssessmentItemSession; |
28 | use qtism\data\AssessmentTest; |
29 | use qtism\data\IAssessmentItem; |
30 | use qtism\common\datatypes\QtiDuration; |
31 | |
32 | /** |
33 | * A TAO specific implementation of QTISM's AbstractSessionManager. |
34 | * |
35 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
36 | * |
37 | */ |
38 | class taoQtiTest_helpers_SessionManager extends AbstractSessionManager |
39 | { |
40 | /** |
41 | * The class name of the default TestSession |
42 | */ |
43 | public const DEFAULT_TEST_SESSION = '\\taoQtiTest_helpers_TestSession'; |
44 | |
45 | /** |
46 | * The result server to be used by tao_helpers_TestSession created by the factory. |
47 | * |
48 | * @var ResultStorageWrapper |
49 | */ |
50 | private $resultServer; |
51 | |
52 | /** |
53 | * The TAO Resource describing the Test definition to be set to the AssessmentTestSession to be built. |
54 | * |
55 | * @var core_kernel_classes_Resource |
56 | */ |
57 | private $test; |
58 | |
59 | /** |
60 | * Create a new SessionManager object. |
61 | * |
62 | * @param ResultStorageWrapper $resultServer The ResultServer to be set to the AssessmentTestSession to be built. |
63 | * @param core_kernel_classes_Resource $test The TAO Resource describing the Test definition to be set to the |
64 | * AssessmentTestSession to be built. |
65 | * @throws \InvalidArgumentException |
66 | * @throws common_Exception |
67 | */ |
68 | public function __construct(ResultStorageWrapper $resultServer, core_kernel_classes_Resource $test) |
69 | { |
70 | parent::__construct(); |
71 | $this->setAcceptableLatency( |
72 | new QtiDuration(taoQtiTest_models_classes_QtiTestService::singleton()->getQtiTestAcceptableLatency()) |
73 | ); |
74 | $this->setResultServer($resultServer); |
75 | $this->setTest($test); |
76 | } |
77 | |
78 | /** |
79 | * Set the result server to be used by tao_helpers_TestSession created by the factory. |
80 | * |
81 | * @param ResultStorageWrapper $resultServer |
82 | */ |
83 | public function setResultServer(ResultStorageWrapper $resultServer) |
84 | { |
85 | $this->resultServer = $resultServer; |
86 | } |
87 | |
88 | /** |
89 | * Get the result server to be used by tao_helpers_TestSession created by the factory. |
90 | * |
91 | * @return ResultStorageWrapper |
92 | */ |
93 | public function getResultServer() |
94 | { |
95 | return $this->resultServer; |
96 | } |
97 | |
98 | /** |
99 | * Set the TAO Resource describing the Test definition to be set to the AssessmentTestSession to be built. |
100 | * |
101 | * @param core_kernel_classes_Resource $test A TAO Test Resource. |
102 | */ |
103 | public function setTest(core_kernel_classes_Resource $test) |
104 | { |
105 | $this->test = $test; |
106 | } |
107 | |
108 | /** |
109 | * Get the TAO Resource describing the Test definition to be set to the AssessmentTestSession to be built. |
110 | * |
111 | * @return core_kernel_classes_Resource A TAO Resource. |
112 | */ |
113 | public function getTest() |
114 | { |
115 | return $this->test; |
116 | } |
117 | |
118 | /** |
119 | * Instantiates an AssessmentTestSession with the default implementation provided by QTISM. |
120 | * @param AssessmentTest $test |
121 | * @param Route $route |
122 | * @return AssessmentTestSession |
123 | * @throws common_ext_ExtensionException |
124 | */ |
125 | protected function instantiateAssessmentTestSession(AssessmentTest $test, Route $route) |
126 | { |
127 | $config = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->getConfig('testRunner'); |
128 | |
129 | // Test Session class instantiation, depending on configuration. |
130 | if (!isset($config) || !isset($config['test-session'])) { |
131 | $className = self::DEFAULT_TEST_SESSION; |
132 | \common_Logger::w("Missing configuration for TestRunner session class, using '${className}' by default!"); |
133 | } else { |
134 | $className = $config['test-session']; |
135 | } |
136 | |
137 | $assessmentTestSession = new $className($test, $this, $route, $this->getResultServer(), $this->getTest()); |
138 | |
139 | $forceBranchrules = (isset($config['force-branchrules'])) ? $config['force-branchrules'] : false; |
140 | $forcePreconditions = (isset($config['force-preconditions'])) ? $config['force-preconditions'] : false; |
141 | $pathTracking = (isset($config['path-tracking'])) ? $config['path-tracking'] : false; |
142 | $alwaysAllowJumps = (isset($config['always-allow-jumps'])) ? $config['always-allow-jumps'] : false; |
143 | |
144 | $assessmentTestSession->setForceBranching($forceBranchrules); |
145 | $assessmentTestSession->setForcePreconditions($forcePreconditions); |
146 | $assessmentTestSession->setAlwaysAllowJumps($alwaysAllowJumps); |
147 | $assessmentTestSession->setPathTracking($pathTracking); |
148 | |
149 | return $assessmentTestSession; |
150 | } |
151 | |
152 | /** |
153 | * Extra configuration for newly instantiated AssessmentTestSession objects. This implementation |
154 | * forces test results to be sent at the end of the candidate session, and get the acceptable |
155 | * latency time from the taoQtiTest extension's configuration. |
156 | * |
157 | * @param AssessmentTestSession $assessmentTestSession |
158 | */ |
159 | protected function configureAssessmentTestSession(AssessmentTestSession $assessmentTestSession) |
160 | { |
161 | $assessmentTestSession->setTestResultsSubmission(TestResultsSubmission::END); |
162 | } |
163 | |
164 | /** |
165 | * Instantiates an AssessmentItemSession with the default implementation provided by QTISM. |
166 | * |
167 | * @param IAssessmentItem $assessmentItem |
168 | * @param integer $navigationMode A value from the NavigationMode enumeration. |
169 | * @param integer $submissionMode A value from the SubmissionMode enumeration. |
170 | * @return AssessmentItemSession A freshly instantiated AssessmentItemSession. |
171 | * @throws \InvalidArgumentException |
172 | */ |
173 | protected function instantiateAssessmentItemSession( |
174 | IAssessmentItem $assessmentItem, |
175 | $navigationMode, |
176 | $submissionMode |
177 | ) { |
178 | return new AssessmentItemSession($assessmentItem, $this, $navigationMode, $submissionMode); |
179 | } |
180 | } |