Skip to content

Commit

Permalink
send group message recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Dec 9, 2024
1 parent a7fc6a2 commit bd0e431
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/transformer/events/core/group_message_sent.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,32 @@ function group_message_sent(array $config, \stdClass $event) {
$course = $repo->read_record_by_id('course', $group->courseid);
$lang = utils\get_course_lang($course);

return [[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://activitystrea.ms/send',
'display' => [
'en' => 'Sent'
],
$statement = [
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://activitystrea.ms/send',
'display' => [
'en' => 'Sent'
],
'object' => utils\get_activity\message($config, $lang, $message),
'context' => [
...utils\get_context_base($config, $event, $lang, $course),
'contextActivities' => [
'grouping' => [
utils\get_activity\course_group($config, $course, $group)
],
'parent' => [
utils\get_activity\course($config, $course),
],
'category' => [
utils\get_activity\site($config),
],
],
]
]];
],
'object' => utils\get_activity\message($config, $lang, $message),
'context' => [
...utils\get_context_base($config, $event, $lang, $course),
'contextActivities' => [
'grouping' => [
utils\get_activity\course_group($config, $course, $group)
],
'parent' => [
utils\get_activity\course($config, $course),
],
'category' => [
utils\get_activity\site($config),
],
],
]
];
$statement['context']['extensions']['https://yetanalytics.com/profiles/prepositions/concepts/context-extensions/to'] = utils\get_group($config, $group);
return [
$statement
];
}
66 changes: 66 additions & 0 deletions src/transformer/utils/get_group.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/>.

/**
* Transformer utility for retrieving group data.
*
* @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;

/**
* Transformer utility for retrieving group data.
*
* @param array $config The transformer config settings.
* @param \stdClass $group The group object.
* @return array
*/
function get_group(array $config, \stdClass $group) {
$repo = $config['repo'];
$members = $repo->read_records(
'groups_members',
['groupid' => $group->id]
);
$users =
array_values(
array_map(
function($member) use ($repo) {
return $repo->read_record_by_id('user', $member->userid);
},
$members
)
);

return [
'objectType' => 'Group',
...((isset($group->name))
? [
'name' => $group->name
]
: []),
'member' => array_values(
array_map(
function($user) use ($config) {
return get_user($config, $user);
},
$users
)
),
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@
"id": 1,
"itemid": 1
}
],
"groups_members": [
{
"groupid": 1,
"userid": 1
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
"event_name": "\\core\\event\\group_message_sent",
"http://moodle.org": "1.0.0",
"https://github.com/xAPI-vle/moodle-logstore_xapi": "0.0.0-development"
},
"https://yetanalytics.com/profiles/prepositions/concepts/context-extensions/to": {
"name": "test_name",
"objectType": "Group",
"member": [
{
"account": {
"homePage": "http://www.example.org",
"name": "1"
},
"name": "test_fullname"
}
]
}
}
}
Expand Down

0 comments on commit bd0e431

Please sign in to comment.