forked from adlnet/moodle-logstore_xapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* amend enrolment created event * add possible instructor to enrolment created * user enrolment deleted * correct table * put in our enrol type extension * user enrolment updated * refactor out context building
- Loading branch information
Showing
20 changed files
with
718 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
||
|
@@ -37,31 +38,28 @@ | |
*/ | ||
function user_enrolment_created(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
$user = $repo->read_record_by_id('user', $event->relateduserid); | ||
$user = $repo->read_record_by_id('user', $event->userid); | ||
$cuser = $repo->read_record_by_id('user', $event->relateduserid); | ||
$course = $repo->read_record_by_id('course', $event->courseid); | ||
$lang = utils\get_course_lang($course); | ||
|
||
return[[ | ||
'actor' => utils\get_user($config, $user), | ||
return [[ | ||
'actor' => utils\get_user($config, $cuser), | ||
'verb' => [ | ||
'id' => 'http://adlnet.gov/expapi/verbs/registered', | ||
'id' => 'https://xapi.edlm/profiles/edlm-lms/concepts/verbs/enrolled', | ||
'display' => [ | ||
$lang => 'enrolled to' | ||
$lang => 'Enrolled', | ||
], | ||
], | ||
'object' => utils\get_activity\course($config, $course), | ||
'context' => [ | ||
'language' => $lang, | ||
'extensions' => utils\extensions\base($config, $event, $course), | ||
'contextActivities' => [ | ||
'grouping' => [ | ||
utils\get_activity\site($config) | ||
], | ||
'category' => [ | ||
utils\get_activity\source($config) | ||
] | ||
], | ||
] | ||
'context' => utils\get_enrolment_context( | ||
$config, | ||
$event, | ||
$course, | ||
$cuser, | ||
$user, | ||
$lang | ||
), | ||
]]; | ||
|
||
} |
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,63 @@ | ||
<?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 fn for user enrolment deleted event. | ||
* | ||
* @package logstore_xapi | ||
* @copyright Milt Reder <[email protected]> | ||
* | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace src\transformer\events\core; | ||
|
||
use src\transformer\utils as utils; | ||
|
||
/** | ||
* Transformer fn for user enrolment deleted event. | ||
* | ||
* @param array $config The transformer config settings. | ||
* @param \stdClass $event The event to be transformed. | ||
* @return array | ||
*/ | ||
|
||
function user_enrolment_deleted(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
$user = $repo->read_record_by_id('user', $event->userid); | ||
$cuser = $repo->read_record_by_id('user', $event->relateduserid); | ||
$course = $repo->read_record_by_id('course', $event->courseid); | ||
$lang = utils\get_course_lang($course); | ||
|
||
return [[ | ||
'actor' => utils\get_user($config, $cuser), | ||
'verb' => [ | ||
'id' => 'http://activitystrea.ms/leave', | ||
'display' => [ | ||
$lang => 'Left', | ||
], | ||
], | ||
'object' => utils\get_activity\course($config, $course), | ||
'context' => utils\get_enrolment_context( | ||
$config, | ||
$event, | ||
$course, | ||
$cuser, | ||
$user, | ||
$lang | ||
), | ||
]]; | ||
} |
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,74 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Transform for user enrolment updated event. | ||
* | ||
* @package logstore_xapi | ||
* @copyright Milt Reder <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace src\transformer\events\core; | ||
|
||
use src\transformer\utils as utils; | ||
|
||
/** | ||
* Transformer for the user enrolment updated event. | ||
* | ||
* @param array $config The transformer config settings. | ||
* @param \stdClass $event The event to be transformed. | ||
* @return array | ||
*/ | ||
function user_enrolment_updated(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
$enrolment = $repo->read_record_by_id('user_enrolments', $event->objectid); | ||
$user = $repo->read_record_by_id('user', $event->userid); | ||
$cuser = $repo->read_record_by_id('user', $event->relateduserid); | ||
$course = $repo->read_record_by_id('course', $event->courseid); | ||
$lang = utils\get_course_lang($course); | ||
|
||
if ($enrolment->status == 1) { | ||
$verb = [ | ||
'id' => 'https://w3id.org/xapi/tla/verbs/suspended', | ||
'display' => [ | ||
$lang => 'Suspended', | ||
], | ||
]; | ||
} else { | ||
$verb = [ | ||
'id' => 'https://w3id.org/xapi/tla/verbs/resumed', | ||
'display' => [ | ||
$lang => 'Resumed', | ||
], | ||
]; | ||
} | ||
|
||
return [[ | ||
'actor' => utils\get_user($config, $cuser), | ||
'verb' => $verb, | ||
'object' => utils\get_activity\course($config, $course), | ||
'context' => utils\get_enrolment_context( | ||
$config, | ||
$event, | ||
$course, | ||
$cuser, | ||
$user, | ||
$lang | ||
), | ||
]]; | ||
|
||
} |
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
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,70 @@ | ||
<?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 enrolment context object. | ||
* | ||
* @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 a context object for a user enrolment. | ||
* @param array $config The transformer config array. | ||
* @param \stdClass $event The moodle event. | ||
* @param \stdClass $course The moodle course. | ||
* @param \stdClass $cuser The user attending the course. | ||
* @param \stdClass $user The user triggering the event. | ||
* @param string $lang The language to use. | ||
* @return array | ||
*/ | ||
function get_enrolment_context( | ||
array $config, | ||
\stdClass $event, | ||
\stdClass $course, | ||
\stdClass $cuser, | ||
\stdClass $user, | ||
string $lang | ||
) { | ||
$info = unserialize($event->other); | ||
|
||
$ctx = [ | ||
'language' => $lang, | ||
'extensions' => array_merge( | ||
utils\extensions\base($config, $event, $course), | ||
[ | ||
'https://xapi.edlm/profiles/edlm-lms/concepts/context-extensions/enrolment-type' => | ||
$info['enrol'] | ||
] | ||
), | ||
'contextActivities' => [ | ||
'category' => [ | ||
utils\get_activity\site($config), | ||
], | ||
], | ||
]; | ||
|
||
// add a possible instructor different from course user | ||
if ($cuser->id !== $user->id) { | ||
$ctx['instructor'] = utils\get_user($config, $user); | ||
} | ||
return $ctx; | ||
} |
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 |
---|---|---|
|
@@ -2,15 +2,13 @@ | |
"user": [ | ||
{ | ||
"id": 1, | ||
"firstname": "test_fullname", | ||
"firstname": "test_fullname1", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"course": [ | ||
}, | ||
{ | ||
"id": 1, | ||
"fullname": "test_name", | ||
"lang": "en" | ||
"id": 2, | ||
"firstname": "test_fullname2", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
8 changes: 5 additions & 3 deletions
8
tests/core/user_enrolment_created/existing_user_enrolled/event.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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{ | ||
"id": 1, | ||
"relateduserid": 1, | ||
"userid": 1, | ||
"relateduserid": 2, | ||
"courseid": 1, | ||
"timecreated": 1433946701, | ||
"objecttable": "user", | ||
"objecttable": "user_enrolments", | ||
"objectid": 1, | ||
"eventname": "\\core\\event\\user_enrolment_created" | ||
"eventname": "\\core\\event\\user_enrolment_created", | ||
"other": "a:1:{s:5:\"enrol\";s:6:\"manual\";}" | ||
} |
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
14 changes: 14 additions & 0 deletions
14
tests/core/user_enrolment_deleted/existing_user_enrolment_deleted/data.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,14 @@ | ||
{ | ||
"user": [ | ||
{ | ||
"id": 1, | ||
"firstname": "test_fullname1", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"id": 2, | ||
"firstname": "test_fullname2", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
Oops, something went wrong.