Skip to content

Commit

Permalink
Moodle import: Fix question creation multichoice is now MULTIPLE_ANSWER
Browse files Browse the repository at this point in the history
Instead of UNIQUE_ANSWER see BT#18172
  • Loading branch information
jmontoyaa committed Jan 13, 2021
1 parent 93e1094 commit b6b57d2
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions main/inc/lib/MoodleImport.php
Expand Up @@ -282,9 +282,7 @@ public function import($uploadedFile)
error_log('question: '.$question['questionid']);
}

$questionInstance->updateTitle(
$moduleValues['question_instances'][$index]['name']
);
$questionInstance->updateTitle($moduleValues['question_instances'][$index]['name']);
$questionText = $moduleValues['question_instances'][$index]['questiontext'];

// Replace the path from @@PLUGINFILE@@ to a correct chamilo path
Expand Down Expand Up @@ -699,7 +697,7 @@ public function matchMoodleChamiloQuestionTypes($moodleQuestionType)
{
switch ($moodleQuestionType) {
case 'multichoice':
return UNIQUE_ANSWER;
return MULTIPLE_ANSWER;
case 'multianswer':
case 'shortanswer':
case 'match':
Expand Down Expand Up @@ -759,7 +757,7 @@ public function processAnswers(
$objAnswer = new Answer($questionInstance->id);
$questionWeighting = 0;
foreach ($questionList as $slot => $answer) {
$this->processUniqueAnswer(
$this->processMultipleAnswer(
$objAnswer,
$answer,
$slot + 1,
Expand Down Expand Up @@ -939,6 +937,37 @@ public function processUniqueAnswer(
);
}

public function processMultipleAnswer(
Answer $objAnswer,
$answerValues,
$position,
&$questionWeighting,
$importedFiles
) {
$answer = $answerValues['answertext'];
$comment = $answerValues['feedback'];
$weighting = $answerValues['fraction'];
//$weighting = abs($weighting);
if ($weighting > 0) {
$questionWeighting += $weighting;
}
$goodAnswer = $weighting > 0;

$this->fixPathInText($importedFiles, $answer);

$objAnswer->createAnswer(
$answer,
$goodAnswer,
$comment,
$weighting,
$position,
null,
null,
''
);
}


/**
* Process Chamilo True False.
*
Expand Down

0 comments on commit b6b57d2

Please sign in to comment.