Skip to content

Commit

Permalink
feat: Adds statement for multichoiceset quiz answers. (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryasmi authored Aug 28, 2018
1 parent 7dca1ae commit 64d65a3
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 16 deletions.
1 change: 1 addition & 0 deletions classes/log/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function process_events(array $events) {
'source_version' => $CFG->release,
'source_lang' => 'en',
'send_mbox' => $this->get_config('mbox', false),
'send_response_choices' => $this->get_config('sendresponsechoices', false),
'send_short_course_id' => $this->get_config('shortcourseid', false),
'send_username' => $this->get_config('send_username', false),
'plugin_url' => 'https://github.com/xAPI-vle/moodle-logstore_xapi',
Expand Down
2 changes: 2 additions & 0 deletions lang/en/logstore_xapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@
$string['send_username_desc'] = 'Statements will identify users with their username when this box is ticked, but only if identifying users by email is disabled.';
$string['shortcourseid'] = 'Send short course name';
$string['shortcourseid_desc'] = 'Statements will contain the shortname for a course as a short course id extension';
$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';
4 changes: 4 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
get_string('send_username', 'logstore_xapi'),
get_string('send_username_desc', 'logstore_xapi'), 0));

$settings->add(new admin_setting_configcheckbox('logstore_xapi/sendresponsechoices',
get_string('send_response_choices', 'logstore_xapi'),
get_string('send_response_choices_desc', 'logstore_xapi'), 0));

// Filters.
$settings->add(new admin_setting_heading('filters',
get_string('filters', 'logstore_xapi'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace src\transformer\events\mod_quiz\question_answered;

defined('MOODLE_INTERNAL') || die();

use src\transformer\utils as utils;
Expand All @@ -39,17 +38,12 @@ function multichoice(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' => 'choice',
]
'definition' => utils\get_multichoice_definition($config, $questionattempt, $question, $lang),
],
'timestamp' => utils\get_event_timestamp($event),
'result' => [
'response' => $questionattempt->responsesummary,
'success' => $questionattempt->rightanswer == $questionattempt->responsesummary,
'completion' => $questionattempt->responsesummary !== '',
'extensions' => [
'http://learninglocker.net/xapi/cmi/choice/response' => $questionattempt->responsesummary,
Expand All @@ -74,4 +68,4 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt
],
]
]];
}
}
54 changes: 54 additions & 0 deletions src/transformer/utils/get_multichoice_definition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace src\transformer\utils;
defined('MOODLE_INTERNAL') || die();

function get_multichoice_definition(array $config, \stdClass $questionattempt, \stdClass $question, $lang) {
if ($config['send_response_choices']) {
$repo = $config['repo'];
$answers = $repo->read_records('question_answers', [
'question' => $questionattempt->questionid
]);
$choices = array_map(function ($answer) use ($lang) {
return [
"id" => "$answer->id",
"description" => [
$lang => $answer->answer
]
];
}, $answers);
return [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
],
'interactionType' => 'choice',
'correctResponsesPattern' => [
$questionattempt->rightanswer,
],
'choices' => $choices
];
}

return [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
],
'interactionType' => 'choice'
];
}
23 changes: 22 additions & 1 deletion tests/mod_quiz/attempt_submitted/multichoice/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"id": 1,
"questionusageid": 1,
"questionid": 1,
"responsesummary": "test_answer"
"responsesummary": "answer 1",
"rightanswer": "answer 1"
}
],
"question": [
Expand All @@ -67,5 +68,25 @@
"qtype": "multichoice",
"questiontext": "test_question"
}
],
"question_answers": [
{
"id": 1,
"fraction": 1.000,
"answer": "answer 1",
"question": 1
},
{
"id": 2,
"fraction": 1.000,
"answer": "answer 2",
"question": 1
},
{
"id": 3,
"fraction": 1.000,
"answer": "answer 3",
"question": 1
}
]
}
5 changes: 3 additions & 2 deletions tests/mod_quiz/attempt_submitted/multichoice/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@
},
"timestamp": "2015-06-10T15:31:41+01:00",
"result": {
"response": "test_answer",
"response": "answer 1",
"success": true,
"completion": true,
"extensions": {
"http:\/\/learninglocker.net\/xapi\/cmi\/choice\/response": "test_answer"
"http:\/\/learninglocker.net\/xapi\/cmi\/choice\/response": "answer 1"
}
},
"context": {
Expand Down
80 changes: 80 additions & 0 deletions tests/mod_quiz/attempt_submitted/multichoice_withchoices/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"user": [
{
"id": 1,
"firstname": "test_fullname",
"email": "test@test.com"
}
],
"course": [
{
"id": 1,
"fullname": "test_name",
"lang": "en"
}
],
"course_modules": [
{
"id": 1,
"course": 1,
"module": 1,
"instance": 1
}
],
"modules": [
{
"id": 1,
"name": "quiz"
}
],
"quiz_attempts": [
{
"id": 1,
"quiz": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"quiz": [
{
"id": 1,
"name": "test_quiz_name"
}
],
"grade_items": [
{
"id": 1,
"iteminstance": 1,
"itemmodule": "quiz",
"grademin": 0,
"grademax": 100,
"gradepass": 50
}
],
"question_attempts": [
{
"id": 1,
"questionusageid": 1,
"questionid": 1,
"responsesummary": "answer 1",
"rightanswer": "answer 1"
}
],
"question": [
{
"id": 1,
"qtype": "multichoice",
"questiontext": "test_question"
}
],
"question_answers": [
{
"id": 1,
"fraction": 1.000,
"answer": "answer 1",
"question": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": 1,
"relateduserid": 1,
"courseid": 1,
"timecreated": 1433946701,
"objecttable": "attempt",
"objectid": 1,
"contextinstanceid": 1,
"eventname": "\\mod_quiz\\event\\attempt_submitted"
}
Loading

0 comments on commit 64d65a3

Please sign in to comment.