public function test_course_module_instance_list_viewed() { // There is no proper API to call to trigger this event, so what we are // doing here is simply making sure that the events returns the right information. $course = $this->getDataGenerator()->create_course(); $event = \mod_glossary\event\course_module_instance_list_viewed::create(array('context' => context_course::instance($course->id))); // Triggering and capturing 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_glossary\\event\\course_module_instance_list_viewed', $event); $this->assertEquals(CONTEXT_COURSE, $event->contextlevel); $this->assertEquals($course->id, $event->contextinstanceid); $expected = array($course->id, 'glossary', 'view all', 'index.php?id=' . $course->id, ''); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
/// This page lists all the instances of glossary in a particular course /// Replace glossary with the name of your module require_once "../../config.php"; require_once "lib.php"; require_once "{$CFG->libdir}/rsslib.php"; require_once "{$CFG->dirroot}/course/lib.php"; $id = required_param('id', PARAM_INT); // course $PAGE->set_url('/mod/glossary/index.php', array('id' => $id)); if (!($course = $DB->get_record('course', array('id' => $id)))) { print_error('invalidcourseid'); } require_course_login($course); $PAGE->set_pagelayout('incourse'); $context = context_course::instance($course->id); $event = \mod_glossary\event\course_module_instance_list_viewed::create(array('context' => $context)); $event->add_record_snapshot('course', $course); $event->trigger(); /// Get all required strings $strglossarys = get_string("modulenameplural", "glossary"); $strglossary = get_string("modulename", "glossary"); $strrss = get_string("rss"); /// Print the header $PAGE->navbar->add($strglossarys, "index.php?id={$course->id}"); $PAGE->set_title($strglossarys); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($strglossarys), 2); /// Get all the appropriate data if (!($glossarys = get_all_instances_in_course("glossary", $course))) { notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id={$course->id}");