Skip to content

Commit

Permalink
Merge branch 'master' into group_message_sent
Browse files Browse the repository at this point in the history
  • Loading branch information
milt authored Oct 25, 2024
2 parents 0e39c43 + 9f3df5c commit 3ba3d8b
Show file tree
Hide file tree
Showing 26 changed files with 486 additions and 19 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 @@ -49,6 +49,8 @@ function get_event_function_map() {
'\core\event\group_created' => 'core\group_created',
'\core\event\group_deleted' => 'core\group_deleted',
'\core\event\group_message_sent' => 'core\group_message_sent',
'\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
7 changes: 2 additions & 5 deletions src/transformer/utils/get_scaled_score.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 @@ -35,9 +36,5 @@
* @return int
*/
function get_scaled_score($rawscore, $minscore, $maxscore) {
if ($rawscore >= 0) {
return $rawscore / $maxscore;
} else {
return $rawscore / $minscore;
}
return (($rawscore - $minscore) / ($maxscore - $minscore) * 2) - 1;
}
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 3ba3d8b

Please sign in to comment.