/**
  * Test discussion_viewed event.
  */
 public function test_discussion_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $anonforum = $this->getDataGenerator()->create_module('anonforum', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['anonforum'] = $anonforum->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_anonforum')->create_discussion($record);
     $context = context_module::instance($anonforum->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id);
     $event = \mod_anonforum\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_anonforum\\event\\discussion_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'anonforum', 'view discussion', "discuss.php?d={$discussion->id}", $discussion->id, $anonforum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
示例#2
0
    $DB->set_field('anonforum_read', 'anonforumid', $anonforumto->id, array('discussionid' => $discussion->id));
    $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'anonymous' => 1, 'other' => array('fromanonforumid' => $anonforum->id, 'toanonforumid' => $anonforumto->id));
    $event = \mod_anonforum\event\discussion_moved::create($params);
    $event->add_record_snapshot('anonforum_discussions', $discussion);
    $event->add_record_snapshot('anonforum', $anonforum);
    $event->add_record_snapshot('anonforum', $anonforumto);
    $event->trigger();
    // Delete the RSS files for the 2  anonymous forums to force regeneration of the feeds
    require_once $CFG->dirroot . '/mod/anonforum/rsslib.php';
    anonforum_rss_delete_file($anonforum);
    anonforum_rss_delete_file($anonforumto);
    redirect($return . '&moved=-1&sesskey=' . sesskey());
}
if (empty($anonforum->anonymous)) {
    $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'anonymous' => 1);
    $event = \mod_anonforum\event\discussion_viewed::create($params);
    $event->add_record_snapshot('anonforum_discussions', $discussion);
    $event->add_record_snapshot('anonforum', $anonforum);
    $event->trigger();
}
unset($SESSION->fromdiscussion);
if ($mode) {
    set_user_preference('anonforum_displaymode', $mode);
}
$displaymode = get_user_preferences('anonforum_displaymode', $CFG->anonforum_displaymode);
if ($parent) {
    // If flat AND parent, then force nested display this time
    if ($displaymode == ANONFORUM_MODE_FLATOLDEST or $displaymode == ANONFORUM_MODE_FLATNEWEST) {
        $displaymode = ANONFORUM_MODE_NESTED;
    }
} else {