Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequencing response format #447

Merged
merged 15 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lang/en/logstore_xapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function essay(array $config, \stdClass $event, \stdClass $questionattempt, \std
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext)
],
'interactionType' => 'long-fill-in',
]
Expand Down
10 changes: 2 additions & 8 deletions src/transformer/events/mod_quiz/question_answered/gapselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => $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' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ($reduction, $selection) {
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext)
],
'interactionType' => 'matching',
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function numerical(array $config, \stdClass $event, \stdClass $questionattempt,
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext)
],
'interactionType' => 'numeric',
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ($reduction, $selection) {
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext)
],
'interactionType' => 'matching',
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function shortanswer(array $config, \stdClass $event, \stdClass $questionattempt
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext)
],
'interactionType' => 'fill-in',
]
Expand Down
22 changes: 16 additions & 6 deletions src/transformer/utils/get_multichoice_definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -32,15 +32,25 @@ 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:
$correctresponsepattern = utils\get_string_html_removed($questionattempt->rightanswer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do choices also need to be imploded in the same way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I don't think so because I think the multi-choice question is only one option.

That would be out of scope for this PR anyway. The goal here is to preserve the behavior of the multi-choice question while changing the gap select one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to do this for multichoice too because this is also an issue for multichoiceset questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since you insist, I fixed for multichoice questions where there are multiple correct answers too. :-)

Waiting for tests to run....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha okay thanks Andrew 👍 looks good

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)
];
Expand All @@ -51,6 +61,6 @@ function get_multichoice_definition(array $config, \stdClass $questionattempt, \
'name' => [
$lang => utils\get_string_html_removed($question->questiontext),
],
'interactionType' => 'choice'
'interactionType' => $interactiontype
];
}
4 changes: 2 additions & 2 deletions tests/mod_quiz/attempt_submitted/gapselect/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@
"definition": {
"type": "http:\/\/adlnet.gov\/expapi\/activities\/cmi.interaction",
"name": {
"en": "<p>Example [[1]] missing [[2]] words [[3]]<\/p>"
"en": "Example [[1]] missing [[2]] words [[3]]"
},
"interactionType": "sequencing"
}
},
"timestamp": "2015-06-10T15:31:41+01:00",
"result": {
"response": "{spicy} {mango} {milkshake}",
"response": "spicy[,]mango[,]milkshake",
"completion": true,
"success": true,
"extensions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"definition": {
"type": "http:\/\/adlnet.gov\/expapi\/activities\/cmi.interaction",
"name": {
"en": "<p>Example Random short-answer matching question<br><\/p>"
"en": "Example Random short-answer matching question"
},
"interactionType": "matching"
}
Expand Down