Ejemplo n.º 1
0
    public function test_chapter_printed() {
        // There is no proper API to call to test the 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 = \booktool_print\event\chapter_printed::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('\booktool_print\event\chapter_printed', $event);
        $this->assertEquals(context_module::instance($book->cmid), $event->get_context());
        $this->assertEquals($chapter->id, $event->objectid);
        $expected = array($course->id, 'book', 'print chapter', 'tool/print/index.php?id=' . $book->cmid .
            '&chapterid=' . $chapter->id, $chapter->id, $book->cmid);
        $this->assertEventLegacyLogData($expected, $event);
        $this->assertEventContextNotUsed($event);
    }
Ejemplo n.º 2
0
// Security checks END.
// read chapters
$chapters = book_preload_chapters($book);
$strbooks = get_string('modulenameplural', 'mod_book');
$strbook = get_string('modulename', 'mod_book');
$strtop = get_string('top', 'mod_book');
@header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
@header('Pragma: no-cache');
@header('Expires: ');
@header('Accept-Ranges: none');
@header('Content-type: text/html; charset=utf-8');
if ($chapter) {
    if ($chapter->hidden) {
        require_capability('mod/book:viewhiddenchapters', $context);
    }
    \booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter)->trigger();
    // page header
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
      <title><?php 
    echo format_string($book->name, true, array('context' => $context));
    ?>
</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta name="description" content="<?php 
    echo s(format_string($book->name, true, array('context' => $context)));
    ?>
" />
      <link rel="stylesheet" type="text/css" href="print.css" />
Ejemplo n.º 3
0
// read chapters
$chapters = book_preload_chapters($book);
$strbooks = get_string('modulenameplural', 'mod_book');
$strbook = get_string('modulename', 'mod_book');
$strtop = get_string('top', 'mod_book');
@header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
@header('Pragma: no-cache');
@header('Expires: ');
@header('Accept-Ranges: none');
@header('Content-type: text/html; charset=utf-8');
if ($chapter) {
    if ($chapter->hidden) {
        require_capability('mod/book:viewhiddenchapters', $context);
    }
    $params = array('context' => $context, 'objectid' => $chapter->id);
    $event = \booktool_print\event\chapter_printed::create($params);
    $event->add_record_snapshot('book_chapters', $chapter);
    $event->trigger();
    // page header
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
      <title><?php 
    echo format_string($book->name, true, array('context' => $context));
    ?>
</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta name="description" content="<?php 
    echo s(format_string($book->name, true, array('context' => $context)));
    ?>