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 400 and 401]

   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 frontpage section displayer.
  19   *
  20   * The frontpage has a different wat of rendering the main topic.
  21   *
  22   * @package   core_courseformat
  23   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  24   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  namespace core_courseformat\output\local\content;
  28  
  29  use context_course;
  30  use core\output\named_templatable;
  31  use core_courseformat\base as course_format;
  32  use core_courseformat\output\local\courseformat_named_templatable;
  33  use moodle_url;
  34  use renderable;
  35  use section_info;
  36  use stdClass;
  37  
  38  /**
  39   * Represents the frontpage section 1.
  40   *
  41   * @package   core_courseformat
  42   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  43   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44   */
  45  class frontpagesection implements named_templatable, renderable {
  46  
  47      use courseformat_named_templatable;
  48  
  49      /** @var course_format the course format class */
  50      protected $format;
  51  
  52      /** @var section_info the course section class */
  53      protected $section;
  54  
  55      /** @var string the section output class name */
  56      protected $sectionclass;
  57  
  58      /**
  59       * Constructor.
  60       *
  61       * @param course_format $format the course format
  62       * @param section_info $section the section info
  63       */
  64      public function __construct(course_format $format, section_info $section) {
  65          $this->format = $format;
  66          $this->section = $section;
  67  
  68          // Get the necessary classes.
  69          $this->sectionclass = $format->get_output_classname('content\\section');
  70      }
  71  
  72      /**
  73       * Export this data so it can be used as the context for a mustache template.
  74       *
  75       * @param renderer_base $output typically, the renderer that's calling this function
  76       * @return stdClass data context for a mustache template
  77       */
  78      public function export_for_template(\renderer_base $output): stdClass {
  79          global $USER;
  80  
  81          $format = $this->format;
  82          $section = $this->section;
  83  
  84          $sectionoutput = new $this->sectionclass($format, $section);
  85          $sectionoutput->hide_controls();
  86  
  87          if (trim($section->name ?? '') == '') {
  88              $sectionoutput->hide_title();
  89          }
  90  
  91          $data = (object)[
  92              'sections' => [$sectionoutput->export_for_template($output)],
  93          ];
  94  
  95          if ($format->show_editor(['moodle/course:update'])) {
  96              $data->showsettings = true;
  97              $data->settingsurl = new moodle_url('/course/editsection.php', ['id' => $section->id]);
  98          }
  99  
 100          return $data;
 101      }
 102  }