|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This class handles the SCORM export of free-answer questions. |
|
6
|
|
|
* |
|
7
|
|
|
* @package chamilo.exercise.scorm |
|
8
|
|
|
*/ |
|
9
|
|
|
class ScormAnswerFree extends Answer |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Export the text with missing words. |
|
13
|
|
|
* |
|
14
|
|
|
* As a side effect, it stores two lists in the class : |
|
15
|
|
|
* the missing words and their respective weightings. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function export() |
|
18
|
|
|
{ |
|
19
|
|
|
$js = ''; |
|
20
|
|
|
$identifier = 'question_'.$this->questionJSId.'_free'; |
|
21
|
|
|
// currently the free answers cannot be displayed, so ignore the textarea |
|
22
|
|
|
$html = '<tr><td colspan="2">'; |
|
23
|
|
|
$type = $this->getQuestionType(); |
|
24
|
|
|
|
|
25
|
|
|
if ($type == ORAL_EXPRESSION) { |
|
26
|
|
|
/* |
|
27
|
|
|
$template = new Template(''); |
|
28
|
|
|
$template->assign('directory', '/tmp/'); |
|
29
|
|
|
$template->assign('user_id', api_get_user_id()); |
|
30
|
|
|
|
|
31
|
|
|
$layout = $template->get_template('document/record_audio.tpl'); |
|
32
|
|
|
$html .= $template->fetch($layout);*/ |
|
33
|
|
|
|
|
34
|
|
|
$html = '<tr><td colspan="2">'.get_lang('ThisItemIsNotExportable').'</td></tr>'; |
|
35
|
|
|
|
|
36
|
|
|
return [$js, $html]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$html .= '<textarea minlength="20" name="'.$identifier.'" id="'.$identifier.'" ></textarea>'; |
|
40
|
|
|
$html .= '</td></tr>'; |
|
41
|
|
|
$js .= 'questions_answers['.$this->questionJSId.'] = new Array();'; |
|
42
|
|
|
$js .= 'questions_answers_correct['.$this->questionJSId.'] = "";'; |
|
43
|
|
|
$js .= 'questions_types['.$this->questionJSId.'] = \'free\';'; |
|
44
|
|
|
$jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = "0";'; |
|
45
|
|
|
$js .= $jstmpw; |
|
46
|
|
|
|
|
47
|
|
|
return [$js, $html]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* This class handles the SCORM export of hotpot questions. |
|
53
|
|
|
* |
|
54
|
|
|
* @package chamilo.exercise.scorm |
|
55
|
|
|
*/ |
|
56
|
|
|
class ScormAnswerHotspot extends Answer |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the javascript code that goes with HotSpot exercises. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string The JavaScript code |
|
62
|
|
|
*/ |
|
63
|
|
|
public function get_js_header() |
|
64
|
|
|
{ |
|
65
|
|
|
$header = '<script>'; |
|
66
|
|
|
$header .= file_get_contents(api_get_path(SYS_CODE_PATH).'inc/lib/javascript/hotspot/js/hotspot.js'); |
|
67
|
|
|
$header .= '</script>'; |
|
68
|
|
|
|
|
69
|
|
|
if ($this->standalone) { |
|
70
|
|
|
//because this header closes so many times the <script> tag, we have to reopen our own |
|
71
|
|
|
$header .= '<script>'; |
|
72
|
|
|
$header .= 'questions_answers['.$this->questionJSId.'] = new Array();'."\n"; |
|
73
|
|
|
$header .= 'questions_answers_correct['.$this->questionJSId.'] = new Array();'."\n"; |
|
74
|
|
|
$header .= 'questions_types['.$this->questionJSId.'] = \'hotspot\';'."\n"; |
|
75
|
|
|
$jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; |
|
76
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; |
|
77
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = 0;'.";\n"; |
|
78
|
|
|
$header .= $jstmpw; |
|
79
|
|
|
} else { |
|
80
|
|
|
$header = ''; |
|
81
|
|
|
$header .= 'questions_answers['.$this->questionJSId.'] = new Array();'."\n"; |
|
82
|
|
|
$header .= 'questions_answers_correct['.$this->questionJSId.'] = new Array();'."\n"; |
|
83
|
|
|
$header .= 'questions_types['.$this->questionJSId.'] = \'hotspot\';'."\n"; |
|
84
|
|
|
$jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; |
|
85
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; |
|
86
|
|
|
$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = 0;'."\n"; |
|
87
|
|
|
$header .= $jstmpw; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $header; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Export the text with missing words. |
|
95
|
|
|
* |
|
96
|
|
|
* As a side effect, it stores two lists in the class : |
|
97
|
|
|
* the missing words and their respective weightings. |
|
98
|
|
|
*/ |
|
99
|
|
|
public function export() |
|
100
|
|
|
{ |
|
101
|
|
|
$js = $this->get_js_header(); |
|
102
|
|
|
$html = '<tr><td colspan="2"><table width="100%">'; |
|
103
|
|
|
// some javascript must be added for that kind of questions |
|
104
|
|
|
$html .= ''; |
|
105
|
|
|
|
|
106
|
|
|
// Get the answers, make a list |
|
107
|
|
|
$nbrAnswers = $this->selectNbrAnswers(); |
|
108
|
|
|
|
|
109
|
|
|
$answerList = '<div |
|
110
|
|
|
style="padding: 10px; |
|
111
|
|
|
margin-left: -8px; |
|
112
|
|
|
border: 1px solid #4271b5; |
|
113
|
|
|
height: 448px; |
|
114
|
|
|
width: 200px;"><b>'.get_lang('HotspotZones').'</b><ol>'; |
|
115
|
|
|
for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
|
116
|
|
|
$answerList .= '<li>'.$this->selectAnswer($answerId).'</li>'; |
|
117
|
|
|
} |
|
118
|
|
|
$answerList .= '</ol></div>'; |
|
119
|
|
|
$relPath = api_get_path(REL_PATH); |
|
120
|
|
|
$html .= <<<HTML |
|
121
|
|
|
<tr> |
|
122
|
|
|
<td> |
|
123
|
|
|
<div id="hotspot-{$this->questionJSId}"></div> |
|
124
|
|
|
<script> |
|
125
|
|
|
document.addEventListener('DOMContentListener', function () { |
|
126
|
|
|
new HotspotQuestion({ |
|
127
|
|
|
questionId: {$this->questionJSId}, |
|
128
|
|
|
selector: '#hotspot-{$this->questionJSId}', |
|
129
|
|
|
for: 'user', |
|
130
|
|
|
relPath: '$relPath' |
|
131
|
|
|
}); |
|
132
|
|
|
}); |
|
133
|
|
|
</script> |
|
134
|
|
|
</td> |
|
135
|
|
|
<td> |
|
136
|
|
|
$answerList |
|
137
|
|
|
</td> |
|
138
|
|
|
<tr> |
|
139
|
|
|
HTML; |
|
140
|
|
|
$html .= '</table></td></tr>'; |
|
141
|
|
|
|
|
142
|
|
|
// currently the free answers cannot be displayed, so ignore the textarea |
|
143
|
|
|
$html = '<tr><td colspan="2">'.get_lang('ThisItemIsNotExportable').'</td></tr>'; |
|
144
|
|
|
|
|
145
|
|
|
return [$js, $html]; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.