From 187f5364d18318ee37cd74a46db94d2876f66cdf Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sun, 11 Sep 2016 20:47:37 -0500 Subject: [PATCH] Add support for test description in IMS/QTIv2 import - refs GH#1377 --- main/exercise/export/exercise_import.inc.php | 40 ++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/main/exercise/export/exercise_import.inc.php b/main/exercise/export/exercise_import.inc.php index d91bdd81b8..a4380300f5 100755 --- a/main/exercise/export/exercise_import.inc.php +++ b/main/exercise/export/exercise_import.inc.php @@ -161,6 +161,9 @@ function import_exercise($file) // 1. Create exercise. $exercise = new Exercise(); $exercise->exercise = $exercise_info['name']; + if (!empty($exercise_info['description'])) { + $exercise->updateDescription($exercise_info['description']); + } $exercise->save(); $last_exercise_id = $exercise->selectId(); @@ -363,11 +366,6 @@ function startElementQti2($parser, $name, $attributes) } else { $parent_element = ""; } - if (sizeof($element_pile) >= 3) { - $grant_parent_element = $element_pile[sizeof($element_pile) - 3]; - } else { - $grant_parent_element = ""; - } if ($record_item_body) { @@ -498,7 +496,23 @@ function endElementQti2($parser, $name) global $non_HTML_tag_to_avoid; global $cardinality; + array_push($element_pile, $name); $current_element = end($element_pile); + if (sizeof($element_pile) >= 2) { + $parent_element = $element_pile[sizeof($element_pile) - 2]; + } else { + $parent_element = ""; + } + if (sizeof($element_pile) >= 3) { + $grand_parent_element = $element_pile[sizeof($element_pile) - 3]; + } else { + $grand_parent_element = ""; + } + if (sizeof($element_pile) >= 4) { + $great_grand_parent_element = $element_pile[sizeof($element_pile) - 4]; + } else { + $great_grand_parent_element = ""; + } //treat the record of the full content of itembody tag : @@ -545,9 +559,14 @@ function elementDataQti2($parser, $data) $parent_element = ""; } if (sizeof($element_pile) >= 3) { - $grant_parent_element = $element_pile[sizeof($element_pile) - 3]; + $grand_parent_element = $element_pile[sizeof($element_pile) - 3]; } else { - $grant_parent_element = ""; + $grand_parent_element = ""; + } + if (sizeof($element_pile) >= 4) { + $great_grand_parent_element = $element_pile[sizeof($element_pile) - 4]; + } else { + $great_grand_parent_element = ""; } //treat the record of the full content of itembody tag (needed for question statment and/or FIB text: @@ -609,6 +628,13 @@ function elementDataQti2($parser, $data) $exercise_info['question'][$current_question_ident]['wrong_answers'][] = $data; } break; + case 'MATTEXT': + if ($grand_parent_element == 'FLOW_MAT' && ($great_grand_parent_element == 'PRESENTATION_MATERIAL' || $great_grand_parent_element == 'SECTION')) { + if (!empty(trim($data))) { + $exercise_info['description'] = $data; + } + } + } }