Minor corrections

skala
Julio Montoya 13 years ago
parent e0266911cc
commit 478ea23236
  1. 6
      main/exercice/answer.class.php
  2. 46
      main/exercice/export/exercise_import.inc.php
  3. 4
      main/exercice/qti2.php

@ -487,6 +487,7 @@ class Answer {
$sql.="($c_id, '$i','$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),"; $sql.="($c_id, '$i','$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),";
} }
$sql = api_substr($sql,0,-1); $sql = api_substr($sql,0,-1);
Database::query($sql); Database::query($sql);
// moves $new_* arrays // moves $new_* arrays
@ -526,7 +527,7 @@ class Answer {
//Selecting origin options //Selecting origin options
$origin_options = Question::readQuestionOption($this->selectQuestionId(), $course_info['real_id']); $origin_options = Question::readQuestionOption($this->selectQuestionId(), $course_info['real_id']);
//var_dump($origin_options);
if (!empty($origin_options)) { if (!empty($origin_options)) {
foreach($origin_options as $item) { foreach($origin_options as $item) {
$new_option_list[]=$item['id']; $new_option_list[]=$item['id'];
@ -541,8 +542,7 @@ class Answer {
$fixed_list[$new_option_list[$i]] = $item['id']; $fixed_list[$new_option_list[$i]] = $item['id'];
$i++; $i++;
} }
} }
//var_dump($fixed_list);
} }
// if at least one answer // if at least one answer

@ -83,12 +83,12 @@ function import_exercise($file) {
// set some default values for the new exercise // set some default values for the new exercise
$exercise_info = array (); $exercise_info = array ();
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file); $exercise_info['name'] = preg_replace('/.zip$/i', '', $file);
$exercise_info['question'] = array (); $exercise_info['question'] = array();
$element_pile = array (); $element_pile = array ();
// create parser and array to retrieve info from manifest // create parser and array to retrieve info from manifest
$element_pile = array (); //pile to known the depth in which we are $element_pile = array (); //pile to known the depth in which we are
$module_info = array (); //array to store the info we need //$module_info = array (); //array to store the info we need
// if file is not a .zip, then we cancel all // if file is not a .zip, then we cancel all
if (!preg_match('/.zip$/i', $file)) { if (!preg_match('/.zip$/i', $file)) {
@ -107,7 +107,7 @@ function import_exercise($file) {
//$question_number = 0; //$question_number = 0;
$file_found = false; $file_found = false;
$operation = false; $operation = false;
$result = false;
// parse every subdirectory to search xml question files // parse every subdirectory to search xml question files
while (false !== ($file = readdir($exerciseHandle))) { while (false !== ($file = readdir($exerciseHandle))) {
if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") { if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
@ -115,30 +115,32 @@ function import_exercise($file) {
$questionHandle = opendir($baseWorkDir . '/' . $file); $questionHandle = opendir($baseWorkDir . '/' . $file);
while (false !== ($questionFile = readdir($questionHandle))) { while (false !== ($questionFile = readdir($questionHandle))) {
if (preg_match('/.xml$/i', $questionFile)) { if (preg_match('/.xml$/i', $questionFile)) {
parse_file($baseWorkDir, $file, $questionFile); $result = parse_file($baseWorkDir, $file, $questionFile);
$file_found = true; $file_found = true;
} }
} }
} } elseif (preg_match('/.xml$/i', $file)) {
elseif (preg_match('/.xml$/i', $file)) { $result = parse_file($baseWorkDir, '', $file);
parse_file($baseWorkDir, '', $file);
$file_found = true; $file_found = true;
} // else ignore file } // else ignore file
} }
if (!$file_found) { if (!$file_found) {
Display :: display_error_message(get_lang('No XML file found in the zip')); Display :: display_error_message(get_lang('No XML file found in the zip'));
return false; return false;
} }
if ($result == false ) {
return false;
}
//add exercise in tool //add exercise in tool
//1.create exercise //1.create exercise
$exercise = new Exercise(); $exercise = new Exercise();
$exercise->exercise = $exercise_info['name']; $exercise->exercise = $exercise_info['name'];
$exercise->save(); $exercise->save();
$last_exercise_id = $exercise->selectId(); $last_exercise_id = $exercise->selectId();
if (!empty ($last_exercise_id)) { if (!empty($last_exercise_id)) {
//For each question found... //For each question found...
foreach ($exercise_info['question'] as $key => $question_array) { foreach ($exercise_info['question'] as $key => $question_array) {
//2.create question //2.create question
@ -172,7 +174,7 @@ function import_exercise($file) {
// delete the temp dir where the exercise was unzipped // delete the temp dir where the exercise was unzipped
my_delete($baseWorkDir . $uploadPath); my_delete($baseWorkDir . $uploadPath);
$operation = true; $operation = true;
} }
return $operation; return $operation;
} }
@ -414,12 +416,12 @@ function startElement($parser, $name, $attributes) {
//retrieve answers id for MCUA and MCMA questions //retrieve answers id for MCUA and MCMA questions
case 'SIMPLECHOICE' : case 'SIMPLECHOICE' :
{
$current_answer_id = $attributes['IDENTIFIER']; $current_answer_id = $attributes['IDENTIFIER'];
if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) { if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array (); $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array ();
} }
}
break; break;
case 'MAPENTRY' : case 'MAPENTRY' :
@ -526,16 +528,15 @@ function elementData($parser, $data) {
if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) { if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
$current_question_item_body .= $data; $current_question_item_body .= $data;
} }
switch ($current_element) { switch ($current_element) {
case 'SIMPLECHOICE' : case 'SIMPLECHOICE' :
{
if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) { if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data); $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data);
} else { } else {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ''.trim($data); $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ''.trim($data);
} }
}
break; break;
case 'FEEDBACKINLINE' : case 'FEEDBACKINLINE' :
@ -593,5 +594,4 @@ function elementData($parser, $data) {
} }
break; break;
} }
} }
?>

@ -70,9 +70,9 @@ function ch_qti2_import_file($array_file) {
require_once $main_path.'exercice/export/qti2/qti2_classes.php'; require_once $main_path.'exercice/export/qti2/qti2_classes.php';
$imported = import_exercise($array_file['name']); $imported = import_exercise($array_file['name']);
if ($imported) { if ($imported) {
header('Location: exercice.php?' . Security::remove_XSS(api_get_cidreq()) .''); header('Location: exercice.php?'.api_get_cidreq());
} else { } else {
Display::display_error_message(get_lang('The import was not performed')); Display::display_error_message(get_lang('UplNoFileUploaded'));
return false; return false;
} }
} }

Loading…
Cancel
Save