Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.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  namespace core\event;
  18  
  19  /**
  20   * Course ended event class.
  21   *
  22   * @property-read array $other {
  23   *      Extra information about event.
  24   *
  25   *      - string fullname: fullname of course.
  26   *      - string shortname: (optional) shortname of course.
  27   * }
  28   *
  29   * @package    core
  30   * @copyright  2023 Sara Arjona <sara@moodle.com>
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class course_ended extends base {
  34  
  35      /**
  36       * Initialise the event data.
  37       */
  38      protected function init() {
  39          $this->data['objecttable'] = 'course';
  40          $this->data['crud'] = 'u';
  41          $this->data['edulevel'] = self::LEVEL_TEACHING;
  42      }
  43  
  44      /**
  45       * Returns localised general event name.
  46       *
  47       * @return string
  48       */
  49      public static function get_name() {
  50          return get_string('eventcourseended');
  51      }
  52  
  53      /**
  54       * Returns non-localised description of what happened.
  55       *
  56       * @return string
  57       */
  58      public function get_description() {
  59          return "The course with id '$this->courseid' has ended.";
  60      }
  61  
  62      /**
  63       * Returns relevant URL.
  64       *
  65       * @return \moodle_url
  66       */
  67      public function get_url() {
  68          return new \moodle_url('/course/view.php', ['id' => $this->objectid]);
  69      }
  70  
  71      /**
  72       * Custom validation.
  73       *
  74       * @throws \coding_exception
  75       * @return void
  76       */
  77      protected function validate_data() {
  78          parent::validate_data();
  79  
  80          if (!isset($this->other['fullname'])) {
  81              throw new \coding_exception('The \'fullname\' value must be set in other.');
  82          }
  83      }
  84  
  85      public static function get_objectid_mapping() {
  86          return [
  87              'db' => 'course',
  88              'restore' => 'course',
  89          ];
  90      }
  91  
  92      public static function get_other_mapping() {
  93          // Nothing to map.
  94          return [];
  95      }
  96  }