Minor corrections

skala
Julio Montoya 13 years ago
parent e0266911cc
commit 478ea23236
  1. 4
      main/exercice/answer.class.php
  2. 36
      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 = api_substr($sql,0,-1);
Database::query($sql);
// moves $new_* arrays
@ -526,7 +527,7 @@ class Answer {
//Selecting origin options
$origin_options = Question::readQuestionOption($this->selectQuestionId(), $course_info['real_id']);
//var_dump($origin_options);
if (!empty($origin_options)) {
foreach($origin_options as $item) {
$new_option_list[]=$item['id'];
@ -542,7 +543,6 @@ class Answer {
$i++;
}
}
//var_dump($fixed_list);
}
// if at least one answer

@ -83,12 +83,12 @@ function import_exercise($file) {
// set some default values for the new exercise
$exercise_info = array ();
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file);
$exercise_info['question'] = array ();
$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
$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 (!preg_match('/.zip$/i', $file)) {
@ -107,7 +107,7 @@ function import_exercise($file) {
//$question_number = 0;
$file_found = false;
$operation = false;
$result = false;
// parse every subdirectory to search xml question files
while (false !== ($file = readdir($exerciseHandle))) {
if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
@ -115,30 +115,32 @@ function import_exercise($file) {
$questionHandle = opendir($baseWorkDir . '/' . $file);
while (false !== ($questionFile = readdir($questionHandle))) {
if (preg_match('/.xml$/i', $questionFile)) {
parse_file($baseWorkDir, $file, $questionFile);
$result = parse_file($baseWorkDir, $file, $questionFile);
$file_found = true;
}
}
}
elseif (preg_match('/.xml$/i', $file)) {
parse_file($baseWorkDir, '', $file);
} elseif (preg_match('/.xml$/i', $file)) {
$result = parse_file($baseWorkDir, '', $file);
$file_found = true;
} // else ignore file
}
if (!$file_found) {
Display :: display_error_message(get_lang('No XML file found in the zip'));
return false;
}
if ($result == false ) {
return false;
}
//add exercise in tool
//1.create exercise
$exercise = new Exercise();
$exercise->exercise = $exercise_info['name'];
$exercise->save();
$last_exercise_id = $exercise->selectId();
if (!empty ($last_exercise_id)) {
if (!empty($last_exercise_id)) {
//For each question found...
foreach ($exercise_info['question'] as $key => $question_array) {
//2.create question
@ -414,12 +416,12 @@ function startElement($parser, $name, $attributes) {
//retrieve answers id for MCUA and MCMA questions
case 'SIMPLECHOICE' :
{
$current_answer_id = $attributes['IDENTIFIER'];
if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array ();
}
}
$current_answer_id = $attributes['IDENTIFIER'];
if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array ();
}
break;
case 'MAPENTRY' :
@ -529,13 +531,12 @@ function elementData($parser, $data) {
switch ($current_element) {
case 'SIMPLECHOICE' :
{
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);
} else {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ''.trim($data);
}
}
break;
case 'FEEDBACKINLINE' :
@ -594,4 +595,3 @@ function elementData($parser, $data) {
break;
}
}
?>

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

Loading…
Cancel
Save