Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * Renderer for outputting the topics course format.
  19   *
  20   * @package format_topics
  21   * @copyright 2012 Dan Poltawski
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @since Moodle 2.3
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  require_once($CFG->dirroot.'/course/format/renderer.php');
  29  
  30  /**
  31   * Basic renderer for topics format.
  32   *
  33   * @copyright 2012 Dan Poltawski
  34   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class format_topics_renderer extends format_section_renderer_base {
  37  
  38      /**
  39       * Constructor method, calls the parent constructor
  40       *
  41       * @param moodle_page $page
  42       * @param string $target one of rendering target constants
  43       */
  44      public function __construct(moodle_page $page, $target) {
  45          parent::__construct($page, $target);
  46  
  47          // Since format_topics_renderer::section_edit_control_items() only displays the 'Highlight' control when editing mode is on
  48          // we need to be sure that the link 'Turn editing mode on' is available for a user who does not have any other managing capability.
  49          $page->set_other_editing_capability('moodle/course:setcurrentsection');
  50      }
  51  
  52      /**
  53       * Generate the starting container html for a list of sections
  54       * @return string HTML to output.
  55       */
  56      protected function start_section_list() {
  57          return html_writer::start_tag('ul', array('class' => 'topics'));
  58      }
  59  
  60      /**
  61       * Generate the closing container html for a list of sections
  62       * @return string HTML to output.
  63       */
  64      protected function end_section_list() {
  65          return html_writer::end_tag('ul');
  66      }
  67  
  68      /**
  69       * Generate the title for this section page
  70       * @return string the page title
  71       */
  72      protected function page_title() {
  73          return get_string('topicoutline');
  74      }
  75  
  76      /**
  77       * Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page
  78       *
  79       * @param stdClass $section The course_section entry from DB
  80       * @param stdClass $course The course entry from DB
  81       * @return string HTML to output.
  82       */
  83      public function section_title($section, $course) {
  84          return $this->render(course_get_format($course)->inplace_editable_render_section_name($section));
  85      }
  86  
  87      /**
  88       * Generate the section title to be displayed on the section page, without a link
  89       *
  90       * @param stdClass $section The course_section entry from DB
  91       * @param stdClass $course The course entry from DB
  92       * @return string HTML to output.
  93       */
  94      public function section_title_without_link($section, $course) {
  95          return $this->render(course_get_format($course)->inplace_editable_render_section_name($section, false));
  96      }
  97  
  98      /**
  99       * Generate the edit control items of a section
 100       *
 101       * @param stdClass $course The course entry from DB
 102       * @param stdClass $section The course_section entry from DB
 103       * @param bool $onsectionpage true if being printed on a section page
 104       * @return array of edit control items
 105       */
 106      protected function section_edit_control_items($course, $section, $onsectionpage = false) {
 107          if (!$this->page->user_is_editing()) {
 108              return array();
 109          }
 110  
 111          $coursecontext = context_course::instance($course->id);
 112  
 113          if ($onsectionpage) {
 114              $url = course_get_url($course, $section->section);
 115          } else {
 116              $url = course_get_url($course);
 117          }
 118          $url->param('sesskey', sesskey());
 119  
 120          $controls = array();
 121          if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
 122              if ($course->marker == $section->section) {  // Show the "light globe" on/off.
 123                  $url->param('marker', 0);
 124                  $highlightoff = get_string('highlightoff');
 125                  $controls['highlight'] = array('url' => $url, "icon" => 'i/marked',
 126                                                 'name' => $highlightoff,
 127                                                 'pixattr' => array('class' => ''),
 128                                                 'attr' => array('class' => 'editing_highlight',
 129                                                     'data-action' => 'removemarker'));
 130              } else {
 131                  $url->param('marker', $section->section);
 132                  $highlight = get_string('highlight');
 133                  $controls['highlight'] = array('url' => $url, "icon" => 'i/marker',
 134                                                 'name' => $highlight,
 135                                                 'pixattr' => array('class' => ''),
 136                                                 'attr' => array('class' => 'editing_highlight',
 137                                                     'data-action' => 'setmarker'));
 138              }
 139          }
 140  
 141          $parentcontrols = parent::section_edit_control_items($course, $section, $onsectionpage);
 142  
 143          // If the edit key exists, we are going to insert our controls after it.
 144          if (array_key_exists("edit", $parentcontrols)) {
 145              $merged = array();
 146              // We can't use splice because we are using associative arrays.
 147              // Step through the array and merge the arrays.
 148              foreach ($parentcontrols as $key => $action) {
 149                  $merged[$key] = $action;
 150                  if ($key == "edit") {
 151                      // If we have come to the edit key, merge these controls here.
 152                      $merged = array_merge($merged, $controls);
 153                  }
 154              }
 155  
 156              return $merged;
 157          } else {
 158              return array_merge($controls, $parentcontrols);
 159          }
 160      }
 161  }