Skip to content

Commit

Permalink
wiki comment created
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Nov 12, 2024
1 parent c6889b1 commit 8597646
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 1 deletion.
82 changes: 82 additions & 0 deletions src/transformer/events/mod_wiki/comment_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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 comment created event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/

function comment_created(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);
$comment = $repo->read_record_by_id('comments', $event->objectid);
$wikipage = $repo->read_record_by_id('wiki_pages', $comment->itemid);
$lang = utils\get_course_lang($course);

return[[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://adlnet.gov/expapi/verbs/commented',
'display' => [
$lang => 'Commented'
],
],
'object' => utils\get_activity\wiki_discussion(
$config, $course, $wikipage
),
'result' => [
'response' => utils\get_string_html_removed($comment->content),
],
'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 @@ -137,6 +137,7 @@ function get_event_function_map() {
'\mod_survey\event\course_module_viewed' => 'all\course_module_viewed',
'\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_workshop\event\course_module_viewed' => 'all\course_module_viewed',
'\totara_program\event\program_assigned' => 'totara_program\program_assigned'

Expand Down
13 changes: 13 additions & 0 deletions src/transformer/utils/get_activity/course_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ function course_module(array $config, \stdClass $course, int $cmid) {
);
}

// Wiki
if ($module->name === 'wiki') {
$def = [
'type' => $activitytype,
'name' => [
$courselang => $instancename,
],
'description' => [
$courselang => utils\get_string_html_removed($instance->intro),
]
];
}

$object = [
'id' => $coursemoduleurl,
'definition' => $def,
Expand Down
53 changes: 53 additions & 0 deletions src/transformer/utils/get_activity/wiki_discussion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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 wiki discussion activity objects.
*
* @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 wiki discussion activity objects.
*
* @param array $config The transformer config settings.
* @param \stdClass $course The course object.
* @param \stdClass $wikipage The wiki page object.
* @return array
*/
function wiki_discussion(
array $config,
\stdClass $course,
\stdClass $wikipage
) {
$lang = utils\get_course_lang($course);

return [
'id' => $config['app_url'] . '/mod/wiki/comments.php?pageid=' . $wikipage->id,
'definition' => [
'type' => 'http://id.tincanapi.com/activitytype/discussion',
'name' => [
$lang => $wikipage->title . ' Discussion',
],
],
];
}
56 changes: 56 additions & 0 deletions src/transformer/utils/get_activity/wiki_page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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 wiki page activity objects.
*
* @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 wiki page activity objects.
*
* @param array $config The transformer config settings.
* @param \stdClass $course The course object.
* @param \stdClass $wikipage The wiki page object.
* @return array
*/
function wiki_page(
array $config,
\stdClass $course,
\stdClass $wikipage
) {
$lang = utils\get_course_lang($course);

return [
'id' => $config['app_url'] . '/mod/wiki/view.php?pageid=' . $wikipage->id,
'definition' => [
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/wiki-page',
'name' => [
$lang => $wikipage->title,
],
'description' => [
$lang => utils\get_string_html_removed($wikipage->cachedcontent),
]
],
];
}
70 changes: 70 additions & 0 deletions tests/mod_wiki/comment_created/comment_created_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 created.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_created_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_created
* @return void
*/
public function test_init() {

}
}
36 changes: 36 additions & 0 deletions tests/mod_wiki/comment_created/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/comment_created/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\\comment_created",
"objectid": 1,
"objecttable": "comments"
}
Loading

0 comments on commit 8597646

Please sign in to comment.