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.
   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 summary (used for multipage format).
  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 context_course;
  28  use core\output\named_templatable;
  29  use core_courseformat\base as course_format;
  30  use core_courseformat\output\local\courseformat_named_templatable;
  31  use renderable;
  32  use section_info;
  33  use stdClass;
  34  
  35  /**
  36   * Base class to render a course section summary.
  37   *
  38   * @package   core_courseformat
  39   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class summary implements named_templatable, renderable {
  43  
  44      use courseformat_named_templatable;
  45  
  46      /** @var course_format the course format class */
  47      protected $format;
  48  
  49      /** @var section_info the course section class */
  50      private $section;
  51  
  52      /**
  53       * Constructor.
  54       *
  55       * @param course_format $format the course format
  56       * @param section_info $section the section info
  57       */
  58      public function __construct(course_format $format, section_info $section) {
  59          $this->format = $format;
  60          $this->section = $section;
  61      }
  62  
  63      /**
  64       * Export this data so it can be used as the context for a mustache template.
  65       *
  66       * @param renderer_base $output typically, the renderer that's calling this function
  67       * @return array data context for a mustache template
  68       */
  69      public function export_for_template(\renderer_base $output): stdClass {
  70  
  71          $section = $this->section;
  72  
  73          $data = new stdClass();
  74  
  75          if ($section->uservisible || $section->visible) {
  76              $data->summarytext = $this->format_summary_text();
  77          }
  78          return $data;
  79      }
  80  
  81      /**
  82       * Generate html for a section summary text
  83       *
  84       * @return string HTML to output.
  85       */
  86      public function format_summary_text(): string {
  87          $section = $this->section;
  88          $context = context_course::instance($section->course);
  89          $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php',
  90              $context->id, 'course', 'section', $section->id);
  91  
  92          $options = new stdClass();
  93          $options->noclean = true;
  94          $options->overflowdiv = true;
  95          return format_text($summarytext, $section->summaryformat, $options);
  96      }
  97  }