-
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 numerical quiz questions. (#201)
- Loading branch information
Showing
6 changed files
with
365 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
75 changes: 75 additions & 0 deletions
75
src/transformer/events/mod_quiz/question_answered/numerical.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,75 @@ | ||
<?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_quiz\question_answered; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use src\transformer\utils as utils; | ||
|
||
function numerical(array $config, \stdClass $event, \stdClass $questionattempt, \stdClass $question) { | ||
$repo = $config['repo']; | ||
$user = $repo->read_record_by_id('user', $event->relateduserid); | ||
$course = $repo->read_record_by_id('course', $event->courseid); | ||
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid); | ||
$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); | ||
|
||
return [[ | ||
'actor' => utils\get_user($config, $user), | ||
'verb' => [ | ||
'id' => 'http://adlnet.gov/expapi/verbs/answered', | ||
'display' => [ | ||
$lang => 'answered' | ||
], | ||
], | ||
'object' => [ | ||
'id' => $config['app_url'].'/question/question.php?cmid='.$coursemodule->id.'&id='.$question->id, | ||
'definition' => [ | ||
'type' => 'http://adlnet.gov/expapi/activities/question', | ||
'name' => [ | ||
$lang => $questionattempt->questionsummary, | ||
], | ||
'interactionType' => 'numeric', | ||
] | ||
], | ||
'timestamp' => utils\get_event_timestamp($event), | ||
'result' => [ | ||
'response' => $questionattempt->responsesummary, | ||
'completion' => $questionattempt->responsesummary !== '', | ||
'success' => $questionattempt->rightanswer === $questionattempt->responsesummary, | ||
], | ||
'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\module($config, 'quiz', $quiz, $lang), | ||
utils\get_activity\module($config, 'attempt', $attempt, $lang), | ||
], | ||
'category' => [ | ||
utils\get_activity\source($config), | ||
] | ||
], | ||
] | ||
]]; | ||
} |
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,66 @@ | ||
{ | ||
"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 | ||
} | ||
], | ||
"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, | ||
"questionsummary": "test_question", | ||
"responsesummary": "1", | ||
"rightanswer": "1" | ||
} | ||
], | ||
"question": [ | ||
{ | ||
"id": 1, | ||
"qtype": "numerical" | ||
} | ||
] | ||
} |
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,10 @@ | ||
{ | ||
"id": 1, | ||
"relateduserid": 1, | ||
"courseid": 1, | ||
"timecreated": 1433946701, | ||
"objecttable": "attempt", | ||
"objectid": 1, | ||
"contextinstanceid": 1, | ||
"eventname": "\\mod_quiz\\event\\attempt_submitted" | ||
} |
188 changes: 188 additions & 0 deletions
188
tests/mod_quiz/attempt_submitted/numerical/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,188 @@ | ||
[ | ||
{ | ||
"actor": { | ||
"name": "test_fullname", | ||
"account": { | ||
"homePage": "http:\/\/www.example.org", | ||
"name": "1" | ||
} | ||
}, | ||
"verb": { | ||
"id": "http:\/\/adlnet.gov\/expapi\/verbs\/completed", | ||
"display": { | ||
"en": "completed" | ||
} | ||
}, | ||
"object": { | ||
"id": "http:\/\/www.example.org\/mod\/quiz\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/module", | ||
"name": { | ||
"en": "test_quiz_name" | ||
} | ||
} | ||
}, | ||
"timestamp": "2015-06-10T15:31:41+01:00", | ||
"result": { | ||
"score": { | ||
"raw": 50, | ||
"min": 0, | ||
"max": 100, | ||
"scaled": 0.5 | ||
}, | ||
"completion": true, | ||
"success": true, | ||
"duration": "PT1S" | ||
}, | ||
"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_quiz\\event\\attempt_submitted", | ||
"event_function": "\\src\\transformer\\events\\mod_quiz\\attempt_submitted\\handler" | ||
} | ||
}, | ||
"contextActivities": { | ||
"other": [ | ||
{ | ||
"id": "http:\/\/www.example.org\/mod\/attempt\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/module", | ||
"name": { | ||
"en": "attempt" | ||
} | ||
} | ||
} | ||
], | ||
"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\/question\/question.php?cmid=1&id=1", | ||
"definition": { | ||
"type": "http:\/\/adlnet.gov\/expapi\/activities\/question", | ||
"name": { | ||
"en": "test_question" | ||
}, | ||
"interactionType": "numeric" | ||
} | ||
}, | ||
"timestamp": "2015-06-10T15:31:41+01:00", | ||
"result": { | ||
"response": "1", | ||
"completion": true, | ||
"success": true | ||
}, | ||
"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_quiz\\event\\attempt_submitted", | ||
"event_function": "\\src\\transformer\\events\\mod_quiz\\attempt_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\/quiz\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/module", | ||
"name": { | ||
"en": "test_quiz_name" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "http:\/\/www.example.org\/mod\/attempt\/view.php?id=1", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/module", | ||
"name": { | ||
"en": "attempt" | ||
} | ||
} | ||
} | ||
], | ||
"category": [ | ||
{ | ||
"id": "http:\/\/moodle.org", | ||
"definition": { | ||
"type": "http:\/\/id.tincanapi.com\/activitytype\/source", | ||
"name": { | ||
"en": "Moodle" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] |
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_quiz\attempt_submitted\numerical; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class test extends \tests\xapi_test_case { | ||
protected function get_test_dir() { | ||
return __DIR__; | ||
} | ||
} |