Example #1
0
 public function test_chapter_updated()
 {
     // There is no proper API to call to generate chapters for a book, 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_updated::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_updated', $event);
     $this->assertEquals(context_module::instance($book->id), $event->get_context());
     $this->assertEquals($chapter->id, $event->objectid);
     $expected = array($course->id, 'book', 'update chapter', 'view.php?id=' . $book->cmid . '&chapterid=' . $chapter->id, $chapter->id, $book->cmid);
     $this->assertEventLegacyLogData($expected, $event);
 }
Example #2
0
    if (empty($chapter->id)) {
        redirect("view.php?id={$cm->id}");
    } else {
        redirect("view.php?id={$cm->id}&chapterid={$chapter->id}");
    }
} else {
    if ($data = $mform->get_data()) {
        if ($data->id) {
            // store the files
            $data->timemodified = time();
            $data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id);
            $DB->update_record('book_chapters', $data);
            $DB->set_field('book', 'revision', $book->revision + 1, array('id' => $book->id));
            add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id=' . $cm->id, 'book ' . $book->id);
            $params = array('context' => $context, 'objectid' => $data->id);
            $event = \mod_book\event\chapter_updated::create($params);
            $event->add_record_snapshot('book_chapters', $data);
            $event->trigger();
        } else {
            // adding new chapter
            $data->bookid = $book->id;
            $data->hidden = 0;
            $data->timecreated = time();
            $data->timemodified = time();
            $data->importsrc = '';
            $data->content = '';
            // updated later
            $data->contentformat = FORMAT_HTML;
            // updated later
            // make room for new page
            $sql = "UPDATE {book_chapters}\n                   SET pagenum = pagenum + 1\n                 WHERE bookid = ? AND pagenum >= ?";