diff --git a/src/transformer/events/core/course_module_created.php b/src/transformer/events/core/course_module_created.php new file mode 100644 index 000000000..d373dbc1d --- /dev/null +++ b/src/transformer/events/core/course_module_created.php @@ -0,0 +1,62 @@ +. + +namespace src\transformer\events\core; + +defined('MOODLE_INTERNAL') || die(); + +use src\transformer\utils as utils; + +function course_module_created(array $config, \stdClass $event) { + $repo = $config['repo']; + $user = $repo->read_record_by_id('user', $event->relateduserid); + $course = $repo->read_record_by_id('course', $event->courseid); + $coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid); + $moduletype = $repo->read_record_by_id('modules', $coursemodule->module); + $module = $repo->read_record_by_id($moduletype->name, $coursemodule->instance); + $lang = utils\get_course_lang($course); + + return [[ + 'actor' => utils\get_user($config, $user), + 'verb' => [ + 'id' => 'http://activitystrea.ms/schema/1.0/create', + 'display' => [ + $lang => 'created' + ], + ], + 'object' => utils\get_activity\course_module( + $config, + $course, + $event->contextinstanceid, + 'http://id.tincanapi.com/activitytype/lms/module' + ), + 'timestamp' => utils\get_event_timestamp($event), + 'context' => [ + 'platform' => $config['source_name'], + 'language' => $lang, + 'extensions' => utils\extensions\base($config, $event, $course), + 'contextActivities' => [ + 'grouping' => [ + utils\get_activity\site($config), + utils\get_activity\course($config, $course), + ], + 'category' => [ + utils\get_activity\source($config), + ] + ], + ] + ]]; +} diff --git a/src/transformer/get_event_function_map.php b/src/transformer/get_event_function_map.php index 4c89f3d2b..a653d8697 100644 --- a/src/transformer/get_event_function_map.php +++ b/src/transformer/get_event_function_map.php @@ -26,6 +26,7 @@ function get_event_function_map() { '\core\event\user_loggedin' => 'core\user_loggedin', '\core\event\user_loggedout' => 'core\user_loggedout', '\core\event\course_module_completion_updated' => 'core\course_module_completion_updated', + '\core\event\course_module_created' => 'core\course_module_created', '\mod_assign\event\assessable_submitted' => 'mod_assign\assignment_submitted', '\mod_assign\event\submission_graded' => 'mod_assign\assignment_graded', diff --git a/src/transformer/utils/get_user.php b/src/transformer/utils/get_user.php index f80ccc13d..35be8b229 100644 --- a/src/transformer/utils/get_user.php +++ b/src/transformer/utils/get_user.php @@ -43,7 +43,7 @@ function get_user(array $config, \stdClass $user) { 'name' => $fullname, 'account' => [ 'homePage' => $config['app_url'], - 'name' => strval($user->id), + 'name' => $user->username, ], ]; } diff --git a/tests/core/course_module_created/data.json b/tests/core/course_module_created/data.json new file mode 100644 index 000000000..f483e8786 --- /dev/null +++ b/tests/core/course_module_created/data.json @@ -0,0 +1,36 @@ +{ + "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": "file" + } + ], + "book": [ + { + "id": 1, + "name": "Lecture 1" + } + ] +} \ No newline at end of file diff --git a/tests/core/course_module_created/event.json b/tests/core/course_module_created/event.json new file mode 100644 index 000000000..e40c9c212 --- /dev/null +++ b/tests/core/course_module_created/event.json @@ -0,0 +1,8 @@ +{ + "id": 1, + "relateduserid": 1, + "courseid": 1, + "timecreated": 1433946701, + "contextinstanceid": 1, + "eventname": "\\core\\event\\course_module_created" +} \ No newline at end of file diff --git a/tests/core/course_module_created/statements.json b/tests/core/course_module_created/statements.json new file mode 100644 index 000000000..1646aae44 --- /dev/null +++ b/tests/core/course_module_created/statements.json @@ -0,0 +1,72 @@ +[ + { + "actor": { + "name": "test_fullname", + "account": { + "homePage": "http:\/\/www.example.org", + "name": "1" + } + }, + "verb": { + "id": "http:\/\/adlnet.gov\/expapi\/verbs\/completed", + "display": { + "en": "created" + } + }, + "object": { + "id": "http:\/\/www.example.org\/mod\/book\/view.php?id=1", + "definition": { + "type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/module", + "name": { + "en": "lecture 1" + } + } + }, + "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_resource\\event\\course_module_created", + "event_function": "\\src\\transformer\\events\\core\\course_module_created" + } + }, + "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/core/course_module_created/test.php b/tests/core/course_module_created/test.php new file mode 100644 index 000000000..2b279f7fe --- /dev/null +++ b/tests/core/course_module_created/test.php @@ -0,0 +1,24 @@ +. + +namespace tests\core\course_module_created\mod_created; +defined('MOODLE_INTERNAL') || die(); + +class test extends \tests\xapi_test_case { + protected function get_test_dir() { + return __DIR__; + } +} \ No newline at end of file