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   * Email failed event.
  19   *
  20   * @package    core
  21   * @since      Moodle 2.7
  22   * @copyright  2013 Mark Nelson <markn@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core\event;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  /**
  31   * Email failed event class.
  32   *
  33   * @property-read array $other {
  34   *      Extra information about event.
  35   *
  36   *      - string subject: the message subject.
  37   *      - string message: the message text.
  38   *      - string errorinfo: the error info.
  39   * }
  40   *
  41   * @package    core
  42   * @since      Moodle 2.7
  43   * @copyright  2013 Mark Nelson <markn@moodle.com>
  44   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  45   */
  46  class email_failed extends base {
  47  
  48      /**
  49       * Initialise the event data.
  50       */
  51      protected function init() {
  52          $this->data['crud'] = 'c';
  53          $this->data['edulevel'] = self::LEVEL_OTHER;
  54      }
  55  
  56      /**
  57       * Returns localised general event name.
  58       *
  59       * @return string
  60       */
  61      public static function get_name() {
  62          return get_string('eventemailfailed');
  63      }
  64  
  65      /**
  66       * Returns non-localised description of what happened.
  67       *
  68       * @return string
  69       */
  70      public function get_description() {
  71          return "Failed to send an email from the user with id '$this->userid' to the user with id '$this->relateduserid'
  72              due to the following error: \"{$this->other['errorinfo']}\".";
  73      }
  74  
  75      /**
  76       * Return legacy data for add_to_log().
  77       *
  78       * @return array
  79       */
  80      protected function get_legacy_logdata() {
  81          return array(SITEID, 'library', 'mailer', qualified_me(), 'ERROR: ' . $this->other['errorinfo']);
  82      }
  83  
  84      /**
  85       * Custom validation.
  86       *
  87       * @throws \coding_exception
  88       */
  89      protected function validate_data() {
  90          parent::validate_data();
  91  
  92          if (!isset($this->relateduserid)) {
  93              throw new \coding_exception('The \'relateduserid\' must be set.');
  94          }
  95          if (!isset($this->other['subject'])) {
  96              throw new \coding_exception('The \'subject\' value must be set in other.');
  97          }
  98          if (!isset($this->other['message'])) {
  99              throw new \coding_exception('The \'message\' value must be set in other.');
 100          }
 101          if (!isset($this->other['errorinfo'])) {
 102              throw new \coding_exception('The \'errorinfo\' value must be set in other.');
 103          }
 104      }
 105  
 106      public static function get_other_mapping() {
 107          return false;
 108      }
 109  }