diff --git a/src/transformer/events/mod_feedback/course_module_viewed.php b/src/transformer/events/mod_feedback/course_module_viewed.php new file mode 100644 index 0000000000000000000000000000000000000000..4ed76ed56b5aff010056ee95c1eede1059cfd403 --- /dev/null +++ b/src/transformer/events/mod_feedback/course_module_viewed.php @@ -0,0 +1,57 @@ +<?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; + +defined('MOODLE_INTERNAL') || die(); + +use src\transformer\utils as utils; + +function course_module_viewed(array $config, \stdClass $event) { + $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', $event->objectid); + $lang = utils\get_course_lang($course); + + return [[ + 'actor' => utils\get_user($config, $user), + 'verb' => [ + 'id' => 'http://id.tincanapi.com/verb/viewed', + 'display' => [ + $lang => 'viewed' + ], + ], + 'object' => utils\get_activity\course_feedback($config, $event->contextinstanceid, $feedback, $lang), + 'timestamp' => utils\get_event_timestamp($event), + '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), + ], + 'category' => [ + utils\get_activity\source($config), + ] + ], + ] + ]]; +} \ No newline at end of file diff --git a/src/transformer/events/mod_feedback/response_submitted.php b/src/transformer/events/mod_feedback/response_submitted.php index 323957292279b68d23da8082e25f8475c4c6b908..750457aec11cdeb63c05f274875b3ef8fc577361 100644 --- a/src/transformer/events/mod_feedback/response_submitted.php +++ b/src/transformer/events/mod_feedback/response_submitted.php @@ -36,7 +36,7 @@ function response_submitted(array $config, \stdClass $event) { $lang => 'submitted' ], ], - 'object' => utils\get_activity\feedback($config, $feedback, $lang), + 'object' => utils\get_activity\course_feedback($config, $event->contextinstanceid, $feedback, $lang), 'timestamp' => utils\get_event_timestamp($event), 'context' => [ 'platform' => $config['source_name'], diff --git a/src/transformer/get_event_function_map.php b/src/transformer/get_event_function_map.php index 6bc318b711757b273fcb1e91710b88725b99e993..72dd2b2c5760c05dc83279249cb933c61e8ce5b2 100644 --- a/src/transformer/get_event_function_map.php +++ b/src/transformer/get_event_function_map.php @@ -36,7 +36,7 @@ function get_event_function_map() { '\mod_facetoface\event\course_module_viewed' => 'all\course_module_viewed', '\mod_facetoface\event\signup_success' => 'mod_facetoface\signup_success', '\mod_facetoface\event\take_attendance' => 'mod_facetoface\take_attendance', - '\mod_feedback\event\course_module_viewed' => 'all\course_module_viewed', + '\mod_feedback\event\course_module_viewed' => 'mod_feedback\course_module_viewed', '\mod_feedback\event\response_submitted' => 'mod_feedback\response_submitted', '\mod_folder\event\course_module_viewed' => 'all\course_module_viewed', '\mod_forum\event\course_module_viewed' => 'all\course_module_viewed', diff --git a/src/transformer/utils/get_activity/feedback.php b/src/transformer/utils/get_activity/course_feedback.php similarity index 93% rename from src/transformer/utils/get_activity/feedback.php rename to src/transformer/utils/get_activity/course_feedback.php index 381354635f225df74fb276d201712843c965cdb1..99ef6cd227dd1d37893b3e6381e4223cff990753 100644 --- a/src/transformer/utils/get_activity/feedback.php +++ b/src/transformer/utils/get_activity/course_feedback.php @@ -19,11 +19,11 @@ defined('MOODLE_INTERNAL') || die(); use src\transformer\utils as utils; -function feedback(array $config, \stdClass $feedback, $lang) { +function course_feedback(array $config, $cmid, $feedback, $lang) { $name = $feedback->name ? $feedback->name : 'A Moodle feedback survey'; return [ - 'id' => $config['app_url'].'/mod/feedback/view.php?id='.$feedback->id, + 'id' => $config['app_url'].'/mod/feedback/view.php?id='.$cmid, 'definition' => [ 'type' => 'http://id.tincanapi.com/activitytype/survey', 'name' => [ diff --git a/tests/mod_feedback/course_module_viewed/viewing_feedback/data.json b/tests/mod_feedback/course_module_viewed/viewing_feedback/data.json new file mode 100644 index 0000000000000000000000000000000000000000..91d2e86b265b6b7542412d2b719574a61ff09ca3 --- /dev/null +++ b/tests/mod_feedback/course_module_viewed/viewing_feedback/data.json @@ -0,0 +1,30 @@ +{ + "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 + } + ], + "feedback": [ + { + "id": 1, + "name": "test_name" + } + ] +} \ No newline at end of file diff --git a/tests/mod_feedback/course_module_viewed/viewing_feedback/event.json b/tests/mod_feedback/course_module_viewed/viewing_feedback/event.json new file mode 100644 index 0000000000000000000000000000000000000000..df521308d38c2ce6dbebc4acafcf9bdad4b5fd35 --- /dev/null +++ b/tests/mod_feedback/course_module_viewed/viewing_feedback/event.json @@ -0,0 +1,9 @@ +{ + "id": 1, + "userid": 1, + "courseid": 1, + "timecreated": 1433946701, + "objectid": 1, + "contextinstanceid": 1, + "eventname": "\\mod_feedback\\event\\course_module_viewed" +} \ No newline at end of file diff --git a/tests/mod_feedback/course_module_viewed/viewing_feedback/statements.json b/tests/mod_feedback/course_module_viewed/viewing_feedback/statements.json new file mode 100644 index 0000000000000000000000000000000000000000..83dc0a9eee03bb073f8f4fa344edf897c30dd4b0 --- /dev/null +++ b/tests/mod_feedback/course_module_viewed/viewing_feedback/statements.json @@ -0,0 +1,72 @@ +[ + { + "actor": { + "name": "test_fullname", + "account": { + "homePage": "http:\/\/www.example.org", + "name": "1" + } + }, + "verb": { + "id": "http:\/\/id.tincanapi.com\/verb\/viewed", + "display": { + "en": "viewed" + } + }, + "object": { + "id": "http:\/\/www.example.org\/mod\/feedback\/view.php?id=1", + "definition": { + "type": "http:\/\/id.tincanapi.com\/activitytype\/survey", + "name": { + "en": "test_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\\course_module_viewed", + "event_function": "\\src\\transformer\\events\\mod_feedback\\course_module_viewed" + } + }, + "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" + } + } + } + ] + } + } + } +] \ No newline at end of file diff --git a/tests/mod_feedback/course_module_viewed/viewing_feedback/test.php b/tests/mod_feedback/course_module_viewed/viewing_feedback/test.php new file mode 100644 index 0000000000000000000000000000000000000000..f232cda43ade360cf3f2716d8aa953db7720c91e --- /dev/null +++ b/tests/mod_feedback/course_module_viewed/viewing_feedback/test.php @@ -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\course_module_viewed\viewing_feedback; +defined('MOODLE_INTERNAL') || die(); + +class test extends \tests\xapi_test_case { + protected function get_test_dir() { + return __DIR__; + } +} \ No newline at end of file diff --git a/tests/mod_feedback/response_submitted/existing_response/event.json b/tests/mod_feedback/response_submitted/existing_response/event.json index cad888ddfb7f3591f5cc9ac444aeb72d66c571f9..5cd948b5e25fcd2ffd2d80dc4afe88d12d7e04ab 100644 --- a/tests/mod_feedback/response_submitted/existing_response/event.json +++ b/tests/mod_feedback/response_submitted/existing_response/event.json @@ -3,7 +3,7 @@ "userid": 1, "courseid": 1, "timecreated": 1433946701, - "objecttable": "feedback_completed", "objectid": 1, + "contextinstanceid": 1, "eventname": "\\mod_feedback\\event\\response_submitted" } \ No newline at end of file