Commit 82d341cf authored by Damyon Wiese's avatar Damyon Wiese
Browse files

Merge branch 'MDL-49503-master' of git://github.com/jleyva/moodle

Conflicts:
	lib/db/services.php
	version.php
parents 037546ae d508dfe7
......@@ -1105,6 +1105,7 @@ $services = array(
'core_user_view_user_list',
'core_message_mark_message_read',
'core_notes_view_notes',
'mod_forum_view_forum_discussion',
),
'enabled' => 0,
'restrictedusers' => 0,
......
......@@ -71,4 +71,13 @@ $functions = array(
'type' => 'write',
'capabilities' => 'mod/forum:viewdiscussion'
),
'mod_forum_view_forum_discussion' => array(
'classname' => 'mod_forum_external',
'methodname' => 'view_forum_discussion',
'classpath' => 'mod/forum/externallib.php',
'description' => 'Simulate the forum/discuss.php web interface page: trigger events, completion, etc...',
'type' => 'write',
'capabilities' => 'mod/forum:viewdiscussion'
),
);
......@@ -172,14 +172,8 @@ if ($move > 0 and confirm_sesskey()) {
redirect($return.'&moved=-1&sesskey='.sesskey());
}
$params = array(
'context' => $modcontext,
'objectid' => $discussion->id,
);
$event = \mod_forum\event\discussion_viewed::create($params);
$event->add_record_snapshot('forum_discussions', $discussion);
$event->add_record_snapshot('forum', $forum);
$event->trigger();
// Trigger discussion viewed event.
forum_discussion_view($modcontext, $forum, $discussion);
unset($SESSION->fromdiscussion);
......
......@@ -872,4 +872,68 @@ class mod_forum_external extends external_api {
);
}
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 2.9
*/
public static function view_forum_discussion_parameters() {
return new external_function_parameters(
array(
'discussionid' => new external_value(PARAM_INT, 'discussion id')
)
);
}
/**
* Simulate the forum/discuss.php web interface page: trigger events
*
* @param int $discussionid the discussion id
* @return array of warnings and status result
* @since Moodle 2.9
* @throws moodle_exception
*/
public static function view_forum_discussion($discussionid) {
global $DB, $CFG;
require_once($CFG->dirroot . "/mod/forum/lib.php");
$params = self::validate_parameters(self::view_forum_discussion_parameters(),
array(
'discussionid' => $discussionid
));
$warnings = array();
$discussion = $DB->get_record('forum_discussions', array('id' => $params['discussionid']), '*', MUST_EXIST);
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
// Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
$modcontext = context_module::instance($cm->id);
self::validate_context($modcontext);
// Call the forum/lib API.
forum_discussion_view($modcontext, $forum, $discussion);
$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
return $result;
}
/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 2.9
*/
public static function view_forum_discussion_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'warnings' => new external_warnings()
)
);
}
}
......@@ -7791,5 +7791,25 @@ function forum_view($forum, $course, $cm, $context) {
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('forum', $forum);
$event->trigger();
}
/**
* Trigger the discussion viewed event
*
* @param stdClass $modcontext module context object
* @param stdClass $forum forum object
* @param stdClass $discussion discussion object
* @since Moodle 2.9
*/
function forum_discussion_view($modcontext, $forum, $discussion) {
$params = array(
'context' => $modcontext,
'objectid' => $discussion->id,
);
$event = \mod_forum\event\discussion_viewed::create($params);
$event->add_record_snapshot('forum_discussions', $discussion);
$event->add_record_snapshot('forum', $forum);
$event->trigger();
}
......@@ -1295,6 +1295,44 @@ class mod_forum_lib_testcase extends advanced_testcase {
}
/**
* Test forum_discussion_view.
*/
public function test_forum_discussion_view() {
global $CFG, $USER;
$this->resetAfterTest();
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
$discussion = $this->create_single_discussion_with_replies($forum, $USER, 2);
$context = context_module::instance($forum->cmid);
$cm = get_coursemodule_from_instance('forum', $forum->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$this->setAdminUser();
forum_discussion_view($context, $forum, $discussion);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_pop($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\mod_forum\event\discussion_viewed', $event);
$this->assertEquals($context, $event->get_context());
$expected = array($course->id, 'forum', 'view discussion', "discuss.php?d={$discussion->id}",
$discussion->id, $forum->cmid);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
}
/**
* Create a new course, forum, and user with a number of discussions and replies.
*
......
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015040700.02; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2015040700.03; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment