Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Class containing data for the view book page.
  19   *
  20   * @package    booktool_print
  21   * @copyright  2019 Mihail Geshoski
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace booktool_print\output;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use renderable;
  29  use renderer_base;
  30  use stdClass;
  31  use templatable;
  32  use context_module;
  33  
  34  /**
  35   * Class containing data for the print book page.
  36   *
  37   * @copyright  2019 Mihail Geshoski
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class print_book_chapter_page implements renderable, templatable {
  41  
  42      /**
  43       * @var object $book The book object.
  44       */
  45      protected $book;
  46  
  47      /**
  48       * @var object $cm The course module object.
  49       */
  50      protected $cm;
  51  
  52      /**
  53       * @var object $chapter The book chapter object.
  54       */
  55      protected $chapter;
  56  
  57      /**
  58       * Construct this renderable.
  59       *
  60       * @param object $book The book
  61       * @param object $cm The course module
  62       * @param object $chapter The book chapter
  63       */
  64      public function __construct($book, $cm, $chapter) {
  65          $this->book = $book;
  66          $this->cm = $cm;
  67          $this->chapter = $chapter;
  68      }
  69  
  70      /**
  71       * Export this data so it can be used as the context for a mustache template.
  72       *
  73       * @param renderer_base $output
  74       * @return stdClass
  75       */
  76      public function export_for_template(renderer_base $output) {
  77          global $OUTPUT;
  78  
  79          $context = context_module::instance($this->cm->id);
  80          $chapters = book_preload_chapters($this->book);
  81  
  82          $data = new stdClass();
  83          // Print dialog link.
  84          $data->printdialoglink = $output->render_print_book_chapter_dialog_link();
  85          $data->booktitle = $OUTPUT->heading(format_string($this->book->name, true,
  86                  array('context' => $context)), 1);
  87          if (!$this->book->customtitles) {
  88              // If the current chapter is a subchapter, get the title of the parent chapter.
  89              if ($this->chapter->subchapter) {
  90                  $parentchaptertitle = book_get_chapter_title($chapters[$this->chapter->id]->parent, $chapters,
  91                          $this->book, $context);
  92                  $data->parentchaptertitle = $OUTPUT->heading(format_string($parentchaptertitle, true,
  93                          array('context' => $context)), 2);
  94              }
  95          }
  96  
  97          list($chaptercontent, $chaptervisible) = $output->render_print_book_chapter($this->chapter, $chapters,
  98                  $this->book, $this->cm);
  99          $chapter = new stdClass();
 100          $chapter->content = $chaptercontent;
 101          $chapter->visible = $chaptervisible;
 102          $data->chapter = $chapter;
 103  
 104          return $data;
 105      }
 106  }