Skip to content

Commit

Permalink
comments viewed
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Nov 13, 2024
1 parent be85657 commit bc18e54
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/transformer/events/mod_wiki/comments_viewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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 created 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 comments viewed event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/

function comments_viewed(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', $event->objectid);
$lang = utils\get_course_lang($course);

return[[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://id.tincanapi.com/verb/viewed',
'display' => [
'en' => 'Viewed'
],
],
'object' => utils\get_activity\wiki_discussion(
$config, $course, $wikipage
),
'context' => [
'language' => $lang,
'extensions' => utils\extensions\base($config, $event, $course),
'contextActivities' => [
'parent' => [
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 @@ -139,6 +139,7 @@ function get_event_function_map() {
'\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_wiki\event\comments_viewed' => 'mod_wiki\comments_viewed',
'\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/comments_viewed/comments_viewed_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 comments viewed.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comments_viewed_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 ::comments_viewed
* @return void
*/
public function test_init() {

}
}
36 changes: 36 additions & 0 deletions tests/mod_wiki/comments_viewed/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"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>"
}
],
"comments": [
{
"id": 1,
"content": "<p>test_content</p>",
"itemid": 1
}
]
}
10 changes: 10 additions & 0 deletions tests/mod_wiki/comments_viewed/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": 1,
"userid": 1,
"courseid": 1,
"timecreated": 1433946701,
"contextinstanceid": 1,
"eventname": "\\mod_wiki\\event\\comments_viewed",
"objectid": 1,
"objecttable": "wiki_pages"
}
95 changes: 95 additions & 0 deletions tests/mod_wiki/comments_viewed/statements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[
{
"actor": {
"name": "test_fullname",
"account": {
"homePage": "http://www.example.org",
"name": "1"
}
},
"verb": {
"id": "http://id.tincanapi.com/verb/viewed",
"display": {
"en": "Viewed"
}
},
"object": {
"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"
}
}
},
"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\\comments_viewed",
"event_function": "\\src\\transformer\\events\\mod_wiki\\comments_viewed"
}
},
"contextActivities": {
"parent": [
{
"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 bc18e54

Please sign in to comment.