Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.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   * Badge criteria created event.
  19   *
  20   * @package    core
  21   * @copyright  2016 Stephen Bourget
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core\event;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Event triggered after criteria is created for a badge.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about the event.
  33   *
  34   *      - int badgeid: The ID of the badge affected
  35   *
  36   * @package    core
  37   * @since      Moodle 3.2
  38   * @copyright  2016 Stephen Bourget
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class badge_criteria_created extends base {
  42  
  43      /**
  44       * Set basic properties for the event.
  45       */
  46      protected function init() {
  47          $this->data['objecttable'] = 'badge_criteria';
  48          $this->data['crud'] = 'c';
  49          $this->data['edulevel'] = self::LEVEL_TEACHING;
  50      }
  51  
  52      /**
  53       * Returns localised general event name.
  54       *
  55       * @return string
  56       */
  57      public static function get_name() {
  58          return get_string('eventbadgecriteriacreated', 'badges');
  59      }
  60  
  61      /**
  62       * Returns non-localised event description with id's for admin use only.
  63       *
  64       * @return string
  65       */
  66      public function get_description() {
  67          return "The user with id '$this->userid' has created criteria to the badge with id '".$this->other['badgeid']."'.";
  68      }
  69  
  70      /**
  71       * Returns relevant URL.
  72       * @return \moodle_url
  73       */
  74      public function get_url() {
  75          return new \moodle_url('/badges/criteria.php', array('id' => $this->other['badgeid']));
  76      }
  77  
  78      /**
  79       * Custom validations.
  80       *
  81       * @throws \coding_exception
  82       * @return void
  83       */
  84      protected function validate_data() {
  85          parent::validate_data();
  86  
  87          if (!isset($this->objectid)) {
  88              throw new \coding_exception('The \'objectid\' must be set.');
  89          }
  90          if (!isset($this->other['badgeid'])) {
  91              throw new \coding_exception('The \'badgeid\' value must be set in other.');
  92          }
  93      }
  94  
  95      /**
  96       * Used for maping events on restore
  97       *
  98       * @return array
  99       */
 100      public static function get_objectid_mapping() {
 101          return array('db' => 'badge_criteria', 'restore' => 'badge_criteria');
 102      }
 103  
 104      /**
 105       * Used for maping events on restore
 106       *
 107       * @return bool
 108       */
 109      public static function get_other_mapping() {
 110          $othermapped = array();
 111          $othermapped['badgeid'] = array('db' => 'badge', 'restore' => 'badge');
 112          return $othermapped;
 113      }
 114  }
 115  
 116