[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/book/tool/print/ -> locallib.php (source)

   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   * Book print lib
  19   *
  20   * @package    booktool_print
  21   * @copyright  2011 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die;
  26  
  27  require_once (__DIR__.'/lib.php');
  28  require_once($CFG->dirroot.'/mod/book/locallib.php');
  29  
  30  /**
  31   * Generate toc structure and titles
  32   *
  33   * @param array $chapters
  34   * @param stdClass $book
  35   * @param stdClass $cm
  36   * @return array
  37   */
  38  function booktool_print_get_toc($chapters, $book, $cm) {
  39      $first = true;
  40      $titles = array();
  41  
  42      $context = context_module::instance($cm->id);
  43  
  44      $toc = ''; // Representation of toc (HTML).
  45  
  46      switch ($book->numbering) {
  47          case BOOK_NUM_NONE:
  48              $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
  49              break;
  50          case BOOK_NUM_NUMBERS:
  51              $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
  52              break;
  53          case BOOK_NUM_BULLETS:
  54              $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
  55              break;
  56          case BOOK_NUM_INDENTED:
  57              $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
  58              break;
  59      }
  60  
  61      $toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
  62  
  63      $toc .= html_writer::tag('h2', get_string('toc', 'mod_book'));
  64      $toc .= html_writer::start_tag('ul');
  65      foreach ($chapters as $ch) {
  66          if (!$ch->hidden) {
  67              $title = book_get_chapter_title($ch->id, $chapters, $book, $context);
  68              if (!$ch->subchapter) {
  69  
  70                  if ($first) {
  71                      $toc .= html_writer::start_tag('li');
  72                  } else {
  73                      $toc .= html_writer::end_tag('ul');
  74                      $toc .= html_writer::end_tag('li');
  75                      $toc .= html_writer::start_tag('li');
  76                  }
  77  
  78              } else {
  79  
  80                  if ($first) {
  81                      $toc .= html_writer::start_tag('li');
  82                      $toc .= html_writer::start_tag('ul');
  83                      $toc .= html_writer::start_tag('li');
  84                  } else {
  85                      $toc .= html_writer::start_tag('li');
  86                  }
  87  
  88              }
  89              $titles[$ch->id] = $title;
  90              $toc .= html_writer::link(new moodle_url('#ch'.$ch->id), $title, array('title' => s($title)));
  91              if (!$ch->subchapter) {
  92                  $toc .= html_writer::start_tag('ul');
  93              } else {
  94                  $toc .= html_writer::end_tag('li');
  95              }
  96              $first = false;
  97          }
  98      }
  99  
 100      $toc .= html_writer::end_tag('ul');
 101      $toc .= html_writer::end_tag('li');
 102      $toc .= html_writer::end_tag('ul');
 103      $toc .= html_writer::end_tag('div');
 104  
 105      $toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
 106  
 107      return array($toc, $titles);
 108  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1