Add question category when exporting and importing a question

See BT#10891
remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 8c130aa8e6
commit def203ec78
  1. 19
      main/exercise/export/exercise_import.inc.php
  2. 27
      main/exercise/export/qti2/qti2_export.php

@ -184,6 +184,24 @@ function import_exercise($file)
$question->updateTitle(formatText(substr(strip_tags($question_array['title']), 0, 50)));
$description .= $question_array['title'];
}
if (isset($question_array['category'])) {
$category = formatText(strip_tags($question_array['category']));
$categoryId = TestCategory::get_category_id_for_title(
$category,
api_get_course_int_id()
);
if (!empty($categoryId)) {
$question->category = $categoryId;
} else {
$cat = new TestCategory();
$cat->name = $category;
$cat->description = '';
$question->category = $cat->addCategoryInBDD();
}
}
if (!empty($question_array['description'])) {
$description .= $question_array['description'];
}
@ -406,6 +424,7 @@ function startElementQti2($parser, $name, $attributes)
$exercise_info['question'][$current_question_ident]['answer'] = array();
$exercise_info['question'][$current_question_ident]['correct_answers'] = array();
$exercise_info['question'][$current_question_ident]['title'] = $attributes['TITLE'];
$exercise_info['question'][$current_question_ident]['category'] = $attributes['CATEGORY'];
$exercise_info['question'][$current_question_ident]['tempdir'] = $questionTempDir;
break;
case 'SECTION':

@ -45,11 +45,22 @@ class ImsAssessmentItem
*/
function start_item()
{
$categoryTitle = '';
if (!empty($this->question->category)) {
$category = new TestCategory();
$category = $category->getCategory($this->question->category);
if ($category) {
$categoryTitle = htmlspecialchars(formatExerciseQtiTitle($category->name));
}
}
$string = '<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 imsqti_v2p1.xsd"
identifier="'.$this->questionIdent.'"
title="'.htmlspecialchars(formatExerciseQtiTitle($this->question->selectTitle())).'">'."\n";
title = "'.htmlspecialchars(formatExerciseQtiTitle($this->question->selectTitle())).'"
category = "'.$categoryTitle.'"
>'."\n";
return $string;
}
@ -161,7 +172,10 @@ class ImsSection
function start_section()
{
$out = '<section ident="EXO_' . $this->exercise->selectId() . '" title="' .cleanAttribute(formatExerciseQtiDescription($this->exercise->selectTitle())) . '">' . "\n";
$out = '<section
ident = "EXO_' . $this->exercise->selectId() . '"
title = "' .cleanAttribute(formatExerciseQtiDescription($this->exercise->selectTitle())) . '"
>' . "\n";
return $out;
}
@ -438,16 +452,17 @@ function export_question_qti($questionId, $standalone = true)
{
$question = new Ims2Question();
$qst = $question->read($questionId);
if (!$qst or $qst->type == FREE_ANSWER) {
if (!$qst || $qst->type == FREE_ANSWER) {
return '';
}
$question->id = $qst->id;
$question->type = $qst->type;
$question->question = $qst->question;
$question->description = $qst->description;
$question->weighting=$qst->weighting;
$question->position=$qst->position;
$question->picture=$qst->picture;
$question->weighting = $qst->weighting;
$question->position = $qst->position;
$question->picture = $qst->picture;
$question->category = $qst->category;
$ims = new ImsAssessmentItem($question);
return $ims->export($standalone);

Loading…
Cancel
Save