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.
   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 event class for displaying a list of calendar events for a single course.
  19   *
  20   * @package   core_calendar
  21   * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_calendar\external;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use \renderer_base;
  30  
  31  /**
  32   * Class for displaying a list of calendar events for a single course.
  33   *
  34   * This class uses the events relateds cache in order to get the related
  35   * data for exporting an event without having to naively hit the database
  36   * for each event.
  37   *
  38   * @package   core_calendar
  39   * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class events_same_course_exporter extends events_exporter {
  43  
  44      /**
  45       * @var array $courseid The id of the course for these events.
  46       */
  47      protected $courseid;
  48  
  49      /**
  50       * Constructor.
  51       *
  52       * @param int $courseid The course id for these events
  53       * @param array $events An array of event_interface objects
  54       * @param array $related An array of related objects
  55       */
  56      public function __construct($courseid, array $events, $related = []) {
  57          parent::__construct($events, $related);
  58          $this->courseid = $courseid;
  59      }
  60  
  61      /**
  62       * Return the list of additional properties.
  63       *
  64       * @return array
  65       */
  66      protected static function define_other_properties() {
  67          $properties = parent::define_other_properties();
  68          $properties['courseid'] = ['type' => PARAM_INT];
  69          return $properties;
  70      }
  71  
  72      /**
  73       * Get the additional values to inject while exporting.
  74       *
  75       * @param renderer_base $output The renderer.
  76       * @return array Keys are the property names, values are their values.
  77       */
  78      protected function get_other_values(renderer_base $output) {
  79          $values = parent::get_other_values($output);
  80          $values['courseid'] = $this->courseid;
  81          return $values;
  82      }
  83  }