Skip to content

Commit

Permalink
Add bootstrap/jquery when exporting a SCORM package, adding oral ques…
Browse files Browse the repository at this point in the history
…tion type

 See BT#11321
  • Loading branch information
jmontoyaa committed Jul 6, 2016
1 parent 63c0c37 commit 8e340ef
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 53 deletions.
6 changes: 3 additions & 3 deletions main/document/record_audio.php
Expand Up @@ -29,9 +29,9 @@
$dir = $document_data['path'];

//make some vars
$wamidir=$dir;
if($wamidir=="/"){
$wamidir="";
$wamidir = $dir;
if ($wamidir == "/") {
$wamidir = "";
}
$wamiurlplay = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$wamidir."/";
$groupId = api_get_group_id();
Expand Down
101 changes: 63 additions & 38 deletions main/exercise/export/scorm/scorm_classes.php
Expand Up @@ -166,18 +166,27 @@ function getQuestionHTML()
/**
* Return the JavaScript code bound to the question
*/
function getQuestionJS()
public function getQuestionJS()
{
$w = $this->selectWeighting();
$s = 'questions.push('.$this->js_id.');'."\n";
if ($this->type == HOT_SPOT) {
//put the max score to 0 to avoid discounting the points of
//non-exported quiz types in the SCORM
$w = 0;
$weight = $this->selectWeighting();
$js = 'questions.push('.$this->js_id.');'."\n";

switch ($this->type) {
case ORAL_EXPRESSION:
$script = file_get_contents(api_get_path(LIBRARY_PATH) . 'javascript/rtc/RecordRTC.js');
$script .= file_get_contents(api_get_path(LIBRARY_PATH) . 'wami-recorder/recorder.js');
$script .= file_get_contents(api_get_path(LIBRARY_PATH) . 'wami-recorder/gui.js');
$js .= $script;
break;
case HOT_SPOT:
//put the max score to 0 to avoid discounting the points of
//non-exported quiz types in the SCORM
$weight = 0;
break;
}
$s .= 'questions_score_max['.$this->js_id.'] = '.$w.";";
$js .= 'questions_score_max['.$this->js_id.'] = '.$weight.";";

return $s;
return $js;
}
}

Expand Down Expand Up @@ -215,7 +224,7 @@ function export()
<input name="'.$identifier.'" id="'.$identifier.'" value="'.$i.'" type="checkbox" />
</td>
<td width="95%">
<label for="'.$identifier.'">' . $this->answer[$i] . '</label>
<label for="'.$identifier.'">' . Security::remove_XSS($this->answer[$i]) . '</label>
</td>
</tr>';

Expand Down Expand Up @@ -243,7 +252,7 @@ function export()
<input name="'.$identifier.'" id="'.$identifier.'" value="'.$i.'" type="checkbox" />
</td>
<td width="95%">
<label for="'.$identifier.'">' . $this->answer[$i] . '</label>
<label for="'.$identifier.'">' . Security::remove_XSS($this->answer[$i]) . '</label>
</td>
</tr>';

Expand Down Expand Up @@ -271,7 +280,7 @@ function export()
<input name="'.$identifier_name.'" id="'.$identifier.'" value="'.$i.'" type="checkbox"/>
</td>
<td width="95%">
<label for="'.$identifier.'">' . $this->answer[$i] . '</label>
<label for="'.$identifier.'">' . Security::remove_XSS($this->answer[$i]) . '</label>
</td>
</tr>';
$jstmp .= $i.',';
Expand Down Expand Up @@ -539,6 +548,18 @@ function export()
$identifier = 'question_'.$this->questionJSId.'_free';
// currently the free answers cannot be displayed, so ignore the textarea
$html = '<tr><td colspan="2">';
$type = $this->getQuestionType();

if ($type == ORAL_EXPRESSION) {
$template = new Template('');
$template->assign('directory', '/tmp/');
$template->assign('user_id', api_get_user_id());

$layout = $template->get_template('document/record_audio.tpl');
$html .= $template->fetch($layout);

}

$html .= '<textarea minlength="20" name="'.$identifier.'" id="'.$identifier.'" ></textarea>';
$html .= '</td></tr>';
$js .= 'questions_answers['.$this->questionJSId.'] = new Array();';
Expand Down Expand Up @@ -679,12 +700,13 @@ public function __construct($question, $standalone = false)
*/
function start_page()
{
$charset = 'UTF-8';
$head = '';
if ($this->standalone) {
$charset = 'UTF-8';
$head = '<?xml version="1.0" encoding="'.$charset.'" standalone="no"?>';
$head .= '<html>';
}

return $head;
}

Expand Down Expand Up @@ -729,6 +751,7 @@ function css()
$css .= '/*]]>*/'."\n";
$css .= '</style>';
}

return $css;
}

Expand All @@ -749,18 +772,18 @@ function end_header()
*/
function start_js()
{
$js = '<script type="text/javascript" src="assets/api_wrapper.js"></script>';
if ($this->standalone) {
return '<script>';
}
return '';
return $js;
}

