Skip to content

Commit

Permalink
Merge pull request #21 from yetanalytics/course_module_completion_upd…
Browse files Browse the repository at this point in the history
…ated

Course module completion updated
  • Loading branch information
milt authored Oct 10, 2024
2 parents b1b7fb1 + 962872d commit 5b7811c
Show file tree
Hide file tree
Showing 292 changed files with 12,082 additions and 11,864 deletions.
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "xapi-vle/moodle-logstore-xapi",
"license": "GPL v3",
"require-dev": {
"learninglocker/statementfactory": "~0.0"
},
"require": {
"ext-json": "*"
},
"prefer-stable": true,
"minimum-stability": "dev"
}
"name": "xapi-vle/moodle-logstore-xapi",
"license": "GPL v3",
"require-dev": {
"learninglocker/statementfactory": "~0.0"
},
"require": {
"ext-json": "*"
},
"prefer-stable": true,
"minimum-stability": "dev"
}
3 changes: 1 addition & 2 deletions src/transformer/events/all/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/lms/module'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
30 changes: 20 additions & 10 deletions src/transformer/events/core/course_module_completion_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,41 @@ function course_module_completion_updated(array $config, \stdClass $event) {
$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);
$completionstate = unserialize($event->other)['completionstate'];

return [[
'actor' => utils\get_user($config, $user),
'verb' => [
if ($completionstate) {
$verb = [
'id' => 'http://adlnet.gov/expapi/verbs/completed',
'display' => [
$lang => 'completed'
$lang => 'Completed'
],
],
];
} else {
$verb = [
'id' => 'https://xapi.edlm/profiles/edlm-lms/concepts/verbs/uncompleted',
'display' => [
$lang => 'Uncompleted'
],
];
}

return [[
'actor' => utils\get_user($config, $user),
'verb' => $verb,
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/lms/module'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
'extensions' => utils\extensions\base($config, $event, $course),
'contextActivities' => [
'grouping' => [
utils\get_activity\site($config),
'parent' => [
utils\get_activity\course($config, $course),
],
'category' => [
utils\get_activity\source($config),
utils\get_activity\site($config),
]
],
]
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_book/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/book'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'https://w3id.org/xapi/acrossx/activities/face-to-face-discussion'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_lesson/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://adlnet.gov/expapi/activities/lesson'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_page/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'https://w3id.org/xapi/acrossx/activities/page'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_resource/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/resource'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_scorm/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/legacy-learning-standard'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_survey/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/survey'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/events/mod_url/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function course_module_viewed(array $config, \stdClass $event) {
'object' => utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://adlnet.gov/expapi/activities/link'
$event->contextinstanceid
),
'context' => [
'language' => $lang,
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/utils/get_activity/course_feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function course_feedback(array $config, \stdClass $course, string $cmid) {
return utils\get_activity\course_module(
$config,
$course,
$cmid,
'http://id.tincanapi.com/activitytype/survey'
$cmid
);
}
3 changes: 1 addition & 2 deletions src/transformer/utils/get_activity/course_forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function course_forum(array $config, \stdClass $course, string $cmid) {
return utils\get_activity\course_module(
$config,
$course,
$cmid,
'http://id.tincanapi.com/activitytype/forum-topic'
$cmid
);
}
10 changes: 7 additions & 3 deletions src/transformer/utils/get_activity/course_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @copyright Jerret Fowler <[email protected]>
* Ryan Smith <https://www.linkedin.com/in/ryan-smith-uk/>
* David Pesce <[email protected]>
* Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -34,10 +35,9 @@
* @param array $config The transformer config settings.
* @param \stdClass $course The course object.
* @param int $cmid The id of the context.
* @param string $xapitype The type of xAPI object.
* @return array
*/
function course_module(array $config, \stdClass $course, int $cmid, string $xapitype) {
function course_module(array $config, \stdClass $course, int $cmid) {
$repo = $config['repo'];
$coursemodule = $repo->read_record_by_id('course_modules', $cmid);
$module = $repo->read_record_by_id('modules', $coursemodule->module);
Expand All @@ -47,10 +47,14 @@ function course_module(array $config, \stdClass $course, int $cmid, string $xapi
$courselang = utils\get_course_lang($course);
$instancename = property_exists($instance, 'name') ? $instance->name : $module->name;

$activitytype = utils\get_module_activity_type($module->name);

// TODO: Some objects (like mod_choice CMI interactions) will need more
// dispatch and add those here
$object = [
'id' => $coursemoduleurl,
'definition' => [
'type' => $xapitype,
'type' => $activitytype,
'name' => [
$courselang => $instancename,
],
Expand Down
7 changes: 3 additions & 4 deletions src/transformer/utils/get_activity/course_quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
* @return array
*/
function course_quiz(array $config, \stdClass $course, string $cmid) {
$xapytype = 'http://adlnet.gov/expapi/activities/assessment';
$xapiobject = utils\get_activity\course_module($config, $course, $cmid);

// JISC specific activity type.
if (utils\is_enabled_config($config, 'send_jisc_data')) {
$xapytype = 'http://xapi.jisc.ac.uk/activities/quiz';
$xapiobject['definition']['type'] = 'http://xapi.jisc.ac.uk/activities/quiz';
}

return utils\get_activity\course_module($config, $course, $cmid, $xapytype);
return $xapiobject;
}
78 changes: 78 additions & 0 deletions src/transformer/utils/get_module_activity_type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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/>.

/**
* Transformer utility for retrieving course module activity types.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace src\transformer\utils;

use src\transformer\utils as utils;

/**
* Return the mapping of modules to activity types.
* @return array
*/

function get_module_activity_type_mapping() {
return [
'assign' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/assignment',
'bigbluebuttonbn' => 'http://adlnet.gov/expapi/activities/meeting',
'book' => 'http://id.tincanapi.com/activitytype/book',
'chat' => 'http://id.tincanapi.com/activitytype/chat-channel',
'choice' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'data' => 'http://xapi.org.au/contentprofile/activitytype/database',
'facetoface' => 'https://w3id.org/xapi/acrossx/activities/face-to-face-discussion',
'feedback' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/feedback',
'folder' => 'http://activitystrea.ms/collection',
'forum' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/forum',
'glossary' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/glossary',
'h5pactivity' => 'http://adlnet.gov/expapi/activities/media',
'imscp' => 'https://w3id.org/xapi/cmi5/activitytype/course',
'label' => 'https://w3id.org/xapi/acrossx/activities/webpage',
'lesson' => 'http://adlnet.gov/expapi/activities/lesson',
'lti' => 'http://adlnet.gov/expapi/activities/media',
'page' => 'https://w3id.org/xapi/acrossx/activities/page',
'quiz' => 'http://adlnet.gov/expapi/activities/assessment',
'resource' => 'http://id.tincanapi.com/activitytype/resource',
'scorm' => 'http://id.tincanapi.com/activitytype/legacy-learning-standard',
'url' => 'http://adlnet.gov/expapi/activities/link',
'wiki' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/wiki',
'workshop' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/workshop',
'questionnaire' => 'http://id.tincanapi.com/activitytype/survey',
'survey' => 'http://id.tincanapi.com/activitytype/survey'
];
}

/**
* Return an activity type or default for a given module name.
*
* @param string $module_name The name of a moodle course module.
* @return string
*/
function get_module_activity_type($module_name) {
$module_uris = get_module_activity_type_mapping();

if (array_key_exists($module_name, $module_uris)) {
return $module_uris[$module_name];
} else {
return 'http://id.tincanapi.com/activitytype/lms/module';
}
}
3 changes: 1 addition & 2 deletions tests/common/event.json
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{
}
{}
10 changes: 5 additions & 5 deletions tests/common/statement.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"timestamp": "2015-06-10T14:31:41.000Z",
"context": {
"platform": "Moodle",
"registration": "58028332-2277-5b51-a632-7836992917ea"
}
"timestamp": "2015-06-10T14:31:41.000Z",
"context": {
"platform": "Moodle",
"registration": "58028332-2277-5b51-a632-7836992917ea"
}
}
16 changes: 8 additions & 8 deletions tests/core/badge_awarded/user_achieved_badge/event.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id":1,
"eventname":"\\core\\event\\badge_awarded",
"timecreated": 1433946701,
"relateduserid": 1,
"courseid": 1,
"objectid": 1,
"other": "a:1:{s:13:\"badgeissuedid\";i:2;}",
"objecttable": "badge"
"id": 1,
"eventname": "\\core\\event\\badge_awarded",
"timecreated": 1433946701,
"relateduserid": 1,
"courseid": 1,
"objectid": 1,
"other": "a:1:{s:13:\"badgeissuedid\";i:2;}",
"objecttable": "badge"
}
Loading

0 comments on commit 5b7811c

Please sign in to comment.