Skip to content

Commit

Permalink
group member added/removed (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
milt authored Oct 25, 2024
1 parent 806ef87 commit 9f3df5c
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/transformer/events/core/group_member_added.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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 the group member added 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;

/**
* Transform for the group member added event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/
function group_member_added(array $config, \stdClass $event) {
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->userid);
$member = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$lang = utils\get_course_lang($course);
$group = $repo->read_record_by_id($event->objecttable, $event->objectid);

return [[
'actor' => utils\get_user($config, $member),
'verb' => [
'id' => 'http://activitystrea.ms/join',
'display' => [
$lang => 'Joined'
],
],
'object' => utils\get_activity\course_group($config, $course, $group),
'context' => [
'instructor' => utils\get_user($config, $user),
'extensions' => utils\extensions\base($config, $event, null),
'contextActivities' => [
'parent' => [
utils\get_activity\course($config, $course),
],
'category' => [
utils\get_activity\site($config),
],
],
]
]];
}
66 changes: 66 additions & 0 deletions src/transformer/events/core/group_member_removed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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 the group member removed 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;

/**
* Transform for the group member removed event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/
function group_member_removed(array $config, \stdClass $event) {
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->userid);
$member = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$lang = utils\get_course_lang($course);
$group = $repo->read_record_by_id($event->objecttable, $event->objectid);

return [[
'actor' => utils\get_user($config, $member),
'verb' => [
'id' => 'http://activitystrea.ms/leave',
'display' => [
$lang => 'Left'
],
],
'object' => utils\get_activity\course_group($config, $course, $group),
'context' => [
'instructor' => utils\get_user($config, $user),
'extensions' => utils\extensions\base($config, $event, null),
'contextActivities' => [
'parent' => [
utils\get_activity\course($config, $course),
],
'category' => [
utils\get_activity\site($config),
],
],
]
]];
}
2 changes: 2 additions & 0 deletions src/transformer/get_event_function_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function get_event_function_map() {
'\core\event\course_resources_list_viewed' => 'core\course_resources_list_viewed',
'\core\event\group_created' => 'core\group_created',
'\core\event\group_deleted' => 'core\group_deleted',
'\core\event\group_member_added' => 'core\group_member_added',
'\core\event\group_member_removed' => 'core\group_member_removed',
'\core\event\user_created' => 'core\user_created',
'\core\event\user_enrolment_created' => 'core\user_enrolment_created',
'\core\event\user_loggedin' => 'core\user_loggedin',
Expand Down
20 changes: 20 additions & 0 deletions tests/core/group_member_added/new_group_member_added/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"user": [
{
"id": 1,
"firstname": "test_fullname1",
"email": "[email protected]"
},
{
"id": 2,
"firstname": "test_fullname2",
"email": "[email protected]"
}
],
"groups": [
{
"id": 1,
"name": "test_name"
}
]
}
10 changes: 10 additions & 0 deletions tests/core/group_member_added/new_group_member_added/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": 1,
"objecttable": "groups",
"timecreated": 1433946701,
"objectid": 1,
"courseid": 1,
"eventname": "\\core\\event\\group_member_added",
"userid": 1,
"relateduserid": 2
}
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/>.

namespace logstore_xapi\core\group_member_added\new_group_member_added_test;

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->dirroot . '/admin/tool/log/store/xapi/tests/xapi_test_case.php');

/**
* Unit test for group member added event.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class new_group_member_added_test extends \logstore_xapi\xapi_test_case {

/**
* Retrieve the directory of the unit test.
*
* @return string
*/
protected function get_test_dir() {
return __DIR__;
}

/**
* Retrieve the plugin type being tested.
*
* @return string
*/
protected function get_plugin_type() {
return "core";
}

/**
* Retrieve the plugin name being tested.
*
* @return string
*/
protected function get_plugin_name() {
return "course";
}

/**
* Appease auto-detecting of test cases. xapi_test_case has default test cases.
*
* @covers ::attempt_submitted
* @return void
*/
public function test_init() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"actor": {
"account": {
"homePage": "http://www.example.org",
"name": "2"
},
"name": "test_fullname2"
},
"verb": {
"id": "http://activitystrea.ms/join",
"display": {
"en": "Joined"
}
},
"object": {
"id": "http://www.example.org/group/index.php?id=1",
"objectType": "Activity",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/group",
"name": {
"en": "test_name"
}
}
},
"context": {
"instructor": {
"account": {
"homePage": "http://www.example.org",
"name": "1"
},
"name": "test_fullname1"
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/course/view.php?id=1",
"definition": {
"type": "https://w3id.org/xapi/cmi5/activitytype/course",
"name": {
"en": "test_name"
}
}
}
],
"category": [
{
"id": "http://www.example.org",
"definition": {
"type": "http://id.tincanapi.com/activitytype/lms",
"name": {
"en": "test_name"
}
}
}
]
},
"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\\group_member_added",
"event_function": "\\src\\transformer\\events\\core\\group_member_added"
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"user": [
{
"id": 1,
"firstname": "test_fullname1",
"email": "[email protected]"
},
{
"id": 2,
"firstname": "test_fullname2",
"email": "[email protected]"
}
],
"groups": [
{
"id": 1,
"name": "test_name"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": 1,
"objecttable": "groups",
"timecreated": 1433946701,
"objectid": 1,
"courseid": 1,
"eventname": "\\core\\event\\group_member_removed",
"userid": 1,
"relateduserid": 2
}
Loading

0 comments on commit 9f3df5c

Please sign in to comment.