Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
QtiRunnerRubric | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
getRubrics | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
getRubricBlock | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 |
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) 2016 (original work) Open Assessment Technologies SA ; |
19 | */ |
20 | |
21 | /** |
22 | * @author Jean-Sébastien Conan <jean-sebastien.conan@vesperiagroup.com> |
23 | */ |
24 | |
25 | namespace oat\taoQtiTest\models\runner\rubric; |
26 | |
27 | use oat\oatbox\service\ConfigurableService; |
28 | use oat\taoQtiTest\models\runner\RunnerServiceContext; |
29 | use OutOfBoundsException; |
30 | use qtism\data\AssessmentItemRef; |
31 | use qtism\data\View; |
32 | use qtism\runtime\tests\AssessmentTestSession; |
33 | use qtism\runtime\tests\RouteItem; |
34 | use taoQtiTest_models_classes_QtiTestService; |
35 | |
36 | /** |
37 | * Class QtiRunnerRubric |
38 | * @package oat\taoQtiTest\models\runner\rubric |
39 | */ |
40 | class QtiRunnerRubric extends ConfigurableService implements RunnerRubric |
41 | { |
42 | public const SERVICE_ID = 'taoQtiTest/QtiRunnerRubric'; |
43 | |
44 | /** |
45 | * Gets the rubrics according to the current session state |
46 | * The content is directly rendered into the page |
47 | * @param RunnerServiceContext $context |
48 | * @param AssessmentItemRef $itemRef (optional) otherwise use the current |
49 | * @return mixed |
50 | */ |
51 | public function getRubrics(RunnerServiceContext $context, AssessmentItemRef $itemRef = null) |
52 | { |
53 | /* @var AssessmentTestSession $session */ |
54 | $session = $context->getTestSession(); |
55 | |
56 | $routeItem = null; |
57 | if (!is_null($itemRef)) { |
58 | try { |
59 | $routeItem = $session->getRoute()->getRouteItemsByAssessmentItemRef($itemRef); |
60 | if ($routeItem) { |
61 | $routeItem = $routeItem[0]; |
62 | } |
63 | } catch (OutOfBoundsException $obe) { |
64 | \common_Logger::d("Could not retrieve the route for item '${itemRef}'."); |
65 | } |
66 | } else { |
67 | $routeItem = $session->getRoute()->current(); |
68 | } |
69 | |
70 | return implode('', $this->getRubricBlock($routeItem, $session, $context->getCompilationDirectory())); |
71 | } |
72 | |
73 | |
74 | /** |
75 | * @param RouteItem $routeItem |
76 | * @param AssessmentTestSession $session |
77 | * @param array $compilationDirs |
78 | * @return array |
79 | */ |
80 | public function getRubricBlock($routeItem, $session, $compilationDirs) |
81 | { |
82 | // TODO: make a better implementation for rubrics loading. |
83 | |
84 | $rubrics = []; |
85 | |
86 | if ($routeItem) { |
87 | $rubricRefs = $routeItem->getRubricBlockRefs(); |
88 | |
89 | if (count($rubricRefs) > 0) { |
90 | // -- variables used in the included rubric block templates. |
91 | // base path (base URI to be used for resource inclusion). |
92 | $basePathVarName = taoQtiTest_models_classes_QtiTestService::TEST_BASE_PATH_NAME; |
93 | $$basePathVarName = $compilationDirs['public']->getPublicAccessUrl(); |
94 | |
95 | // state name (the variable to access to get the state of the assessmentTestSession). |
96 | $stateName = taoQtiTest_models_classes_QtiTestService::TEST_RENDERING_STATE_NAME; |
97 | $$stateName = $session; |
98 | |
99 | // views name (the variable to be accessed for the visibility of rubric blocks). |
100 | $viewsName = taoQtiTest_models_classes_QtiTestService::TEST_VIEWS_NAME; |
101 | $$viewsName = [View::CANDIDATE]; |
102 | |
103 | $tmpDir = \tao_helpers_File::createTempDir(); |
104 | ob_start(); |
105 | foreach ($rubricRefs as $rubric) { |
106 | $data = $compilationDirs['private']->read($rubric->getHref()); |
107 | $tmpFile = $tmpDir . basename($rubric->getHref()); |
108 | file_put_contents($tmpFile, $data); |
109 | include($tmpFile); |
110 | unlink($tmpFile); |
111 | } |
112 | $rubrics[] = ob_get_contents(); |
113 | ob_end_clean(); |
114 | rmdir($tmpDir); |
115 | } |
116 | } |
117 | |
118 | return $rubrics; |
119 | } |
120 | } |