Exemplo n.º 1
0
 /**
  * Test the readtracking_enabled event.
  */
 public function test_readtracking_enabled()
 {
     // Setup test data.
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id));
     $context = context_module::instance($twf->cmid);
     $params = array('context' => $context, 'other' => array('twfid' => $twf->id), 'relateduserid' => $user->id);
     $event = \mod_twf\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_twf\\event\\readtracking_enabled', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'start tracking', "view.php?f={$twf->id}", $twf->id, $twf->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/twf/view.php', array('f' => $twf->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Exemplo n.º 2
0
}
if (!($cm = get_coursemodule_from_instance("twf", $twf->id, $course->id))) {
    print_error('invalidcoursemodule');
}
require_login($course, false, $cm);
$returnto = twf_go_back_to($returnpage . '?id=' . $course->id . '&f=' . $twf->id);
if (!twf_tp_can_track_twfs($twf)) {
    redirect($returnto);
}
$info = new stdClass();
$info->name = fullname($USER);
$info->twf = format_string($twf->name);
$eventparams = array('context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, 'other' => array('twfid' => $twf->id));
if (twf_tp_is_tracked($twf)) {
    if (twf_tp_stop_tracking($twf->id)) {
        $event = \mod_twf\event\readtracking_disabled::create($eventparams);
        $event->trigger();
        redirect($returnto, get_string("nownottracking", "twf", $info), 1);
    } else {
        print_error('cannottrack', '', get_local_referer(false));
    }
} else {
    // subscribe
    if (twf_tp_start_tracking($twf->id)) {
        $event = \mod_twf\event\readtracking_enabled::create($eventparams);
        $event->trigger();
        redirect($returnto, get_string("nowtracking", "twf", $info), 1);
    } else {
        print_error('cannottrack', '', get_local_referer(false));
    }
}