Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * User competency review requested event.
  19   *
  20   * @package    core_competency
  21   * @copyright  2016 Issam Taboubi <issam.taboubi@umontreal.ca>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core\event;
  26  
  27  use core\event\base;
  28  use core_competency\user_competency;
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  /**
  32   * User competency review requested event class.
  33   *
  34   *
  35   * @package    core_competency
  36   * @since      Moodle 3.1
  37   * @copyright  2016 Issam Taboubi <issam.taboubi@umontreal.ca>
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class competency_user_competency_review_request_cancelled extends base {
  41  
  42      /**
  43       * Convenience method to instantiate the event.
  44       *
  45       * @param user_competency $usercompetency The user competency.
  46       * @return self
  47       */
  48      public static function create_from_user_competency(user_competency $usercompetency) {
  49          if (!$usercompetency->get('id')) {
  50              throw new \coding_exception('The user competency ID must be set.');
  51          }
  52          $params = array(
  53              'contextid' => $usercompetency->get_context()->id,
  54              'objectid' => $usercompetency->get('id'),
  55              'relateduserid' => $usercompetency->get('userid')
  56          );
  57  
  58          $event = static::create($params);
  59          $event->add_record_snapshot(user_competency::TABLE, $usercompetency->to_record());
  60          return $event;
  61      }
  62  
  63      /**
  64       * Returns description of what happened.
  65       *
  66       * @return string
  67       */
  68      public function get_description() {
  69          return "The user with id '$this->userid' cancelled a review request for the user competency with id '$this->objectid'";
  70      }
  71  
  72      /**
  73       * Return localised event name.
  74       *
  75       * @return string
  76       */
  77      public static function get_name() {
  78          return get_string('eventusercompetencyreviewrequestcancelled', 'core_competency');
  79      }
  80  
  81      /**
  82       * Get URL related to the action
  83       *
  84       * @return \moodle_url
  85       */
  86      public function get_url() {
  87          return \core_competency\url::user_competency($this->objectid);
  88      }
  89  
  90      /**
  91       * Init method.
  92       *
  93       * @return void
  94       */
  95      protected function init() {
  96          $this->data['crud'] = 'u';
  97          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  98          $this->data['objecttable'] = user_competency::TABLE;
  99      }
 100  
 101      /**
 102       * Get_objectid_mapping method.
 103       *
 104       * @return string the name of the restore mapping the objectid links to
 105       */
 106      public static function get_objectid_mapping() {
 107          return base::NOT_MAPPED;
 108      }
 109  
 110      /**
 111       * Custom validation.
 112       *
 113       * Throw \coding_exception notice in case of any problems.
 114       */
 115      protected function validate_data() {
 116          if (!$this->relateduserid) {
 117              throw new \coding_exception('The \'relateduserid\' value must be set.');
 118          }
 119      }
 120  
 121  }