|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
?> |
|
|
|
|