original_string: public function render_print_book_toc($chapters, $book, $cm) {
  
          $first = true;
  
          $context = context_module::instance($cm->id);
  
          $toc = ''; // Representation of toc (HTML).
  
          switch ($book->numbering) {
              case BOOK_NUM_NONE:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
                  break;
              case BOOK_NUM_NUMBERS:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
                  break;
              case BOOK_NUM_BULLETS:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
                  break;
              case BOOK_NUM_INDENTED:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
                  break;
          }
  
          $toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
  
          $toc .= html_writer::tag('h2', get_string('toc', 'mod_book'), ['class' => 'text-center p-b-2']);
          $toc .= html_writer::start_tag('ul');
          foreach ($chapters as $ch) {
              if (!$ch->hidden) {
                  $title = book_get_chapter_title($ch->id, $chapters, $book, $context);
                  if (!$ch->subchapter) {
  
                      if ($first) {
                          $toc .= html_writer::start_tag('li');
                      } else {
                          $toc .= html_writer::end_tag('ul');
                          $toc .= html_writer::end_tag('li');
                          $toc .= html_writer::start_tag('li');
                      }
  
                  } else {
  
                      if ($first) {
                          $toc .= html_writer::start_tag('li');
                          $toc .= html_writer::start_tag('ul');
                          $toc .= html_writer::start_tag('li');
                      } else {
                          $toc .= html_writer::start_tag('li');
                      }
  
                  }
  
                  if (!$ch->subchapter) {
                      $toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
                              array('title' => s($title), 'class' => 'font-weight-bold text-decoration-none'));
                      $toc .= html_writer::start_tag('ul');
                  } else {
                      $toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
                              array('title' => s($title), 'class' => 'text-decoration-none'));
                      $toc .= html_writer::end_tag('li');
                  }
                  $first = false;
              }
          }
  
          $toc .= html_writer::end_tag('ul');
          $toc .= html_writer::end_tag('li');
          $toc .= html_writer::end_tag('ul');
          $toc .= html_writer::end_tag('div');
  
          $toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
  
          return $toc;
      }
code: public function render_print_book_toc($chapters, $book, $cm) {
  
          $first = true;
  
          $context = context_module::instance($cm->id);
  
          $toc = ''; // Representation of toc (HTML).
  
          switch ($book->numbering) {
              case BOOK_NUM_NONE:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
                  break;
              case BOOK_NUM_NUMBERS:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
                  break;
              case BOOK_NUM_BULLETS:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
                  break;
              case BOOK_NUM_INDENTED:
                  $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
                  break;
          }
  
          $toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
  
          $toc .= html_writer::tag('h2', get_string('toc', 'mod_book'), ['class' => 'text-center p-b-2']);
          $toc .= html_writer::start_tag('ul');
          foreach ($chapters as $ch) {
              if (!$ch->hidden) {
                  $title = book_get_chapter_title($ch->id, $chapters, $book, $context);
                  if (!$ch->subchapter) {
  
                      if ($first) {
                          $toc .= html_writer::start_tag('li');
                      } else {
                          $toc .= html_writer::end_tag('ul');
                          $toc .= html_writer::end_tag('li');
                          $toc .= html_writer::start_tag('li');
                      }
  
                  } else {
  
                      if ($first) {
                          $toc .= html_writer::start_tag('li');
                          $toc .= html_writer::start_tag('ul');
                          $toc .= html_writer::start_tag('li');
                      } else {
                          $toc .= html_writer::start_tag('li');
                      }
  
                  }
  
                  if (!$ch->subchapter) {
                      $toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
                              array('title' => s($title), 'class' => 'font-weight-bold text-decoration-none'));
                      $toc .= html_writer::start_tag('ul');
                  } else {
                      $toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
                              array('title' => s($title), 'class' => 'text-decoration-none'));
                      $toc .= html_writer::end_tag('li');
                  }
                  $first = false;
              }
          }
  
          $toc .= html_writer::end_tag('ul');
          $toc .= html_writer::end_tag('li');
          $toc .= html_writer::end_tag('ul');
          $toc .= html_writer::end_tag('div');
  
          $toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
  
          return $toc;
      }
code_tokens: public function render_print_book_toc ( $ chapters , $ book , $ cm ) { $ first = true ; $ context = context_module :: instance ( $ cm -> id ) ; $ toc = '' ; // Representation of toc (HTML). switch ( $ book -> numbering ) { case BOOK_NUM_NONE : $ toc .= html_writer :: start_tag ( 'div' , array ( 'class' => 'book_toc_none' ) ) ; break ; case BOOK_NUM_NUMBERS : $ toc .= html_writer :: start_tag ( 'div' , array ( 'class' => 'book_toc_numbered' ) ) ; break ; case BOOK_NUM_BULLETS : $ toc .= html_writer :: start_tag ( 'div' , array ( 'class' => 'book_toc_bullets' ) ) ; break ; case BOOK_NUM_INDENTED : $ toc .= html_writer :: start_tag ( 'div' , array ( 'class' => 'book_toc_indented' ) ) ; break ; } $ toc .= html_writer :: tag ( 'a' , '' , array ( 'name' => 'toc' ) ) ; // Representation of toc (HTML). $ toc .= html_writer :: tag ( 'h2' , get_string ( 'toc' , 'mod_book' ) , [ 'class' => 'text-center p-b-2' ] ) ; $ toc .= html_writer :: start_tag ( 'ul' ) ; foreach ( $ chapters as $ ch ) { if ( ! $ ch -> hidden ) { $ title = book_get_chapter_title ( $ ch -> id , $ chapters , $ book , $ context ) ; if ( ! $ ch -> subchapter ) { if ( $ first ) { $ toc .= html_writer :: start_tag ( 'li' ) ; } else { $ toc .= html_writer :: end_tag ( 'ul' ) ; $ toc .= html_writer :: end_tag ( 'li' ) ; $ toc .= html_writer :: start_tag ( 'li' ) ; } } else { if ( $ first ) { $ toc .= html_writer :: start_tag ( 'li' ) ; $ toc .= html_writer :: start_tag ( 'ul' ) ; $ toc .= html_writer :: start_tag ( 'li' ) ; } else { $ toc .= html_writer :: start_tag ( 'li' ) ; } } if ( ! $ ch -> subchapter ) { $ toc .= html_writer :: link ( new moodle_url ( '#ch' . $ ch -> id ) , $ title , array ( 'title' => s ( $ title ) , 'class' => 'font-weight-bold text-decoration-none' ) ) ; $ toc .= html_writer :: start_tag ( 'ul' ) ; } else { $ toc .= html_writer :: link ( new moodle_url ( '#ch' . $ ch -> id ) , $ title , array ( 'title' => s ( $ title ) , 'class' => 'text-decoration-none' ) ) ; $ toc .= html_writer :: end_tag ( 'li' ) ; } $ first = false ; } } $ toc .= html_writer :: end_tag ( 'ul' ) ; $ toc .= html_writer :: end_tag ( 'li' ) ; $ toc .= html_writer :: end_tag ( 'ul' ) ; $ toc .= html_writer :: end_tag ( 'div' ) ; $ toc = str_replace ( '<ul></ul>' , '' , $ toc ) ; // Cleanup of invalid structures. return $ toc ; }
docstring: Render the print book table of contents.
  
  @param array $chapters Array of book chapters
  @param object $book The book object
  @param object $cm The curse module object
  @return string html for the TOC
docstring_tokens: Render the print book table of contents .