Minor - Code styling - refs CT#7504

1.10.x
Yannick Warnier 11 years ago
parent 29fdac74c2
commit 61c2faec8c
  1. 46
      main/exercice/export/exercise_import.inc.php

@ -13,7 +13,6 @@
/** /**
* function to create a temporary directory (SAME AS IN MODULE ADMIN) * function to create a temporary directory (SAME AS IN MODULE ADMIN)
*/ */
function tempdir($dir, $prefix = 'tmp', $mode = 0777) function tempdir($dir, $prefix = 'tmp', $mode = 0777)
{ {
if (substr($dir, -1) != '/') { if (substr($dir, -1) != '/') {
@ -28,12 +27,11 @@ function tempdir($dir, $prefix = 'tmp', $mode = 0777)
} }
/** /**
* the path of the temporary directory where the exercise was uploaded and unzipped * Unzip the exercise in the temp folder
* @param string * @param string The path of the temporary directory where the exercise was uploaded and unzipped
* @param string * @param string
* @return bool * @return bool
*/ */
function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)
{ {
$_course = api_get_course_info(); $_course = api_get_course_info();
@ -63,11 +61,10 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)
} }
/** /**
* Imports an exercise, * Imports an exercise in QTI format if the XML structure can be found in it
* @param array $file * @param array $file
* @return an array as a backlog of what was really imported, and error or debug messages to display * @return an array as a backlog of what was really imported, and error or debug messages to display
*/ */
function import_exercise($file) function import_exercise($file)
{ {
global $exercise_info; global $exercise_info;
@ -217,6 +214,13 @@ function formatText($text)
return api_html_entity_decode($text); return api_html_entity_decode($text);
} }
/**
* Parses a given XML file and fills global arrays with the elements
* @param $exercisePath
* @param $file
* @param $questionFile
* @return bool
*/
function parse_file($exercisePath, $file, $questionFile) function parse_file($exercisePath, $file, $questionFile)
{ {
global $exercise_info; global $exercise_info;
@ -272,10 +276,14 @@ function parse_file($exercisePath, $file, $questionFile)
//close file //close file
fclose($fp); fclose($fp);
if (!$question_format_supported) { if (!$question_format_supported) {
Display:: display_error_message(get_lang('Unknown question format in file %file', Display:: display_error_message(
get_lang(
'Unknown question format in file %file',
array( array(
'%file' => $questionFile '%file' => $questionFile
))); )
)
);
return false; return false;
} }
return true; return true;
@ -288,7 +296,6 @@ function parse_file($exercisePath, $file, $questionFile)
* @param unknown_type $name name of the element * @param unknown_type $name name of the element
* @param unknown_type $attributes * @param unknown_type $attributes
*/ */
function startElement($parser, $name, $attributes) function startElement($parser, $name, $attributes)
{ {
global $element_pile; global $element_pile;
@ -436,7 +443,6 @@ function startElement($parser, $name, $attributes)
* @param $parser xml parser created with "xml_parser_create()" * @param $parser xml parser created with "xml_parser_create()"
* @param $name name of the element * @param $name name of the element
*/ */
function endElement($parser, $name) function endElement($parser, $name)
{ {
global $element_pile; global $element_pile;
@ -451,9 +457,7 @@ function endElement($parser, $name)
//treat the record of the full content of itembody tag : //treat the record of the full content of itembody tag :
if ($record_item_body && (!in_array($current_element, if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
$non_HTML_tag_to_avoid))
) {
$current_question_item_body .= "</" . $name . ">"; $current_question_item_body .= "</" . $name . ">";
} }
@ -471,9 +475,12 @@ function endElement($parser, $name)
} }
/**
* @param $parser
* @param $data
*/
function elementData($parser, $data) function elementData($parser, $data)
{ {
global $element_pile; global $element_pile;
global $exercise_info; global $exercise_info;
global $current_question_ident; global $current_question_ident;
@ -500,9 +507,7 @@ function elementData($parser, $data)
//treat the record of the full content of itembody tag (needed for question statment and/or FIB text: //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, if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
$non_HTML_tag_to_avoid))
) {
$current_question_item_body .= $data; $current_question_item_body .= $data;
} }
@ -541,8 +546,11 @@ function elementData($parser, $data)
// if this is the right answer, then we must replace the claroline tags in the FIB text bye the answer between "[" and "]" : // if this is the right answer, then we must replace the claroline tags in the FIB text bye the answer between "[" and "]" :
$answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id]; $answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
if ($current_inlinechoice_id == $answer_identifier) { if ($current_inlinechoice_id == $answer_identifier) {
$current_question_item_body = str_replace("**claroline_start**" . $current_answer_id . "**claroline_end**", $current_question_item_body = str_replace(
"[" . $data . "]", $current_question_item_body); "**claroline_start**" . $current_answer_id . "**claroline_end**",
"[" . $data . "]",
$current_question_item_body
);
} else { } else {
if (!isset ($exercise_info['question'][$current_question_ident]['wrong_answers'])) { if (!isset ($exercise_info['question'][$current_question_ident]['wrong_answers'])) {
$exercise_info['question'][$current_question_ident]['wrong_answers'] = array(); $exercise_info['question'][$current_question_ident]['wrong_answers'] = array();

Loading…
Cancel
Save