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   * User competency grade rated in course 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 grade rated in plan event class.
  33   *
  34   * @property-read array $other {
  35   *      Extra information about event.
  36   *
  37   *      - int competencyid: id of competency.
  38   *      - int grade: grade name of the user competency
  39   *      - int planid: the plan id
  40   * }
  41   *
  42   * @package    core_competency
  43   * @since      Moodle 3.1
  44   * @copyright  2016 Issam Taboubi <issam.taboubi@umontreal.ca>
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class competency_user_competency_rated_in_plan extends base {
  48  
  49      /**
  50       * Convenience method to instantiate the event.
  51       *
  52       * @param user_competency $usercompetency The user competency.
  53       * @param int $planid The plan ID
  54       * @return self
  55       */
  56      public static function create_from_user_competency(user_competency $usercompetency, $planid) {
  57          if (!$usercompetency->get('id')) {
  58              throw new \coding_exception('The user competency ID must be set.');
  59          }
  60  
  61          $params = array(
  62              'contextid' => $usercompetency->get_context()->id,
  63              'objectid' => $usercompetency->get('id'),
  64              'relateduserid' => $usercompetency->get('userid'),
  65              'other' => array(
  66                  'competencyid' => $usercompetency->get('competencyid'),
  67                  'grade' => $usercompetency->get('grade'),
  68                  'planid' => $planid
  69              )
  70          );
  71  
  72          $event = static::create($params);
  73          $event->add_record_snapshot(user_competency::TABLE, $usercompetency->to_record());
  74          return $event;
  75      }
  76  
  77      /**
  78       * Returns description of what happened.
  79       *
  80       * @return string
  81       */
  82      public function get_description() {
  83          return "The user with id '$this->userid' rated the user competency with id '$this->objectid' with "
  84                  . "'" . $this->other['grade'] . "' rating "
  85                  . "in plan with id '" . $this->other['grade'] . "'";
  86      }
  87  
  88      /**
  89       * Return localised event name.
  90       *
  91       * @return string
  92       */
  93      public static function get_name() {
  94          return get_string('eventusercompetencyratedinplan', 'core_competency');
  95      }
  96  
  97      /**
  98       * Get URL related to the action
  99       *
 100       * @return \moodle_url
 101       */
 102      public function get_url() {
 103          return \core_competency\url::user_competency_in_plan($this->relateduserid, $this->other['competencyid'],
 104              $this->other['planid']);
 105      }
 106  
 107      /**
 108       * Init method.
 109       *
 110       * @return void
 111       */
 112      protected function init() {
 113          $this->data['crud'] = 'u';
 114          $this->data['edulevel'] = self::LEVEL_TEACHING;
 115          $this->data['objecttable'] = user_competency::TABLE;
 116      }
 117  
 118      /**
 119       * Get_objectid_mapping method.
 120       *
 121       * @return string the name of the restore mapping the objectid links to
 122       */
 123      public static function get_objectid_mapping() {
 124          return base::NOT_MAPPED;
 125      }
 126  
 127      /**
 128       * Custom validation.
 129       *
 130       * Throw \coding_exception notice in case of any problems.
 131       */
 132      protected function validate_data() {
 133          if (!isset($this->other) || !isset($this->other['competencyid'])) {
 134              throw new \coding_exception('The \'competencyid\' value must be set.');
 135          }
 136  
 137          if (!isset($this->other['planid'])) {
 138              throw new \coding_exception('The \'planid\' value must be set.');
 139          }
 140  
 141          if (!$this->relateduserid) {
 142              throw new \coding_exception('The \'relateduserid\' value must be set.');
 143          }
 144  
 145          if (!isset($this->other['grade'])) {
 146              throw new \coding_exception('The \'grade\' value must be set.');
 147          }
 148      }
 149  
 150  }