Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

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