Skip to content

Commit

Permalink
comment deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Nov 13, 2024
1 parent 8597646 commit 9d40db5
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 0 deletions.
95 changes: 95 additions & 0 deletions src/transformer/events/mod_wiki/comment_deleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?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 wiki discussion comment 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\mod_wiki;

use src\transformer\utils as utils;

/**
* Transformer fn for wiki discussion comment deleted event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/

function comment_deleted(array $config, \stdClass $event) {
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->userid);
$course = $repo->read_record_by_id('course', $event->courseid);
$wikipage = $repo->read_record_by_id(
'wiki_pages',
(int) unserialize($event->other)['itemid']
);
$lang = utils\get_course_lang($course);

return[[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://activitystrea.ms/delete',
'display' => [
$lang => 'Deleted'
],
],
'object' => [
'id' => $config['app_url']
. '/mod/wiki/instancecomments.php?commentid=' . $event->objectid
. '&pageid=' . $wikipage->id,
'objectType' => 'Activity',
'definition' => [
'type' => 'http://activitystrea.ms/comment',
'name' => [
'en' => 'Comment',
],
],
],
'context' => [
'language' => $lang,
'extensions' => utils\extensions\base($config, $event, $course),
'contextActivities' => [
'parent' => [
utils\get_activity\wiki_discussion(
$config,
$course,
$wikipage
),
utils\get_activity\wiki_page(
$config,
$course,
$wikipage
),
...utils\context_activities\get_parent(
$config,
$event->contextinstanceid,
true
),
],
'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 @@ -138,6 +138,7 @@ function get_event_function_map() {
'\mod_url\event\course_module_viewed' => 'all\course_module_viewed',
'\mod_wiki\event\course_module_viewed' => 'all\course_module_viewed',
'\mod_wiki\event\comment_created' => 'mod_wiki\comment_created',
'\mod_wiki\event\comment_deleted' => 'mod_wiki\comment_deleted',
'\mod_workshop\event\course_module_viewed' => 'all\course_module_viewed',
'\totara_program\event\program_assigned' => 'totara_program\program_assigned'

Expand Down
70 changes: 70 additions & 0 deletions tests/mod_wiki/comment_deleted/comment_deleted_test.php
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\mod_wiki;

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

global $CFG;

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

/**
* Unit test for wiki comment deleted.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_deleted_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 "mod_survey";
}

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

}
}
29 changes: 29 additions & 0 deletions tests/mod_wiki/comment_deleted/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"modules": [
{
"id": 1,
"name": "wiki"
}
],
"wiki": [
{
"id": 1,
"name": "test_name",
"intro": "<p>test_intro</p>"
}
],
"wiki_subwikis": [
{
"id": 1,
"wikiid": 1
}
],
"wiki_pages": [
{
"id": 1,
"subwikiid": 1,
"title": "test_page_title",
"cachedcontent": "<p>test_content</p>"
}
]
}
11 changes: 11 additions & 0 deletions tests/mod_wiki/comment_deleted/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": 1,
"userid": 1,
"courseid": 1,
"timecreated": 1433946701,
"contextinstanceid": 1,
"eventname": "\\mod_wiki\\event\\comment_deleted",
"objectid": 1,
"objecttable": "comments",
"other": "a:1:{s:6:\"itemid\";s:1:\"1\";}"
}
105 changes: 105 additions & 0 deletions tests/mod_wiki/comment_deleted/statements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[
{
"actor": {
"name": "test_fullname",
"account": {
"homePage": "http://www.example.org",
"name": "1"
}
},
"verb": {
"id": "http://activitystrea.ms/delete",
"display": {
"en": "Deleted"
}
},
"object": {
"id": "http://www.example.org/mod/wiki/instancecomments.php?commentid=1&pageid=1",
"objectType": "Activity",
"definition": {
"type": "http://activitystrea.ms/comment",
"name": {
"en": "Comment"
}
}
},
"context": {
"language": "en",
"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": "\\mod_wiki\\event\\comment_deleted",
"event_function": "\\src\\transformer\\events\\mod_wiki\\comment_deleted"
}
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/mod/wiki/comments.php?pageid=1",
"definition": {
"type": "http://id.tincanapi.com/activitytype/discussion",
"name": {
"en": "test_page_title Discussion"
}
}
},
{
"id": "http://www.example.org/mod/wiki/view.php?pageid=1",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/wiki-page",
"name": {
"en": "test_page_title"
},
"description": {
"en": "test_content"
}
}
},
{
"id": "http://www.example.org/mod/wiki/view.php?id=1",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/wiki",
"name": {
"en": "test_name"
},
"description": {
"en": "test_intro"
}
}
},
{
"id": "http://www.example.org/course/section.php?id=1",
"objectType": "Activity",
"definition": {
"name": {
"en": "test_name Section 0"
},
"type": "http://id.tincanapi.com/activitytype/section"
}
},
{
"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"
}
}
}
]
}
}
}
]

0 comments on commit 9d40db5

Please sign in to comment.