-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds statement for multichoice feedback questions. (#218)
- Loading branch information
Showing
6 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/transformer/events/mod_feedback/item_answered/multichoice.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?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\events\mod_feedback\item_answered; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use src\transformer\utils as utils; | ||
|
||
function multichoice(array $config, \stdClass $event, \stdClass $feedbackvalue, \stdClass $feedbackitem) { | ||
$repo = $config['repo']; | ||
$user = $repo->read_record_by_id('user', $event->userid); | ||
$course = $repo->read_record_by_id('course', $event->courseid); | ||
$feedback = $repo->read_record_by_id('feedback', $feedbackitem->feedback); | ||
$lang = utils\get_course_lang($course); | ||
$choices = explode("\n|", substr($feedbackitem->presentation, 6)); | ||
$selectedchoice = $choices[intval($feedbackvalue->value) - 1]; | ||
|
||
return [[ | ||
'actor' => utils\get_user($config, $user), | ||
'verb' => [ | ||
'id' => 'http://adlnet.gov/expapi/verbs/answered', | ||
'display' => [ | ||
$lang => 'answered' | ||
], | ||
], | ||
'object' => [ | ||
'id' => $config['app_url'].'/mod/feedback/edit_item.php?id='.$feedbackitem->id, | ||
'definition' => [ | ||
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction', | ||
'name' => [ | ||
$lang => $feedbackitem->name, | ||
], | ||
'interactionType' => 'choice', | ||
], | ||
], | ||
'timestamp' => utils\get_event_timestamp($event), | ||
'result' => [ | ||
'response' => $selectedchoice, | ||
'completion' => $feedbackvalue->value !== '', | ||
"extensions" => [ | ||
"http://learninglocker.net/xapi/cmi/choice/response" => $selectedchoice, | ||
], | ||
], | ||
'context' => [ | ||
'platform' => $config['source_name'], | ||
'language' => $lang, | ||
'extensions' => [ | ||
utils\INFO_EXTENSION => utils\get_info($config, $event), | ||
], | ||
'contextActivities' => [ | ||
'grouping' => [ | ||
utils\get_activity\site($config), | ||
utils\get_activity\course($config, $course), | ||
utils\get_activity\course_feedback($config, $event->contextinstanceid, $feedback, $lang), | ||
], | ||
'category' => [ | ||
utils\get_activity\source($config), | ||
] | ||
], | ||
] | ||
]]; | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/mod_feedback/response_submitted/multichoice/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"user": [ | ||
{ | ||
"id": 1, | ||
"firstname": "test_fullname", | ||
"email": "test@test.com" | ||
} | ||
], | ||
"course": [ | ||
{ | ||
"id": 1, | ||
"fullname": "test_name", | ||
"lang": "en" | ||
} | ||
], | ||
"feedback_completed": [ | ||
{ | ||
"id": 1, | ||
"feedback": 1 | ||
} | ||
], | ||
"feedback": [ | ||
{ | ||
"id": 1, | ||
"name": "test_feedback_name" | ||
} | ||
], | ||
"feedback_item": [ | ||
{ | ||
"id": 1, | ||
"feedback": 1, | ||
"name": "test_feedback_item", | ||
"typ": "multichoice", | ||
"presentation": "r>>>>>test_choice_1\n|test_choice_2\n|test_choice_3" | ||
} | ||
], | ||
"feedback_value": [ | ||
{ | ||
"id": 1, | ||
"item": 1, | ||
"completed": 1, | ||
"value": "2" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": 1, | ||
"userid": 1, | ||
"courseid": 1, | ||
"timecreated": 1433946701, | ||
"objectid": 1, | ||
"contextinstanceid": 1, | ||
"eventname": "\\mod_feedback\\event\\response_submitted" | ||
} |
159 changes: 159 additions & 0 deletions
159
tests/mod_feedback/response_submitted/multichoice/statements.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
[ | ||
{ | ||
"actor": { | ||
"name": "test_fullname", | ||
"account": { | ||
"homePage": "http:\/\/www.example.org", | ||
"name": "1" | ||
} | ||
}, | ||
"verb": { | ||
"id": "http:\/\/id.tincanapi.com\/verb\/submitted", | ||
"display": { | ||
"en": "submitted" | ||
} | ||
}, | ||
"object": { | ||
"id": "http:\/\/www.example.org\/mod\/feedback\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/survey", | ||
"name": { | ||
"en": "test_feedback_name" | ||
} | ||
} | ||
}, | ||
"timestamp": "2015-06-10T15:31:41+01:00", | ||
"context": { | ||
"platform": "Moodle", | ||
"language": "en", | ||
"extensions": { | ||
"http:\/\/lrs.learninglocker.net\/define\/extensions\/info": { | ||
"http:\/\/moodle.org": "1.0.0", | ||
"https:\/\/github.com\/xAPI-vle\/moodle-logstore_xapi": "0.0.0-development", | ||
"event_name": "\\mod_feedback\\event\\response_submitted", | ||
"event_function": "\\src\\transformer\\events\\mod_feedback\\response_submitted\\handler" | ||
} | ||
}, | ||
"contextActivities": { | ||
"grouping": [ | ||
{ | ||
"id": "http:\/\/www.example.org", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "http:\/\/www.example.org\/course\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/course", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
} | ||
], | ||
"category": [ | ||
{ | ||
"id": "http:\/\/moodle.org", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/source", | ||
"name": { | ||
"en": "Moodle" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"actor": { | ||
"name": "test_fullname", | ||
"account": { | ||
"homePage": "http:\/\/www.example.org", | ||
"name": "1" | ||
} | ||
}, | ||
"verb": { | ||
"id": "http:\/\/adlnet.gov\/expapi\/verbs\/answered", | ||
"display": { | ||
"en": "answered" | ||
} | ||
}, | ||
"object": { | ||
"id": "http:\/\/www.example.org\/mod\/feedback\/edit_item.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/adlnet.gov\/expapi\/activities\/cmi.interaction", | ||
"name": { | ||
"en": "test_feedback_item" | ||
}, | ||
"interactionType": "choice" | ||
} | ||
}, | ||
"timestamp": "2015-06-10T15:31:41+01:00", | ||
"result": { | ||
"response": "test_choice_2", | ||
"completion": true, | ||
"extensions": { | ||
"http:\/\/learninglocker.net\/xapi\/cmi\/choice\/response": "test_choice_2" | ||
} | ||
}, | ||
"context": { | ||
"platform": "Moodle", | ||
"language": "en", | ||
"extensions": { | ||
"http:\/\/lrs.learninglocker.net\/define\/extensions\/info": { | ||
"http:\/\/moodle.org": "1.0.0", | ||
"https:\/\/github.com\/xAPI-vle\/moodle-logstore_xapi": "0.0.0-development", | ||
"event_name": "\\mod_feedback\\event\\response_submitted", | ||
"event_function": "\\src\\transformer\\events\\mod_feedback\\response_submitted\\handler" | ||
} | ||
}, | ||
"contextActivities": { | ||
"grouping": [ | ||
{ | ||
"id": "http:\/\/www.example.org", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "http:\/\/www.example.org\/course\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/course", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "http:\/\/www.example.org\/mod\/feedback\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/survey", | ||
"name": { | ||
"en": "test_feedback_name" | ||
} | ||
} | ||
} | ||
], | ||
"category": [ | ||
{ | ||
"id": "http:\/\/moodle.org", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/source", | ||
"name": { | ||
"en": "Moodle" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] |
24 changes: 24 additions & 0 deletions
24
tests/mod_feedback/response_submitted/multichoice/test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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 tests\mod_feedback\response_submitted\multichoice; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class test extends \tests\xapi_test_case { | ||
protected function get_test_dir() { | ||
return __DIR__; | ||
} | ||
} |