예제 #1
0
if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) {
    print_error('invalidcoursemodule');
}
require_login($course, false, $cm);
$returnpageurl = new moodle_url('/mod/forum/' . $returnpage, array('id' => $course->id, 'f' => $forum->id));
$returnto = forum_go_back_to($returnpageurl);
if (!forum_tp_can_track_forums($forum)) {
    redirect($returnto);
}
$info = new stdClass();
$info->name = fullname($USER);
$info->forum = format_string($forum->name);
$eventparams = array('context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, 'other' => array('forumid' => $forum->id));
if (forum_tp_is_tracked($forum)) {
    if (forum_tp_stop_tracking($forum->id)) {
        $event = \mod_forum\event\readtracking_disabled::create($eventparams);
        $event->trigger();
        redirect($returnto, get_string("nownottracking", "forum", $info), 1);
    } else {
        print_error('cannottrack', '', get_local_referer(false));
    }
} else {
    // subscribe
    if (forum_tp_start_tracking($forum->id)) {
        $event = \mod_forum\event\readtracking_enabled::create($eventparams);
        $event->trigger();
        redirect($returnto, get_string("nowtracking", "forum", $info), 1);
    } else {
        print_error('cannottrack', '', get_local_referer(false));
    }
}
예제 #2
0
 /**
  * Test the readtracking_enabled event.
  */
 public function test_readtracking_enabled()
 {
     // Setup test data.
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     $context = context_module::instance($forum->cmid);
     $params = array('context' => $context, 'other' => array('forumid' => $forum->id), 'relateduserid' => $user->id);
     $event = \mod_forum\event\readtracking_enabled::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\\readtracking_enabled', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'forum', 'start tracking', "view.php?f={$forum->id}", $forum->id, $forum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/forum/view.php', array('f' => $forum->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }