mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-51048 IMS-CC: Fix import & export of true/false questions
This commit is contained in:
parent
1dabedeedf
commit
a3f5974065
3 changed files with 46 additions and 28 deletions
|
@ -27,8 +27,18 @@ class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||||
public function __construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir) {
|
public function __construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir) {
|
||||||
parent::__construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
|
parent::__construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
|
||||||
$this->qtype = cc_qti_profiletype::true_false;
|
$this->qtype = cc_qti_profiletype::true_false;
|
||||||
$this->correct_answer_node_id = $this->questions->nodeValue(
|
|
||||||
'plugin_qtype_truefalse_question/truefalse/trueanswer', $this->question_node);
|
// Determine the correct answer by finding out which answer has the non zero fraction...
|
||||||
|
// This is because a true / false question type can have 'false' as the correct answer.
|
||||||
|
$answers = $this->questions->nodeList('plugin_qtype_truefalse_question/answers/answer', $this->question_node);
|
||||||
|
foreach ($answers as $answer) {
|
||||||
|
$fraction = $this->questions->nodeValue('fraction', $answer);
|
||||||
|
|
||||||
|
if ($fraction != 0) {
|
||||||
|
$this->correct_answer_node_id = (int)$this->questions->nodeValue('@id', $answer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$maximum_quiz_grade = (int)$this->quiz->nodeValue('/activity/quiz/grade');
|
$maximum_quiz_grade = (int)$this->quiz->nodeValue('/activity/quiz/grade');
|
||||||
$this->total_grade_value = ($maximum_quiz_grade + 1).'.0000000';
|
$this->total_grade_value = ($maximum_quiz_grade + 1).'.0000000';
|
||||||
}
|
}
|
||||||
|
|
|
@ -886,26 +886,30 @@ class cc_quiz extends entities {
|
||||||
$sheet_question_categories_question = cc2moodle::loadsheet(SHEET_COURSE_QUESTION_CATEGORIES_QUESTION_CATEGORY_QUESTION_TRUE_FALSE);
|
$sheet_question_categories_question = cc2moodle::loadsheet(SHEET_COURSE_QUESTION_CATEGORIES_QUESTION_CATEGORY_QUESTION_TRUE_FALSE);
|
||||||
|
|
||||||
$max_score = 0;
|
$max_score = 0;
|
||||||
$true_answer_id = 0;
|
$trueanswer = null;
|
||||||
$false_answer_id = 0;
|
$falseanswer = null;
|
||||||
|
|
||||||
if (!empty($question['answers'])) {
|
if (!empty($question['answers'])) {
|
||||||
|
|
||||||
|
// Identify the true and false answers.
|
||||||
foreach ($question['answers'] as $answer) {
|
foreach ($question['answers'] as $answer) {
|
||||||
if ($answer['score'] > $max_score) {
|
if ($answer['identifier'] == 'true') {
|
||||||
$max_score = $answer['score'];
|
$trueanswer = $answer;
|
||||||
$true_answer_id = $answer['id'];
|
} else if ($answer['identifier'] == 'false') {
|
||||||
|
$falseanswer = $answer;
|
||||||
|
} else {
|
||||||
|
// Should not happen, but just in case.
|
||||||
|
throw new coding_exception("Unknown answer identifier detected" .
|
||||||
|
" in true/false quiz question with id {$question['id']}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$node_course_question_categories_question_answer .= $this->create_node_course_question_categories_question_category_question_answer($answer);
|
$node_course_question_categories_question_answer .= $this->create_node_course_question_categories_question_category_question_answer($answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($question['answers'] as $answer) {
|
// Make sure the true and false answer was found.
|
||||||
|
if (is_null($trueanswer) || is_null($falseanswer)) {
|
||||||
if ($answer['id'] != $true_answer_id) {
|
throw new coding_exception("Unable to correctly identify the " .
|
||||||
$max_score = $answer['score'];
|
"true and false answers in the question with id {$question['id']}.");
|
||||||
$false_answer_id = $answer['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,8 +918,8 @@ class cc_quiz extends entities {
|
||||||
'[#false_answer_id#]');
|
'[#false_answer_id#]');
|
||||||
|
|
||||||
$replace_values = array($node_course_question_categories_question_answer,
|
$replace_values = array($node_course_question_categories_question_answer,
|
||||||
$true_answer_id,
|
$trueanswer['id'],
|
||||||
$false_answer_id);
|
$falseanswer['id']);
|
||||||
|
|
||||||
$node_question_categories_question = str_replace($find_tags, $replace_values, $sheet_question_categories_question);
|
$node_question_categories_question = str_replace($find_tags, $replace_values, $sheet_question_categories_question);
|
||||||
|
|
||||||
|
|
|
@ -909,26 +909,30 @@ class cc11_quiz extends entities11 {
|
||||||
$sheet_question_categories_question = cc112moodle::loadsheet(SHEET_COURSE_QUESTION_CATEGORIES_QUESTION_CATEGORY_QUESTION_TRUE_FALSE);
|
$sheet_question_categories_question = cc112moodle::loadsheet(SHEET_COURSE_QUESTION_CATEGORIES_QUESTION_CATEGORY_QUESTION_TRUE_FALSE);
|
||||||
|
|
||||||
$max_score = 0;
|
$max_score = 0;
|
||||||
$true_answer_id = 0;
|
$trueanswer = null;
|
||||||
$false_answer_id = 0;
|
$falseanswer = null;
|
||||||
|
|
||||||
if (!empty($question['answers'])) {
|
if (!empty($question['answers'])) {
|
||||||
|
|
||||||
|
// Identify the true and false answers.
|
||||||
foreach ($question['answers'] as $answer) {
|
foreach ($question['answers'] as $answer) {
|
||||||
if ($answer['score'] > $max_score) {
|
if ($answer['identifier'] == 'true') {
|
||||||
$max_score = $answer['score'];
|
$trueanswer = $answer;
|
||||||
$true_answer_id = $answer['id'];
|
} else if ($answer['identifier'] == 'false') {
|
||||||
|
$falseanswer = $answer;
|
||||||
|
} else {
|
||||||
|
// Should not happen, but just in case.
|
||||||
|
throw new coding_exception("Unknown answer identifier detected " .
|
||||||
|
"in true/false quiz question with id {$question['id']}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$node_course_question_categories_question_answer .= $this->create_node_course_question_categories_question_category_question_answer($answer);
|
$node_course_question_categories_question_answer .= $this->create_node_course_question_categories_question_category_question_answer($answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($question['answers'] as $answer) {
|
// Make sure the true and false answer was found.
|
||||||
|
if (is_null($trueanswer) || is_null($falseanswer)) {
|
||||||
if ($answer['id'] != $true_answer_id) {
|
throw new coding_exception("Unable to correctly identify the " .
|
||||||
$max_score = $answer['score'];
|
"true and false answers in the question with id {$question['id']}.");
|
||||||
$false_answer_id = $answer['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -937,8 +941,8 @@ class cc11_quiz extends entities11 {
|
||||||
'[#false_answer_id#]');
|
'[#false_answer_id#]');
|
||||||
|
|
||||||
$replace_values = array($node_course_question_categories_question_answer,
|
$replace_values = array($node_course_question_categories_question_answer,
|
||||||
$true_answer_id,
|
$trueanswer['id'],
|
||||||
$false_answer_id);
|
$falseanswer['id']);
|
||||||
|
|
||||||
$node_question_categories_question = str_replace($find_tags, $replace_values, $sheet_question_categories_question);
|
$node_question_categories_question = str_replace($find_tags, $replace_values, $sheet_question_categories_question);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue