Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group message sent #32

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/transformer/events/core/group_message_sent.php
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/>.

/**
* Transformer fn for group message sent 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 group message sent event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/

function group_message_sent(array $config, \stdClass $event) {
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->userid);
$message = $repo->read_record_by_id('messages', $event->objectid);
$conversation = $repo->read_record_by_id(
'message_conversations',
$message->conversationid
);
$group = $repo->read_record_by_id('groups', $conversation->itemid);
$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' => [
$lang => 'Sent'
],
],
'object' => utils\get_activity\message($config, $lang, $message),
'context' => [
'extensions' => utils\extensions\base($config, $event, null),
'contextActivities' => [
'grouping' => [
utils\get_activity\course_group($config, $course, $group)
],
'parent' => [
utils\get_activity\course($config, $course),
],
'category' => [
utils\get_activity\site($config),
],
],
]
]];
}
1 change: 1 addition & 0 deletions src/transformer/get_event_function_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ 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_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',
Expand Down
51 changes: 51 additions & 0 deletions src/transformer/utils/get_activity/message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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 message activities.
*
* @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\get_activity;

use src\transformer\utils as utils;

/**
* Transformer utility for retrieving message activities.
*
* @param array $config The transformer config settings.
* @param string $lang The language tag to use.
* @param \stdClass $message The message.
* @return array
*/
function message(array $config, string $lang, \stdClass $message) {
return [
'id' => $config['app_url'] . '/message?id=' . $message->id,
'objectType' => 'Activity',
'definition' => [
'type' => 'http://id.tincanapi.com/activitytype/chat-message',
'name' => [
$lang => $message->subject ?? '[Untitled Message]',
],
'description' => [
$lang => $message->fullmessage,
],
]
];
}
23 changes: 23 additions & 0 deletions tests/core/group_message_sent/new_group_message_sent/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"groups": [
{
"id": 1,
"name": "test_name",
"courseid": 1
}
],
"messages": [
{
"id": 1,
"subject": "test_message_subject",
"fullmessage": "test_message_body",
"conversationid": 1
}
],
"message_conversations": [
{
"id": 1,
"itemid": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"courseid": 1,
"eventname": "\\core\\event\\group_message_sent",
"id": 1,
"objectid": 1,
"objecttable": "messages",
"timecreated": 1433946701,
"userid": 1
}
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_message_sent\new_group_message_sent;

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

global $CFG;

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

/**
* Unit test for group_message_sent 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_message_sent_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,76 @@
[
{
"actor": {
"account": {
"homePage": "http://www.example.org",
"name": "1"
},
"name": "test_fullname"
},
"verb": {
"display": {
"en": "Sent"
},
"id": "http://activitystrea.ms/send"
},
"object": {
"id": "http://www.example.org/message?id=1",
"objectType": "Activity",
"definition": {
"name": {
"en": "test_message_subject"
},
"description": {
"en": "test_message_body"
},
"type": "http://id.tincanapi.com/activitytype/chat-message"
}
},
"context": {
"contextActivities": {
"grouping": [
{
"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"
}
}
}
],
"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": {
"event_function": "\\src\\transformer\\events\\core\\group_message_sent",
"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"
}
}
}
}
]
Loading