Exemple #1
0
/**
 * 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();
}
    $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id));
    $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id));
    $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromforumid' => $forum->id, 'toforumid' => $forumto->id));
    $event = \mod_forum\event\discussion_moved::create($params);
    $event->add_record_snapshot('forum_discussions', $discussion);
    $event->add_record_snapshot('forum', $forum);
    $event->add_record_snapshot('forum', $forumto);
    $event->trigger();
    // Delete the RSS files for the 2 forums to force regeneration of the feeds
    require_once $CFG->dirroot . '/mod/forum/rsslib.php';
    forum_rss_delete_file($forum);
    forum_rss_delete_file($forumto);
    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();
unset($SESSION->fromdiscussion);
if ($mode) {
    set_user_preference('forum_displaymode', $mode);
}
$displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
if ($parent) {
    // If flat AND parent, then force nested display this time
    if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) {
        $displaymode = FORUM_MODE_NESTED;
    }
} else {
    $parent = $discussion->firstpost;
Exemple #3
0
 /**
  * Test discussion_viewed event.
  */
 public function test_discussion_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['forum'] = $forum->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
     $context = context_module::instance($forum->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id);
     $event = \mod_forum\event\discussion_viewed::create($params);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($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());
 }