/**
* Common JS functions
*/
function common_js()
{
$js = file_get_contents('../lp/js/api_wrapper.js');
$js .= 'var questions = new Array();';
$js .= 'var questions_answers = new Array();';
$js .= 'var questions_answers_correct = new Array();';
Expand Down Expand Up @@ -842,7 +865,7 @@ function start_body()
function end_body()
{
if ($this->standalone) {
return '<br /><input type="button" id="dokeos_scorm_submit" name="dokeos_scorm_submit" value="OK" /></form></body>';
return '<br /><input class="btn" type="button" id="dokeos_scorm_submit" name="dokeos_scorm_submit" value="OK" /></form></body>';
}

return '';
Expand All @@ -858,8 +881,7 @@ function end_body()
*/
function export()
{
$js = $html = '';
list($js,$html) = $this->question->export();
list($js, $html) = $this->question->export();
if ($this->standalone) {
$res = $this->start_page()
. $this->start_header()
Expand Down Expand Up @@ -934,7 +956,7 @@ public function __construct($exe)
*/
function start_page()
{
global $charset;
$charset = 'UTF-8';
$head = '<?xml version="1.0" encoding="'.$charset.'" standalone="no"?><html>';

return $head;
Expand All @@ -960,24 +982,15 @@ function start_header()
/**
* Print CSS inclusion
*/
function css()
private function css()
{
$css = '<style type="text/css" media="screen, projection">';
$css .= '/*<![CDATA[*/'."\n";
$css .= '/*]]>*/'."\n";
$css .= '</style>'."\n";
$css .= '<style type="text/css" media="print">';
$css .= '/*<![CDATA[*/'."\n";
$css .= '/*]]>*/'."\n";
$css .= '</style>';

return $css;
return '';
}

/**
* End document header
*/
function end_header()
private function end_header()
{
return '</head>';
}
Expand All @@ -986,19 +999,18 @@ function end_header()
* Start the itemBody
*
*/
function start_js()
private function start_js()
{
return '<script>';
}

/**
* Common JS functions
*/
function common_js()
public function common_js()
{
$js = "\n";
$js .= file_get_contents('../inc/lib/javascript/hotspot/js/hotspot.js');
$js .= file_get_contents('../lp/js/api_wrapper.js');
$js = file_get_contents('../inc/lib/javascript/hotspot/js/hotspot.js');

$js .= 'var questions = new Array();' . "\n";
$js .= 'var questions_answers = new Array();' . "\n";
$js .= 'var questions_answers_correct = new Array();' . "\n";
Expand Down Expand Up @@ -1078,7 +1090,7 @@ function start_body()
*/
function end_body()
{
return '</table><br /><input type="button" id="dokeos_scorm_submit" name="dokeos_scorm_submit" value="OK" /></form></body>';
return '</table><br /><input class="btn btn-primary" type="button" id="dokeos_scorm_submit" name="dokeos_scorm_submit" value="OK" /></form></body>';
}

/**
Expand All @@ -1103,6 +1115,7 @@ function export()
$res = $this->start_page()
. $this->start_header()
. $this->css()
. $this->globalAssets()
. $this->start_js()
. $this->common_js()
. $js
Expand All @@ -1116,6 +1129,18 @@ function export()
return $res;
}

/**
* @return string
*/
private function globalAssets()
{
$assets = '<script type="text/javascript" src="assets/jquery/jquery.min.js"></script>';
$assets .= '<script type="text/javascript" src="assets/api_wrapper.js"></script>';
$assets .= '<link href="assets/bootstrap/bootstrap.min.css" rel="stylesheet" media="screen" type="text/css" />';

return $assets;
}

/**
* Export the questions, as a succession of <items>
* @author Amand Tihon <amand@alrj.org>
Expand All @@ -1125,7 +1150,7 @@ function export_questions()
$js = $html = "";
$js_id = 0;
foreach ($this->exercise->selectQuestionList() as $q) {
list($jstmp,$htmltmp)= ScormQuestion::export_question($q, false, $js_id);
list($jstmp, $htmltmp)= ScormQuestion::export_question($q, false, $js_id);
$js .= $jstmp."\n";
$html .= $htmltmp."\n";
++$js_id;
Expand Down
2 changes: 1 addition & 1 deletion main/inc/lib/exercise.lib.php
Expand Up @@ -105,7 +105,6 @@ public static function showQuestion(
// suggestions here, for the sake of comprehensions, while the ones
// on the right side are called answers
$num_suggestions = 0;

if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
if ($answerType == DRAGGABLE) {
$s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
Expand Down Expand Up @@ -319,6 +318,7 @@ public static function showQuestion(
}

$answer = Security::remove_XSS($answer, STUDENT);

$s .= Display::input(
'hidden',
'choice2[' . $questionId . ']',
Expand Down
14 changes: 4 additions & 10 deletions main/lp/learnpath.class.php
Expand Up @@ -9955,16 +9955,10 @@ public function scorm_export()

// Add the extra files that go along with a SCORM package.
$main_code_path = api_get_path(SYS_CODE_PATH) . 'lp/packaging/';
$extra_files = scandir($main_code_path);
foreach ($extra_files as $extra_file) {
if (strpos($extra_file, '.') === 0) {
continue;
} else {
$dest_file = $archive_path.$temp_dir_short.'/'.$extra_file;
$this->create_path($dest_file);
copy($main_code_path.$extra_file, $dest_file);
}
}

$fs = new \Symfony\Component\Filesystem\Filesystem;
$fs->mirror($main_code_path, $archive_path.$temp_dir_short);


// Finalize the imsmanifest structure, add to the zip, then return the zip.

Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions main/lp/packaging/assets/bootstrap/bootstrap.min.css

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions main/lp/packaging/assets/jquery/jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main/template/default/document/record_audio.tpl
Expand Up @@ -54,7 +54,7 @@
</div>

<script>
$(document).on('ready', function () {
$(document).on('ready', function() {
function useRecordRTC() {
$('#record-audio-recordrtc').show();
Expand Down

0 comments on commit 8e340ef

Please sign in to comment.