Skip to content
Permalink
Browse files

Add "SCORE" support in aiken see BT#15232

Example:

question 1
A. answer 1
B. answer 2
C. answer 3
ANSWER: B
SCORE: 20
  • Loading branch information...
jmontoyaa committed Jan 23, 2019
1 parent 90b5705 commit 63fde0cd836dd8d5406bd7759251577dd3c6985c
Showing with 21 additions and 3 deletions.
  1. +2 −2 main/exercise/aiken.php
  2. +19 −1 main/exercise/export/aiken/aiken_import.inc.php
@@ -27,8 +27,8 @@
// the breadcrumbs
$interbreadcrumb[] = [
"url" => 'exercise.php?'.api_get_cidreq(),
"name" => get_lang('Exercises'),
'url' => 'exercise.php?'.api_get_cidreq(),
'name' => get_lang('Exercises'),
];
$is_allowedToEdit = api_is_allowed_to_edit(null, true);
// import file
@@ -200,6 +200,11 @@ function aiken_import_exercise($file)
$answer->new_nbrAnswers = count($question_array['answer']);
$max_score = 0;
$scoreFromFile = 0;
if (isset($question_array['score']) && !empty($question_array['score'])) {
$scoreFromFile = $question_array['score'];
}
foreach ($question_array['answer'] as $key => $answers) {
$key++;
$answer->new_answer[$key] = $answers['value'];
@@ -218,6 +223,14 @@ function aiken_import_exercise($file)
$answer->new_weighting[$key] = $question_array['weighting'][$key - 1];
$max_score += $question_array['weighting'][$key - 1];
}
if (!empty($scoreFromFile) && $answer->new_correct[$key]) {
$answer->new_weighting[$key] = $scoreFromFile;
}
}
if (!empty($scoreFromFile)) {
$max_score = $scoreFromFile;
}
$answer->save();
@@ -260,7 +273,6 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile)
$data = file($questionFilePath);
$question_index = 0;
$correct_answer = '';
$answers_array = [];
$new_question = true;
foreach ($data as $line => $info) {
@@ -284,6 +296,12 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile)
$exercise_info['question'][$question_index]['correct_answers'][] = $correct_answer_index + 1;
//weight for correct answer
$exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1;
} elseif (preg_match('/^SCORE:\s?(.*)/', $info, $matches)) {
//the correct answers
$correct_answer_index = array_search($matches[1], $answers_array);
$exercise_info['question'][$question_index]['score'] = (float) $matches[1];
//weight for correct answer
//$exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1;
} elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) {
//Comment of correct answer
$correct_answer_index = array_search($matches[1], $answers_array);

0 comments on commit 63fde0c

Please sign in to comment.
You can’t perform that action at this time.