diff --git a/lang/en/logstore_xapi.php b/lang/en/logstore_xapi.php index 77b33ee8c..e922c8e9a 100644 --- a/lang/en/logstore_xapi.php +++ b/lang/en/logstore_xapi.php @@ -48,6 +48,6 @@ $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.'; diff --git a/src/transformer/events/mod_quiz/question_answered/gapselect.php b/src/transformer/events/mod_quiz/question_answered/gapselect.php index d2164e90f..faf5a35f9 100644 --- a/src/transformer/events/mod_quiz/question_answered/gapselect.php +++ b/src/transformer/events/mod_quiz/question_answered/gapselect.php @@ -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' => [ diff --git a/src/transformer/events/mod_quiz/question_answered/multichoice.php b/src/transformer/events/mod_quiz/question_answered/multichoice.php index 3cf6751cd..696964b5e 100644 --- a/src/transformer/events/mod_quiz/question_answered/multichoice.php +++ b/src/transformer/events/mod_quiz/question_answered/multichoice.php @@ -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' => [ diff --git a/src/transformer/utils/get_multichoice_definition.php b/src/transformer/utils/get_multichoice_definition.php index 0f0365bb5..f779e1216 100644 --- a/src/transformer/utils/get_multichoice_definition.php +++ b/src/transformer/utils/get_multichoice_definition.php @@ -18,7 +18,7 @@ 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 ]; } diff --git a/tests/mod_quiz/attempt_submitted/gapselect/statements.json b/tests/mod_quiz/attempt_submitted/gapselect/statements.json index d340379fb..b0c9bc946 100644 --- a/tests/mod_quiz/attempt_submitted/gapselect/statements.json +++ b/tests/mod_quiz/attempt_submitted/gapselect/statements.json @@ -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": { diff --git a/tests/mod_quiz/attempt_submitted/multichoiceset/statements.json b/tests/mod_quiz/attempt_submitted/multichoiceset/statements.json index dac2fa320..0b47d90b5 100644 --- a/tests/mod_quiz/attempt_submitted/multichoiceset/statements.json +++ b/tests/mod_quiz/attempt_submitted/multichoiceset/statements.json @@ -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": { diff --git a/tests/mod_quiz/attempt_submitted/multichoiceset_withchoices/statements.json b/tests/mod_quiz/attempt_submitted/multichoiceset_withchoices/statements.json index bf6d4323d..05885f6ae 100644 --- a/tests/mod_quiz/attempt_submitted/multichoiceset_withchoices/statements.json +++ b/tests/mod_quiz/attempt_submitted/multichoiceset_withchoices/statements.json @@ -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": {