Skip to content

Commit

Permalink
Fix qti import (no score saved) see BT#12777
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 7, 2017
1 parent a641c4b commit 27dda90
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions main/exercise/export/exercise_import.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)
return false;
}

if (preg_match('/.zip$/i', $_FILES['userFile']['name']) &&
handle_uploaded_document(
if (preg_match('/.zip$/i', $_FILES['userFile']['name'])) {
$result = handle_uploaded_document(
$_course,
$_FILES['userFile'],
$baseWorkDir,
Expand All @@ -46,9 +46,8 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)
null,
null,
false
)
) {
return true;
);
return $result;
}
return false;
}
Expand Down Expand Up @@ -85,7 +84,6 @@ function import_exercise($file)
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file);
$exercise_info['question'] = array();
$element_pile = array();

// create parser and array to retrieve info from manifest
$element_pile = array(); //pile to known the depth in which we are

Expand Down Expand Up @@ -178,7 +176,6 @@ function import_exercise($file)
$last_exercise_id = $exercise->selectId();
$courseId = api_get_course_int_id();
if (!empty($last_exercise_id)) {
//var_dump($exercise_info);exit;
// For each question found...
foreach ($exercise_info['question'] as $question_array) {
//2. Create question
Expand Down Expand Up @@ -253,13 +250,15 @@ function import_exercise($file)
} else {
$answer->new_correct[$i] = 0;
}

if (isset($question_array['weighting'][$key])) {
$answer->new_weighting[$i] = $question_array['weighting'][$key];
}
if ($answer->new_correct[$i]) {
$totalCorrectWeight += $answer->new_weighting[$i];
}
}

$question->updateWeighting($totalCorrectWeight);
$question->save($exercise);
$answer->save();
Expand Down Expand Up @@ -616,7 +615,6 @@ function elementDataQti2($parser, $data)
}

//treat the record of the full content of itembody tag (needed for question statment and/or FIB text:

if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
$current_question_item_body .= $data;
}
Expand All @@ -640,9 +638,10 @@ function elementDataQti2($parser, $data)
$exercise_info['question'][$current_question_ident]['answer'][$current_match_set][$currentAssociableChoice] = trim($data);
break;
case 'VALUE':
if ($parent_element == "CORRECTRESPONSE") {
if ($cardinality == "single") {
$exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id] = $data;
if ($parent_element == 'CORRECTRESPONSE') {
if ($cardinality == 'single') {
//$exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id] = $data;
$exercise_info['question'][$current_question_ident]['correct_answers'][$data] = $data;
} else {
$exercise_info['question'][$current_question_ident]['correct_answers'][] = $data;
}
Expand Down Expand Up @@ -1017,6 +1016,8 @@ function isQtiQuestionBank($filePath)
$data = file_get_contents($filePath);
if (!empty($data)) {
$match = preg_match('/ims_qtiasiv(\d)p(\d)/', $data);
//$match2 = preg_match('/imsqti_v(\d)p(\d)/', $data);

if ($match) {
return true;
}
Expand Down

0 comments on commit 27dda90

Please sign in to comment.