예제 #1
0
 /**
  * Test the course_module_viewed event.
  */
 public function test_course_module_viewed()
 {
     // Setup test data.
     $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, 'objectid' => $twf->id);
     $event = \mod_twf\event\course_module_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_twf\\event\\course_module_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'view twf', "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());
 }
예제 #2
0
/**
 * Mark the activity completed (if required) and trigger the course_module_viewed event.
 *
 * @param  stdClass $twf   twf object
 * @param  stdClass $course  course object
 * @param  stdClass $cm      course module object
 * @param  stdClass $context context object
 * @since Moodle 2.9
 */
function twf_view($twf, $course, $cm, $context)
{
    // Completion.
    $completion = new completion_info($course);
    $completion->set_module_viewed($cm);
    // Trigger course_module_viewed event.
    $params = array('context' => $context, 'objectid' => $twf->id);
    $event = \mod_twf\event\course_module_viewed::create($params);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('twf', $twf);
    $event->trigger();
}