Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 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 header format output class.
  19   *
  20   * @package   core_courseformat
  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 core_courseformat\output\local\content\section;
  26  
  27  use core\output\named_templatable;
  28  use core_courseformat\base as course_format;
  29  use core_courseformat\output\local\courseformat_named_templatable;
  30  use renderable;
  31  use section_info;
  32  use stdClass;
  33  
  34  /**
  35   * Base class to render a section header.
  36   *
  37   * @package   core_courseformat
  38   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  39   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class header implements named_templatable, renderable {
  42  
  43      use courseformat_named_templatable;
  44  
  45      /** @var course_format the course format class */
  46      protected $format;
  47  
  48      /** @var section_info the course section class */
  49      protected $section;
  50  
  51      /**
  52       * Constructor.
  53       *
  54       * @param course_format $format the course format
  55       * @param section_info $section the section info
  56       */
  57      public function __construct(course_format $format, section_info $section) {
  58          $this->format = $format;
  59          $this->section = $section;
  60      }
  61  
  62      /**
  63       * Export this data so it can be used as the context for a mustache template.
  64       *
  65       * @param renderer_base $output typically, the renderer that's calling this function
  66       * @return array data context for a mustache template
  67       */
  68      public function export_for_template(\renderer_base $output): stdClass {
  69  
  70          $format = $this->format;
  71          $section = $this->section;
  72          $course = $format->get_course();
  73  
  74          $data = (object)[
  75              'num' => $section->section,
  76              'id' => $section->id,
  77          ];
  78  
  79          $data->title = $output->section_title_without_link($section, $course);
  80  
  81          $coursedisplay = $format->get_course_display();
  82          $data->headerdisplaymultipage = false;
  83          if ($coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
  84              $data->headerdisplaymultipage = true;
  85              $data->title = $output->section_title($section, $course);
  86          }
  87  
  88          if ($section->section > $format->get_last_section_number()) {
  89              // Stealth sections (orphaned) has special title.
  90              $data->title = get_string('orphanedactivitiesinsectionno', '', $section->section);
  91          }
  92  
  93          if (!$section->visible) {
  94              $data->ishidden = true;
  95          }
  96  
  97          if ($course->id == SITEID) {
  98              $data->sitehome = true;
  99          }
 100  
 101          $data->editing = $format->show_editor();
 102  
 103          if (!$format->show_editor() && $coursedisplay == COURSE_DISPLAY_MULTIPAGE && empty($data->issinglesection)) {
 104              if ($section->uservisible) {
 105                  $data->url = course_get_url($course, $section->section);
 106              }
 107          }
 108          $data->name = get_section_name($course, $section);
 109  
 110          return $data;
 111      }
 112  }