示例#1
0
    public function test_chapter_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();
        $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
        $bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');

        $chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));

        $params = array(
            'context' => context_module::instance($book->cmid),
            'objectid' => $chapter->id
        );
        $event = \mod_book\event\chapter_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\chapter_viewed', $event);
        $this->assertEquals(context_module::instance($book->cmid), $event->get_context());
        $this->assertEquals($chapter->id, $event->objectid);
        $expected = array($course->id, 'book', 'view chapter', 'view.php?id=' . $book->cmid . '&chapterid=' .
            $chapter->id, $chapter->id, $book->cmid);
        $this->assertEventLegacyLogData($expected, $event);
        $this->assertEventContextNotUsed($event);
    }
示例#2
0
if (!$chapterid) {
    $PAGE->set_url('/mod/book/view.php', array('id' => $id));
    notice(get_string('nocontent', 'mod_book'), $courseurl->out(false));
}
// Chapter doesnt exist or it is hidden for students
if (!($chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id))) or $chapter->hidden and !$viewhidden) {
    print_error('errorchapter', 'mod_book', $courseurl);
}
$PAGE->set_url('/mod/book/view.php', array('id' => $id, 'chapterid' => $chapterid));
// Unset all page parameters.
unset($id);
unset($bid);
unset($chapterid);
// Security checks END.
$params = array('context' => $context, 'objectid' => $chapter->id);
$event = \mod_book\event\chapter_viewed::create($params);
$event->add_record_snapshot('book_chapters', $chapter);
$event->trigger();
// Read standard strings.
$strbooks = get_string('modulenameplural', 'mod_book');
$strbook = get_string('modulename', 'mod_book');
$strtoc = get_string('toc', 'mod_book');
// prepare header
$pagetitle = $book->name . ": " . $chapter->title;
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
book_add_fake_block($chapters, $chapter, $book, $cm, $edit);
// prepare chapter navigation icons
$previd = null;
$nextid = null;
$last = null;