Skip to content
Snippets Groups Projects
Commit 68b16e30 authored by Andrew Downes's avatar Andrew Downes Committed by Ryan Smith
Browse files

fix: Corrects response formatting for multichoice questions to fix #440. (#447 - Thanks @garemoko)

parent 0d9f8336
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,6 @@ $string['shortcourseid_desc'] = 'Statements will contain the shortname for a cou
$string['sendidnumber'] = 'Send course and activity ID number';
$string['sendidnumber_desc'] = 'Statements will include the ID number (admin defined) for courses and activities in the object extensions';
$string['send_response_choices'] = 'Send response choices';
$string['send_response_choices_desc'] = 'Statements for multiple choice question answers will be sent to the LRS with the correct response and potential choices';
$string['send_response_choices_desc'] = 'Statements for multiple choice and sequencing question answers will be sent to the LRS with the correct response and potential choices';
$string['resendfailedbatches'] = 'Resend failed batches';
$string['resendfailedbatches_desc'] = 'When processing events in batches, try re-sending events in smaller batches if a batch fails. If not selected, the whole batch will not be sent in the event of a failed event.';
......@@ -40,17 +40,11 @@ function gapselect(array $config, \stdClass $event, \stdClass $questionattempt,
],
'object' => [
'id' => utils\get_quiz_question_id($config, $coursemodule->id, $question->id),
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => utils\get_string_html_removed($question->questiontext)
],
'interactionType' => 'sequencing',
]
'definition' => utils\get_multichoice_definition($config, $questionattempt, $question, $lang, 'sequencing'),
],
'timestamp' => utils\get_event_timestamp($event),
'result' => [
'response' => $questionattempt->responsesummary,
'response' => implode ('[,]', $selections),
'completion' => $questionattempt->responsesummary !== null,
'success' => $questionattempt->rightanswer === $questionattempt->responsesummary,
'extensions' => [
......
......@@ -27,6 +27,7 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
$selections = explode('; ', utils\get_string_html_removed($questionattempt->responsesummary));
return [[
'actor' => utils\get_user($config, $user),
'verb' => [
......@@ -41,7 +42,7 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt
],
'timestamp' => utils\get_event_timestamp($event),
'result' => [
'response' => utils\get_string_html_removed($questionattempt->responsesummary),
'response' => implode ('[,]', $selections),
'success' => $questionattempt->rightanswer == $questionattempt->responsesummary,
'completion' => $questionattempt->responsesummary !== '',
'extensions' => [
......
......@@ -18,7 +18,7 @@ namespace src\transformer\utils;
use src\transformer\utils as utils;
defined('MOODLE_INTERNAL') || die();
function get_multichoice_definition(array $config, \stdClass $questionattempt, \stdClass $question, $lang) {
function get_multichoice_definition(array $config, \stdClass $questionattempt, \stdClass $question, $lang, $interactiontype = 'choice') {
if ($config['send_response_choices']) {
$repo = $config['repo'];
$answers = $repo->read_records('question_answers', [
......@@ -32,15 +32,26 @@ function get_multichoice_definition(array $config, \stdClass $questionattempt, \
]
];
}, $answers);
$correctresponsepattern;
switch ($interactiontype) {
case 'sequencing':
$selections = explode('} {', rtrim(ltrim($questionattempt->rightanswer, '{'), '}'));
$correctresponsepattern = implode ('[,]', $selections);
break;
default:
$selections = explode('; ', utils\get_string_html_removed($questionattempt->rightanswer));
$correctresponsepattern = implode ('[,]', $selections);
break;
}
return [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => utils\get_string_html_removed($question->questiontext),
],
'interactionType' => 'choice',
'correctResponsesPattern' => [
utils\get_string_html_removed($questionattempt->rightanswer),
],
'interactionType' => $interactiontype,
'correctResponsesPattern' => [$correctresponsepattern],
// Need to pull out id's that are appended during array_map so json parses it correctly as an array.
'choices' => array_values($choices)
];
......@@ -51,6 +62,6 @@ function get_multichoice_definition(array $config, \stdClass $questionattempt, \
'name' => [
$lang => utils\get_string_html_removed($question->questiontext),
],
'interactionType' => 'choice'
'interactionType' => $interactiontype
];
}
......@@ -117,7 +117,7 @@
},
"timestamp": "2015-06-10T15:31:41+01:00",
"result": {
"response": "{spicy} {mango} {milkshake}",
"response": "spicy[,]mango[,]milkshake",
"completion": true,
"success": true,
"extensions": {
......
......@@ -117,7 +117,7 @@
},
"timestamp": "2015-06-10T15:31:41+01:00",
"result": {
"response": "answer 1; answer 2",
"response": "answer 1[,]answer 2",
"success": true,
"completion": true,
"extensions": {
......
......@@ -114,7 +114,7 @@
},
"interactionType": "choice",
"correctResponsesPattern": [
"answer 1; answer 2"
"answer 1[,]answer 2"
],
"choices": [
{
......@@ -140,7 +140,7 @@
},
"timestamp": "2015-06-10T15:31:41+01:00",
"result": {
"response": "answer 1; answer 2",
"response": "answer 1[,]answer 2",
"success": true,
"completion": true,
"extensions": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment