Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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   * Contains the default section controls output class.
  19   *
  20   * @package   format_topics
  21   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace format_topics\output\courseformat\content\section;
  26  
  27  use context_course;
  28  use core_courseformat\output\local\content\section\controlmenu as controlmenu_base;
  29  
  30  /**
  31   * Base class to render a course section menu.
  32   *
  33   * @package   format_topics
  34   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class controlmenu extends controlmenu_base {
  38  
  39      /** @var course_format the course format class */
  40      protected $format;
  41  
  42      /** @var section_info the course section class */
  43      protected $section;
  44  
  45      /**
  46       * Generate the edit control items of a section.
  47       *
  48       * This method must remain public until the final deprecation of section_edit_control_items.
  49       *
  50       * @return array of edit control items
  51       */
  52      public function section_control_items() {
  53  
  54          $format = $this->format;
  55          $section = $this->section;
  56          $course = $format->get_course();
  57          $sectionreturn = $format->get_section_number();
  58  
  59          $coursecontext = context_course::instance($course->id);
  60  
  61          if ($sectionreturn) {
  62              $url = course_get_url($course, $section->section);
  63          } else {
  64              $url = course_get_url($course);
  65          }
  66          $url->param('sesskey', sesskey());
  67  
  68          $controls = [];
  69          if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
  70              if ($course->marker == $section->section) {  // Show the "light globe" on/off.
  71                  $url->param('marker', 0);
  72                  $highlightoff = get_string('highlightoff');
  73                  $controls['highlight'] = [
  74                      'url' => $url,
  75                      'icon' => 'i/marked',
  76                      'name' => $highlightoff,
  77                      'pixattr' => ['class' => ''],
  78                      'attr' => [
  79                          'class' => 'editing_highlight',
  80                          'data-action' => 'removemarker'
  81                      ],
  82                  ];
  83              } else {
  84                  $url->param('marker', $section->section);
  85                  $highlight = get_string('highlight');
  86                  $controls['highlight'] = [
  87                      'url' => $url,
  88                      'icon' => 'i/marker',
  89                      'name' => $highlight,
  90                      'pixattr' => ['class' => ''],
  91                      'attr' => [
  92                          'class' => 'editing_highlight',
  93                          'data-action' => 'setmarker'
  94                      ],
  95                  ];
  96              }
  97          }
  98  
  99          $parentcontrols = parent::section_control_items();
 100  
 101          // If the edit key exists, we are going to insert our controls after it.
 102          if (array_key_exists("edit", $parentcontrols)) {
 103              $merged = [];
 104              // We can't use splice because we are using associative arrays.
 105              // Step through the array and merge the arrays.
 106              foreach ($parentcontrols as $key => $action) {
 107                  $merged[$key] = $action;
 108                  if ($key == "edit") {
 109                      // If we have come to the edit key, merge these controls here.
 110                      $merged = array_merge($merged, $controls);
 111                  }
 112              }
 113  
 114              return $merged;
 115          } else {
 116              return array_merge($controls, $parentcontrols);
 117          }
 118      }
 119  }