Exemplo n.º 1
0
if (!($cm = get_coursemodule_from_instance("anonforum", $anonforum->id, $course->id))) {
    print_error('invalidcoursemodule');
}
require_course_login($course, false, $cm);
$returnto = anonforum_go_back_to($returnpage . '?id=' . $course->id . '&f=' . $anonforum->id);
if (!anonforum_tp_can_track_anonforums($anonforum)) {
    redirect($returnto);
}
$info = new stdClass();
$info->name = fullname($USER);
$info->anonforum = format_string($anonforum->name);
$eventparams = array('context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, 'anonymous' => 1, 'other' => array('anonforumid' => $anonforum->id));
if (anonforum_tp_is_tracked($anonforum)) {
    if (anonforum_tp_stop_tracking($anonforum->id)) {
        if (empty($anonforum->anonymous)) {
            $event = \mod_anonforum\event\readtracking_disabled::create($eventparams);
            $event->trigger();
        }
        redirect($returnto, get_string("nownottracking", "anonforum", $info), 1);
    } else {
        print_error('cannottrack', '', $_SERVER["HTTP_REFERER"]);
    }
} else {
    // subscribe
    if (anonforum_tp_start_tracking($anonforum->id)) {
        if (empty($anonforum->anonymous)) {
            $event = \mod_anonforum\event\readtracking_enabled::create($eventparams);
            $event->trigger();
        }
        redirect($returnto, get_string("nowtracking", "anonforum", $info), 1);
    } else {
Exemplo n.º 2
0
 /**
  *  Test the readtracking_disabled event.
  */
 public function test_readtracking_disabled()
 {
     // Setup test data.
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $anonforum = $this->getDataGenerator()->create_module('anonforum', array('course' => $course->id));
     $context = context_module::instance($anonforum->cmid);
     $params = array('context' => $context, 'other' => array('anonforumid' => $anonforum->id), 'relateduserid' => $user->id);
     $event = \mod_anonforum\event\readtracking_disabled::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\\readtracking_disabled', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'anonforum', 'stop tracking', "view.php?f={$anonforum->id}", $anonforum->id, $anonforum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/anonforum/view.php', array('f' => $anonforum->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }