/** * Create the event from course record. * * @param \stdClass $course * @return course_module_instance_list_viewed */ public static function create_from_course(\stdClass $course) { $params = array('context' => \context_course::instance($course->id)); $event = \mod_book\event\course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); return $event; }
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(); $params = array('context' => context_course::instance($course->id)); $event = \mod_book\event\course_module_instance_list_viewed::create($params); // 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_book\\event\\course_module_instance_list_viewed', $event); $this->assertEquals(context_course::instance($course->id), $event->get_context()); $expected = array($course->id, 'book', 'view all', 'index.php?id=' . $course->id, ''); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
unset($id); require_course_login($course, true); $PAGE->set_pagelayout('incourse'); // Get all required strings $strbooks = get_string('modulenameplural', 'mod_book'); $strbook = get_string('modulename', 'mod_book'); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); $PAGE->set_url('/mod/book/index.php', array('id' => $course->id)); $PAGE->set_title($course->shortname . ': ' . $strbooks); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($strbooks); echo $OUTPUT->header(); $params = array('context' => context_course::instance($course->id)); $event = \mod_book\event\course_module_instance_list_viewed::create($params); $event->trigger(); // Get all the appropriate data if (!($books = get_all_instances_in_course('book', $course))) { notice(get_string('thereareno', 'moodle', $strbooks), "{$CFG->wwwroot}/course/view.php?id={$course->id}"); die; } $usesections = course_format_uses_sections($course->format); $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; if ($usesections) { $strsectionname = get_string('sectionname', 'format_' . $course->format); $table->head = array($strsectionname, $strname, $strintro); $table->align = array('center', 'left', 'left'); } else { $table->head = array($strlastmodified, $strname, $strintro);