From da6298a14f9d7cbec3a4ee14c0679629a5c6b8b2 Mon Sep 17 00:00:00 2001 From: Ryan Smith <3045513+ryansmith94@users.noreply.github.com> Date: Fri, 17 May 2019 12:01:47 +0100 Subject: [PATCH] feat(JISC): Adds jisc extensions behind `send_jisc_data` setting. (#547) --- classes/log/store.php | 2 + lang/en/logstore_xapi.php | 2 + settings.php | 4 ++ .../events/all/course_module_viewed.php | 4 +- .../events/core/course_completed.php | 4 +- .../core/course_module_completion_updated.php | 4 +- src/transformer/events/core/course_viewed.php | 4 +- src/transformer/events/core/user_created.php | 4 +- .../events/core/user_enrolment_created.php | 4 +- src/transformer/events/core/user_loggedin.php | 4 +- .../events/core/user_loggedout.php | 4 +- .../events/mod_assign/assignment_graded.php | 4 +- .../mod_assign/assignment_submitted.php | 4 +- .../events/mod_book/chapter_viewed.php | 4 +- .../events/mod_book/course_module_viewed.php | 4 +- .../events/mod_chat/course_module_viewed.php | 4 +- .../events/mod_facetoface/cancel_booking.php | 4 +- .../mod_facetoface/course_module_viewed.php | 4 +- .../events/mod_facetoface/signup_success.php | 4 +- .../events/mod_facetoface/take_attendance.php | 4 +- .../mod_feedback/course_module_viewed.php | 4 +- .../item_answered/multichoice.php | 4 +- .../item_answered/multichoicerated.php | 4 +- .../mod_feedback/item_answered/numerical.php | 4 +- .../mod_feedback/item_answered/textarea.php | 4 +- .../mod_feedback/item_answered/textfield.php | 4 +- .../response_submitted/response_submitted.php | 4 +- .../events/mod_forum/course_module_viewed.php | 4 +- .../events/mod_forum/discussion_viewed.php | 4 +- .../events/mod_forum/user_report_viewed.php | 4 +- .../mod_lesson/course_module_viewed.php | 4 +- .../events/mod_page/course_module_viewed.php | 4 +- .../events/mod_quiz/attempt_reviewed.php | 4 +- .../events/mod_quiz/attempt_started.php | 4 +- .../attempt_submitted/attempt_submitted.php | 4 +- .../events/mod_quiz/attempt_viewed.php | 4 +- .../events/mod_quiz/course_module_viewed.php | 4 +- .../mod_quiz/question_answered/essay.php | 4 +- .../mod_quiz/question_answered/gapselect.php | 4 +- .../mod_quiz/question_answered/match.php | 4 +- .../question_answered/multichoice.php | 4 +- .../mod_quiz/question_answered/numerical.php | 4 +- .../question_answered/randomsamatch.php | 4 +- .../question_answered/shortanswer.php | 4 +- .../mod_quiz/question_answered/truefalse.php | 4 +- .../mod_resource/course_module_viewed.php | 4 +- .../events/mod_scorm/course_module_viewed.php | 4 +- .../events/mod_scorm/sco_launched.php | 4 +- .../events/mod_scorm/scoreraw_submitted.php | 4 +- .../events/mod_scorm/status_submitted.php | 4 +- .../mod_survey/course_module_viewed.php | 4 +- .../events/mod_url/course_module_viewed.php | 4 +- .../{constants.php => extensions/base.php} | 9 ++- .../course_area.php} | 14 ++-- src/transformer/utils/extensions/info.php | 29 ++++++++ src/transformer/utils/extensions/jisc.php | 34 +++++++++ .../course_completed/send_jisc_data/data.json | 17 +++++ .../send_jisc_data/event.json | 10 +++ .../send_jisc_data/statements.json | 69 +++++++++++++++++++ .../course_completed/send_jisc_data/test.php | 32 +++++++++ .../user_created/send_jisc_data/data.json | 17 +++++ .../user_created/send_jisc_data/event.json | 10 +++ .../send_jisc_data/statements.json | 55 +++++++++++++++ .../core/user_created/send_jisc_data/test.php | 32 +++++++++ tests/xapi_test_case.php | 2 + 65 files changed, 379 insertions(+), 155 deletions(-) rename src/transformer/utils/{constants.php => extensions/base.php} (78%) rename src/transformer/utils/{get_info.php => extensions/course_area.php} (71%) create mode 100644 src/transformer/utils/extensions/info.php create mode 100644 src/transformer/utils/extensions/jisc.php create mode 100644 tests/core/course_completed/send_jisc_data/data.json create mode 100644 tests/core/course_completed/send_jisc_data/event.json create mode 100644 tests/core/course_completed/send_jisc_data/statements.json create mode 100644 tests/core/course_completed/send_jisc_data/test.php create mode 100644 tests/core/user_created/send_jisc_data/data.json create mode 100644 tests/core/user_created/send_jisc_data/event.json create mode 100644 tests/core/user_created/send_jisc_data/statements.json create mode 100644 tests/core/user_created/send_jisc_data/test.php diff --git a/classes/log/store.php b/classes/log/store.php index a79e842..c35e33a 100755 --- a/classes/log/store.php +++ b/classes/log/store.php @@ -104,6 +104,8 @@ class store extends php_obj implements log_writer { 'send_short_course_id' => $this->get_config('shortcourseid', false), 'send_course_and_module_idnumber' => $this->get_config('sendidnumber', false), 'send_username' => $this->get_config('send_username', false), + 'send_jisc_data' => $this->get_config('send_jisc_data', false), + 'session_id' => sesskey(), 'plugin_url' => 'https://github.com/xAPI-vle/moodle-logstore_xapi', 'plugin_version' => $plugin->release, 'repo' => new \src\transformer\repos\MoodleRepository($DB), diff --git a/lang/en/logstore_xapi.php b/lang/en/logstore_xapi.php index e922c8e..6cb7590 100644 --- a/lang/en/logstore_xapi.php +++ b/lang/en/logstore_xapi.php @@ -43,6 +43,8 @@ $string['mbox'] = 'Identify users by email'; $string['mbox_desc'] = 'Statements will identify users with their email (mbox) when this box is ticked.'; $string['send_username'] = 'Identify users by id'; $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['send_jisc_data'] = 'Adds JISC data to statements'; +$string['send_jisc_data_desc'] = 'Statements will contain data required by JISC.'; $string['shortcourseid'] = 'Send short course name'; $string['shortcourseid_desc'] = 'Statements will contain the shortname for a course as a short course id extension'; $string['sendidnumber'] = 'Send course and activity ID number'; diff --git a/settings.php b/settings.php index 011cc9a..b287a55 100644 --- a/settings.php +++ b/settings.php @@ -59,6 +59,10 @@ if ($hassiteconfig) { get_string('send_username', 'logstore_xapi'), get_string('send_username_desc', 'logstore_xapi'), 0)); + $settings->add(new admin_setting_configcheckbox('logstore_xapi/send_jisc_data', + get_string('send_jisc_data', 'logstore_xapi'), + get_string('send_jisc_data_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)); diff --git a/src/transformer/events/all/course_module_viewed.php b/src/transformer/events/all/course_module_viewed.php index edb802f..c588b32 100644 --- a/src/transformer/events/all/course_module_viewed.php +++ b/src/transformer/events/all/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/core/course_completed.php b/src/transformer/events/core/course_completed.php index 8323b23..e0b2905 100644 --- a/src/transformer/events/core/course_completed.php +++ b/src/transformer/events/core/course_completed.php @@ -39,9 +39,7 @@ function course_completed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config) diff --git a/src/transformer/events/core/course_module_completion_updated.php b/src/transformer/events/core/course_module_completion_updated.php index e1d8c3f..c869d85 100644 --- a/src/transformer/events/core/course_module_completion_updated.php +++ b/src/transformer/events/core/course_module_completion_updated.php @@ -47,9 +47,7 @@ function course_module_completion_updated(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/core/course_viewed.php b/src/transformer/events/core/course_viewed.php index e9a8554..51ecd14 100644 --- a/src/transformer/events/core/course_viewed.php +++ b/src/transformer/events/core/course_viewed.php @@ -39,9 +39,7 @@ function course_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config) diff --git a/src/transformer/events/core/user_created.php b/src/transformer/events/core/user_created.php index cce18ca..611fcb0 100644 --- a/src/transformer/events/core/user_created.php +++ b/src/transformer/events/core/user_created.php @@ -38,9 +38,7 @@ function user_created(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, null), 'contextActivities' => [ 'category' => [ utils\get_activity\source($config) diff --git a/src/transformer/events/core/user_enrolment_created.php b/src/transformer/events/core/user_enrolment_created.php index 5bed801..222ed63 100644 --- a/src/transformer/events/core/user_enrolment_created.php +++ b/src/transformer/events/core/user_enrolment_created.php @@ -39,9 +39,7 @@ function user_enrolment_created(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config) diff --git a/src/transformer/events/core/user_loggedin.php b/src/transformer/events/core/user_loggedin.php index 04e2643..dd95747 100644 --- a/src/transformer/events/core/user_loggedin.php +++ b/src/transformer/events/core/user_loggedin.php @@ -38,9 +38,7 @@ function user_loggedin(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, null), 'contextActivities' => [ 'category' => [ utils\get_activity\source($config) diff --git a/src/transformer/events/core/user_loggedout.php b/src/transformer/events/core/user_loggedout.php index 31d3da2..2ea42fb 100644 --- a/src/transformer/events/core/user_loggedout.php +++ b/src/transformer/events/core/user_loggedout.php @@ -38,9 +38,7 @@ function user_loggedout(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, null), 'contextActivities' => [ 'category' => [ utils\get_activity\source($config) diff --git a/src/transformer/events/mod_assign/assignment_graded.php b/src/transformer/events/mod_assign/assignment_graded.php index ec5d171..47a8481 100644 --- a/src/transformer/events/mod_assign/assignment_graded.php +++ b/src/transformer/events/mod_assign/assignment_graded.php @@ -76,9 +76,7 @@ function assignment_graded(array $config, \stdClass $event) { 'instructor' => utils\get_user($config, $instructor), 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_assign/assignment_submitted.php b/src/transformer/events/mod_assign/assignment_submitted.php index f404d72..f752663 100644 --- a/src/transformer/events/mod_assign/assignment_submitted.php +++ b/src/transformer/events/mod_assign/assignment_submitted.php @@ -41,9 +41,7 @@ function assignment_submitted(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_book/chapter_viewed.php b/src/transformer/events/mod_book/chapter_viewed.php index 87dcc20..1a2dd71 100644 --- a/src/transformer/events/mod_book/chapter_viewed.php +++ b/src/transformer/events/mod_book/chapter_viewed.php @@ -40,9 +40,7 @@ function chapter_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_book/course_module_viewed.php b/src/transformer/events/mod_book/course_module_viewed.php index 9e419a8..ea17508 100644 --- a/src/transformer/events/mod_book/course_module_viewed.php +++ b/src/transformer/events/mod_book/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_chat/course_module_viewed.php b/src/transformer/events/mod_chat/course_module_viewed.php index 304b762..87ca326 100644 --- a/src/transformer/events/mod_chat/course_module_viewed.php +++ b/src/transformer/events/mod_chat/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_facetoface/cancel_booking.php b/src/transformer/events/mod_facetoface/cancel_booking.php index c986161..2fed96e 100644 --- a/src/transformer/events/mod_facetoface/cancel_booking.php +++ b/src/transformer/events/mod_facetoface/cancel_booking.php @@ -44,9 +44,7 @@ function cancel_booking(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_facetoface/course_module_viewed.php b/src/transformer/events/mod_facetoface/course_module_viewed.php index 6840205..48de22f 100644 --- a/src/transformer/events/mod_facetoface/course_module_viewed.php +++ b/src/transformer/events/mod_facetoface/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_facetoface/signup_success.php b/src/transformer/events/mod_facetoface/signup_success.php index 5c0d876..32e75e8 100644 --- a/src/transformer/events/mod_facetoface/signup_success.php +++ b/src/transformer/events/mod_facetoface/signup_success.php @@ -44,9 +44,7 @@ function signup_success(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_facetoface/take_attendance.php b/src/transformer/events/mod_facetoface/take_attendance.php index dc3da22..521ae75 100644 --- a/src/transformer/events/mod_facetoface/take_attendance.php +++ b/src/transformer/events/mod_facetoface/take_attendance.php @@ -61,9 +61,7 @@ function take_attendance(array $config, \stdClass $event) { 'platform' => $config['source_name'], 'language' => $lang, 'instructor' => utils\get_user($config, $user), - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/course_module_viewed.php b/src/transformer/events/mod_feedback/course_module_viewed.php index 7ba6b5c..0b33e0f 100644 --- a/src/transformer/events/mod_feedback/course_module_viewed.php +++ b/src/transformer/events/mod_feedback/course_module_viewed.php @@ -39,9 +39,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/item_answered/multichoice.php b/src/transformer/events/mod_feedback/item_answered/multichoice.php index bf8a1b8..5cc9235 100644 --- a/src/transformer/events/mod_feedback/item_answered/multichoice.php +++ b/src/transformer/events/mod_feedback/item_answered/multichoice.php @@ -58,9 +58,7 @@ function multichoice(array $config, \stdClass $event, \stdClass $feedbackvalue, 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/item_answered/multichoicerated.php b/src/transformer/events/mod_feedback/item_answered/multichoicerated.php index e8703d8..d08e12c 100644 --- a/src/transformer/events/mod_feedback/item_answered/multichoicerated.php +++ b/src/transformer/events/mod_feedback/item_answered/multichoicerated.php @@ -69,9 +69,7 @@ function multichoicerated(array $config, \stdClass $event, \stdClass $feedbackva 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/item_answered/numerical.php b/src/transformer/events/mod_feedback/item_answered/numerical.php index 19dc94d..c46551d 100644 --- a/src/transformer/events/mod_feedback/item_answered/numerical.php +++ b/src/transformer/events/mod_feedback/item_answered/numerical.php @@ -56,9 +56,7 @@ function numerical(array $config, \stdClass $event, \stdClass $feedbackvalue, \s 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/item_answered/textarea.php b/src/transformer/events/mod_feedback/item_answered/textarea.php index d92cc48..0c0b0a0 100644 --- a/src/transformer/events/mod_feedback/item_answered/textarea.php +++ b/src/transformer/events/mod_feedback/item_answered/textarea.php @@ -53,9 +53,7 @@ function textarea(array $config, \stdClass $event, \stdClass $feedbackvalue, \st 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/item_answered/textfield.php b/src/transformer/events/mod_feedback/item_answered/textfield.php index 451e195..2ab539d 100644 --- a/src/transformer/events/mod_feedback/item_answered/textfield.php +++ b/src/transformer/events/mod_feedback/item_answered/textfield.php @@ -53,9 +53,7 @@ function textfield(array $config, \stdClass $event, \stdClass $feedbackvalue, \s 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_feedback/response_submitted/response_submitted.php b/src/transformer/events/mod_feedback/response_submitted/response_submitted.php index 403f33d..0d4cd2e 100644 --- a/src/transformer/events/mod_feedback/response_submitted/response_submitted.php +++ b/src/transformer/events/mod_feedback/response_submitted/response_submitted.php @@ -41,9 +41,7 @@ function response_submitted(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_forum/course_module_viewed.php b/src/transformer/events/mod_forum/course_module_viewed.php index dd0cb85..b5d8878 100644 --- a/src/transformer/events/mod_forum/course_module_viewed.php +++ b/src/transformer/events/mod_forum/course_module_viewed.php @@ -39,9 +39,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_forum/discussion_viewed.php b/src/transformer/events/mod_forum/discussion_viewed.php index 0530553..b3c753b 100644 --- a/src/transformer/events/mod_forum/discussion_viewed.php +++ b/src/transformer/events/mod_forum/discussion_viewed.php @@ -40,9 +40,7 @@ function discussion_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_forum/user_report_viewed.php b/src/transformer/events/mod_forum/user_report_viewed.php index fbbf453..19170d5 100644 --- a/src/transformer/events/mod_forum/user_report_viewed.php +++ b/src/transformer/events/mod_forum/user_report_viewed.php @@ -48,9 +48,7 @@ function user_report_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_lesson/course_module_viewed.php b/src/transformer/events/mod_lesson/course_module_viewed.php index 72163db..af7c5ba 100644 --- a/src/transformer/events/mod_lesson/course_module_viewed.php +++ b/src/transformer/events/mod_lesson/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_page/course_module_viewed.php b/src/transformer/events/mod_page/course_module_viewed.php index 2bf7540..11400be 100644 --- a/src/transformer/events/mod_page/course_module_viewed.php +++ b/src/transformer/events/mod_page/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/attempt_reviewed.php b/src/transformer/events/mod_quiz/attempt_reviewed.php index afa8dfe..c940f8b 100644 --- a/src/transformer/events/mod_quiz/attempt_reviewed.php +++ b/src/transformer/events/mod_quiz/attempt_reviewed.php @@ -52,9 +52,7 @@ function attempt_reviewed(array $config, \stdClass $event) { 'instructor' => utils\get_user($config, $instructor), 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/attempt_started.php b/src/transformer/events/mod_quiz/attempt_started.php index 30fa959..94531bd 100644 --- a/src/transformer/events/mod_quiz/attempt_started.php +++ b/src/transformer/events/mod_quiz/attempt_started.php @@ -42,9 +42,7 @@ function attempt_started(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'other' => [ utils\get_activity\quiz_attempt($config, $attempt->id, $event->contextinstanceid), diff --git a/src/transformer/events/mod_quiz/attempt_submitted/attempt_submitted.php b/src/transformer/events/mod_quiz/attempt_submitted/attempt_submitted.php index 0d13ff6..c8c6f04 100644 --- a/src/transformer/events/mod_quiz/attempt_submitted/attempt_submitted.php +++ b/src/transformer/events/mod_quiz/attempt_submitted/attempt_submitted.php @@ -51,9 +51,7 @@ function attempt_submitted(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'other' => [ utils\get_activity\quiz_attempt($config, $attempt->id, $coursemodule->id), diff --git a/src/transformer/events/mod_quiz/attempt_viewed.php b/src/transformer/events/mod_quiz/attempt_viewed.php index 7273395..5354fbc 100644 --- a/src/transformer/events/mod_quiz/attempt_viewed.php +++ b/src/transformer/events/mod_quiz/attempt_viewed.php @@ -39,9 +39,7 @@ function attempt_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/course_module_viewed.php b/src/transformer/events/mod_quiz/course_module_viewed.php index abd6e1e..c9a30ab 100644 --- a/src/transformer/events/mod_quiz/course_module_viewed.php +++ b/src/transformer/events/mod_quiz/course_module_viewed.php @@ -39,9 +39,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/essay.php b/src/transformer/events/mod_quiz/question_answered/essay.php index 7076467..1210d98 100644 --- a/src/transformer/events/mod_quiz/question_answered/essay.php +++ b/src/transformer/events/mod_quiz/question_answered/essay.php @@ -57,9 +57,7 @@ function essay(array $config, \stdClass $event, \stdClass $questionattempt, \std 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/gapselect.php b/src/transformer/events/mod_quiz/question_answered/gapselect.php index faf5a35..b757d6f 100644 --- a/src/transformer/events/mod_quiz/question_answered/gapselect.php +++ b/src/transformer/events/mod_quiz/question_answered/gapselect.php @@ -54,9 +54,7 @@ function gapselect(array $config, \stdClass $event, \stdClass $questionattempt, 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/match.php b/src/transformer/events/mod_quiz/question_answered/match.php index 4db425e..1153858 100644 --- a/src/transformer/events/mod_quiz/question_answered/match.php +++ b/src/transformer/events/mod_quiz/question_answered/match.php @@ -70,9 +70,7 @@ function match(array $config, \stdClass $event, \stdClass $questionattempt, \std 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/multichoice.php b/src/transformer/events/mod_quiz/question_answered/multichoice.php index 696964b..7a695b8 100644 --- a/src/transformer/events/mod_quiz/question_answered/multichoice.php +++ b/src/transformer/events/mod_quiz/question_answered/multichoice.php @@ -53,9 +53,7 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/numerical.php b/src/transformer/events/mod_quiz/question_answered/numerical.php index 93dc47d..cdc36f1 100644 --- a/src/transformer/events/mod_quiz/question_answered/numerical.php +++ b/src/transformer/events/mod_quiz/question_answered/numerical.php @@ -59,9 +59,7 @@ function numerical(array $config, \stdClass $event, \stdClass $questionattempt, 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/randomsamatch.php b/src/transformer/events/mod_quiz/question_answered/randomsamatch.php index df14dbd..a99ea10 100644 --- a/src/transformer/events/mod_quiz/question_answered/randomsamatch.php +++ b/src/transformer/events/mod_quiz/question_answered/randomsamatch.php @@ -70,9 +70,7 @@ function randomsamatch(array $config, \stdClass $event, \stdClass $questionattem 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/shortanswer.php b/src/transformer/events/mod_quiz/question_answered/shortanswer.php index f7024e2..511f46d 100644 --- a/src/transformer/events/mod_quiz/question_answered/shortanswer.php +++ b/src/transformer/events/mod_quiz/question_answered/shortanswer.php @@ -55,9 +55,7 @@ function shortanswer(array $config, \stdClass $event, \stdClass $questionattempt 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_quiz/question_answered/truefalse.php b/src/transformer/events/mod_quiz/question_answered/truefalse.php index f48c28c..dce6f86 100644 --- a/src/transformer/events/mod_quiz/question_answered/truefalse.php +++ b/src/transformer/events/mod_quiz/question_answered/truefalse.php @@ -59,9 +59,7 @@ function truefalse(array $config, \stdClass $event, \stdClass $questionattempt, 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_resource/course_module_viewed.php b/src/transformer/events/mod_resource/course_module_viewed.php index 68f2473..170a279 100644 --- a/src/transformer/events/mod_resource/course_module_viewed.php +++ b/src/transformer/events/mod_resource/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_scorm/course_module_viewed.php b/src/transformer/events/mod_scorm/course_module_viewed.php index d352f60..582c4f2 100644 --- a/src/transformer/events/mod_scorm/course_module_viewed.php +++ b/src/transformer/events/mod_scorm/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_scorm/sco_launched.php b/src/transformer/events/mod_scorm/sco_launched.php index 1dbe4c7..611d610 100644 --- a/src/transformer/events/mod_scorm/sco_launched.php +++ b/src/transformer/events/mod_scorm/sco_launched.php @@ -40,9 +40,7 @@ function sco_launched(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_scorm/scoreraw_submitted.php b/src/transformer/events/mod_scorm/scoreraw_submitted.php index 4b05cb6..eebfcec 100644 --- a/src/transformer/events/mod_scorm/scoreraw_submitted.php +++ b/src/transformer/events/mod_scorm/scoreraw_submitted.php @@ -46,9 +46,7 @@ function scoreraw_submitted(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_scorm/status_submitted.php b/src/transformer/events/mod_scorm/status_submitted.php index e4b31ab..cde9695 100644 --- a/src/transformer/events/mod_scorm/status_submitted.php +++ b/src/transformer/events/mod_scorm/status_submitted.php @@ -44,9 +44,7 @@ function status_submitted(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_survey/course_module_viewed.php b/src/transformer/events/mod_survey/course_module_viewed.php index 9623a0e..3d96879 100644 --- a/src/transformer/events/mod_survey/course_module_viewed.php +++ b/src/transformer/events/mod_survey/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/events/mod_url/course_module_viewed.php b/src/transformer/events/mod_url/course_module_viewed.php index 293f859..4e8ca36 100644 --- a/src/transformer/events/mod_url/course_module_viewed.php +++ b/src/transformer/events/mod_url/course_module_viewed.php @@ -44,9 +44,7 @@ function course_module_viewed(array $config, \stdClass $event) { 'context' => [ 'platform' => $config['source_name'], 'language' => $lang, - 'extensions' => [ - utils\INFO_EXTENSION => utils\get_info($config, $event), - ], + 'extensions' => utils\extensions\base($config, $event, $course), 'contextActivities' => [ 'grouping' => [ utils\get_activity\site($config), diff --git a/src/transformer/utils/constants.php b/src/transformer/utils/extensions/base.php similarity index 78% rename from src/transformer/utils/constants.php rename to src/transformer/utils/extensions/base.php index 74cbc8c..a7cb7ae 100644 --- a/src/transformer/utils/constants.php +++ b/src/transformer/utils/extensions/base.php @@ -14,7 +14,12 @@ // 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; +namespace src\transformer\utils\extensions; defined('MOODLE_INTERNAL') || die(); -const INFO_EXTENSION = 'http://lrs.learninglocker.net/define/extensions/info'; +function base(array $config, \stdClass $event, $course) { + return array_merge( + info($config, $event), + jisc($config, $event, $course) + ); +} diff --git a/src/transformer/utils/get_info.php b/src/transformer/utils/extensions/course_area.php similarity index 71% rename from src/transformer/utils/get_info.php rename to src/transformer/utils/extensions/course_area.php index 82d10e9..cf0b748 100644 --- a/src/transformer/utils/get_info.php +++ b/src/transformer/utils/extensions/course_area.php @@ -14,14 +14,16 @@ // 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; +namespace src\transformer\utils\extensions; defined('MOODLE_INTERNAL') || die(); -function get_info(array $config, \stdClass $event) { +function course_area($course) { + if ($course === null) { + return []; + } return [ - $config['source_url'] => $config['source_version'], - $config['plugin_url'] => $config['plugin_version'], - 'event_name' => $event->eventname, - 'event_function' => $config['event_function'], + 'http://xapi.jisc.ac.uk/courseArea' => [ + 'http://xapi.jisc.ac.uk/vle_mod_id' => $course->shortname, + ], ]; } diff --git a/src/transformer/utils/extensions/info.php b/src/transformer/utils/extensions/info.php new file mode 100644 index 0000000..e4bd43b --- /dev/null +++ b/src/transformer/utils/extensions/info.php @@ -0,0 +1,29 @@ +<?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\extensions; +defined('MOODLE_INTERNAL') || die(); + +function info(array $config, \stdClass $event) { + return [ + 'http://lrs.learninglocker.net/define/extensions/info' => [ + $config['source_url'] => $config['source_version'], + $config['plugin_url'] => $config['plugin_version'], + 'event_name' => $event->eventname, + 'event_function' => $config['event_function'], + ], + ]; +} diff --git a/src/transformer/utils/extensions/jisc.php b/src/transformer/utils/extensions/jisc.php new file mode 100644 index 0000000..95d6133 --- /dev/null +++ b/src/transformer/utils/extensions/jisc.php @@ -0,0 +1,34 @@ +<?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\extensions; +defined('MOODLE_INTERNAL') || die(); + +use src\transformer\utils as utils; + +function jisc(array $config, \stdClass $event, $course) { + if (utils\is_enabled_config($config, 'send_jisc_data')) { + return array_merge( + [ + 'http://xapi.jisc.ac.uk/sessionId' => $config['session_id'], + 'http://id.tincanapi.com/extension/ip-address' => $event->ip, + 'http://xapi.jisc.ac.uk/statementCat' => 'VLE', + ], + course_area($course) + ); + } + return []; +} diff --git a/tests/core/course_completed/send_jisc_data/data.json b/tests/core/course_completed/send_jisc_data/data.json new file mode 100644 index 0000000..a6a648d --- /dev/null +++ b/tests/core/course_completed/send_jisc_data/data.json @@ -0,0 +1,17 @@ +{ + "user": [ + { + "id": 1, + "firstname": "test_fullname", + "email": "test@test.com" + } + ], + "course": [ + { + "id": 1, + "fullname": "test_name", + "lang": "en", + "shortname": "test_course_short_name" + } + ] +} \ No newline at end of file diff --git a/tests/core/course_completed/send_jisc_data/event.json b/tests/core/course_completed/send_jisc_data/event.json new file mode 100644 index 0000000..8691e02 --- /dev/null +++ b/tests/core/course_completed/send_jisc_data/event.json @@ -0,0 +1,10 @@ +{ + "id": 1, + "relateduserid": 1, + "courseid": 1, + "timecreated": 1433946701, + "objecttable": "course", + "objectid": 1, + "eventname": "\\core\\event\\course_completed", + "ip": "127.0.0.1" +} \ No newline at end of file diff --git a/tests/core/course_completed/send_jisc_data/statements.json b/tests/core/course_completed/send_jisc_data/statements.json new file mode 100644 index 0000000..94c4294 --- /dev/null +++ b/tests/core/course_completed/send_jisc_data/statements.json @@ -0,0 +1,69 @@ +[ + { + "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\/course\/view.php?id=1", + "definition": { + "type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/course", + "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": "\\core\\event\\course_completed", + "event_function": "\\src\\transformer\\events\\core\\course_completed" + }, + "http:\/\/xapi.jisc.ac.uk\/sessionId": "test_session_id", + "http:\/\/id.tincanapi.com\/extension\/ip-address": "127.0.0.1", + "http:\/\/xapi.jisc.ac.uk\/statementCat": "VLE", + "http:\/\/xapi.jisc.ac.uk\/courseArea": { + "http:\/\/xapi.jisc.ac.uk\/vle_mod_id": "test_course_short_name" + } + }, + "contextActivities": { + "grouping": [ + { + "id": "http:\/\/www.example.org", + "definition": { + "type": "http:\/\/id.tincanapi.com\/activitytype\/lms", + "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_completed/send_jisc_data/test.php b/tests/core/course_completed/send_jisc_data/test.php new file mode 100644 index 0000000..8249aaf --- /dev/null +++ b/tests/core/course_completed/send_jisc_data/test.php @@ -0,0 +1,32 @@ +<?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\core\course_completed\send_jisc_data; +defined('MOODLE_INTERNAL') || die(); + +class test extends \tests\xapi_test_case { + protected function get_test_dir() { + return __DIR__; + } + + protected function get_transformer_config() { + $testdata = $this->get_test_data(); + $transformerconfig = parent::get_transformer_config(); + return array_merge($transformerconfig, [ + 'send_jisc_data' => true, + ]); + } +} \ No newline at end of file diff --git a/tests/core/user_created/send_jisc_data/data.json b/tests/core/user_created/send_jisc_data/data.json new file mode 100644 index 0000000..a6a648d --- /dev/null +++ b/tests/core/user_created/send_jisc_data/data.json @@ -0,0 +1,17 @@ +{ + "user": [ + { + "id": 1, + "firstname": "test_fullname", + "email": "test@test.com" + } + ], + "course": [ + { + "id": 1, + "fullname": "test_name", + "lang": "en", + "shortname": "test_course_short_name" + } + ] +} \ No newline at end of file diff --git a/tests/core/user_created/send_jisc_data/event.json b/tests/core/user_created/send_jisc_data/event.json new file mode 100644 index 0000000..cef1276 --- /dev/null +++ b/tests/core/user_created/send_jisc_data/event.json @@ -0,0 +1,10 @@ +{ + "id": 1, + "relateduserid": 1, + "courseid": 1, + "timecreated": 1433946701, + "objecttable": "user", + "objectid": 1, + "eventname": "\\core\\event\\user_created", + "ip": "127.0.0.1" +} \ No newline at end of file diff --git a/tests/core/user_created/send_jisc_data/statements.json b/tests/core/user_created/send_jisc_data/statements.json new file mode 100644 index 0000000..96fe373 --- /dev/null +++ b/tests/core/user_created/send_jisc_data/statements.json @@ -0,0 +1,55 @@ +[ + { + "actor": { + "name": "test_fullname", + "account": { + "homePage": "http:\/\/www.example.org", + "name": "1" + } + }, + "verb": { + "id": "http:\/\/adlnet.gov\/expapi\/verbs\/registered", + "display": { + "en": "registered to" + } + }, + "object": { + "id": "http:\/\/www.example.org", + "definition": { + "type": "http:\/\/id.tincanapi.com\/activitytype\/lms", + "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": "\\core\\event\\user_created", + "event_function": "\\src\\transformer\\events\\core\\user_created" + }, + "http:\/\/xapi.jisc.ac.uk\/sessionId": "test_session_id", + "http:\/\/id.tincanapi.com\/extension\/ip-address": "127.0.0.1", + "http:\/\/xapi.jisc.ac.uk\/statementCat": "VLE" + }, + "contextActivities": { + "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/user_created/send_jisc_data/test.php b/tests/core/user_created/send_jisc_data/test.php new file mode 100644 index 0000000..7409f36 --- /dev/null +++ b/tests/core/user_created/send_jisc_data/test.php @@ -0,0 +1,32 @@ +<?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\core\user_created\send_jisc_data; +defined('MOODLE_INTERNAL') || die(); + +class test extends \tests\xapi_test_case { + protected function get_test_dir() { + return __DIR__; + } + + protected function get_transformer_config() { + $testdata = $this->get_test_data(); + $transformerconfig = parent::get_transformer_config(); + return array_merge($transformerconfig, [ + 'send_jisc_data' => true, + ]); + } +} \ No newline at end of file diff --git a/tests/xapi_test_case.php b/tests/xapi_test_case.php index 1c961ac..834465c 100644 --- a/tests/xapi_test_case.php +++ b/tests/xapi_test_case.php @@ -79,6 +79,8 @@ abstract class xapi_test_case extends PhpUnitTestCase { 'send_short_course_id' => false, 'send_course_and_module_idnumber' => false, 'send_username' => false, + 'send_jisc_data' => false, + 'session_id' => 'test_session_id', 'plugin_url' => 'https://github.com/xAPI-vle/moodle-logstore_xapi', 'plugin_version' => '0.0.0-development', 'repo' => new \src\transformer\repos\TestRepository($testdata), -- GitLab