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.
   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 plan viewed 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_plan;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  /**
  33   * User competency plan viewed event class.
  34   *
  35   * @property-read array $other {
  36   *      Extra information about event.
  37   *
  38   *      - int planid: id of plan for which competency is associated.
  39   *      - int competencyid: id of the competency.
  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_plan_viewed extends base {
  48  
  49      /**
  50       * Convenience method to instantiate the event.
  51       *
  52       * @param user_competency_plan $usercompetencyplan The user competency plan.
  53       * @return self
  54       */
  55      public static function create_from_user_competency_plan(user_competency_plan $usercompetencyplan) {
  56          if (!$usercompetencyplan->get('id')) {
  57              throw new \coding_exception('The user competency plan ID must be set.');
  58          }
  59          $event = static::create(array(
  60              'contextid' => $usercompetencyplan->get_context()->id,
  61              'objectid' => $usercompetencyplan->get('id'),
  62              'relateduserid' => $usercompetencyplan->get('userid'),
  63              'other' => array(
  64                  'planid' => $usercompetencyplan->get('planid'),
  65                  'competencyid' => $usercompetencyplan->get('competencyid')
  66              )
  67          ));
  68          $event->add_record_snapshot(user_competency_plan::TABLE, $usercompetencyplan->to_record());
  69          return $event;
  70      }
  71  
  72      /**
  73       * Returns description of what happened.
  74       *
  75       * @return string
  76       */
  77      public function get_description() {
  78          return "The user with id '$this->userid' viewed the user competency plan with id '$this->objectid'";
  79      }
  80  
  81      /**
  82       * Return localised event name.
  83       *
  84       * @return string
  85       */
  86      public static function get_name() {
  87          return get_string('eventusercompetencyplanviewed', 'core_competency');
  88      }
  89  
  90      /**
  91       * Get URL related to the action
  92       *
  93       * @return \moodle_url
  94       */
  95      public function get_url() {
  96          return \core_competency\url::user_competency_in_plan($this->relateduserid, $this->other['competencyid'],
  97              $this->other['planid']);
  98      }
  99  
 100      /**
 101       * Init method.
 102       *
 103       * @return void
 104       */
 105      protected function init() {
 106          $this->data['crud'] = 'r';
 107          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
 108          $this->data['objecttable'] = user_competency_plan::TABLE;
 109      }
 110  
 111      /**
 112       * Get_objectid_mapping method.
 113       *
 114       * @return string the name of the restore mapping the objectid links to
 115       */
 116      public static function get_objectid_mapping() {
 117          return base::NOT_MAPPED;
 118      }
 119  
 120      /**
 121       * Custom validation.
 122       *
 123       * Throw \coding_exception notice in case of any problems.
 124       */
 125      protected function validate_data() {
 126          if ($this->other === null) {
 127              throw new \coding_exception('The \'competencyid\' and \'planid\' values must be set.');
 128          }
 129  
 130          if (!isset($this->other['competencyid'])) {
 131              throw new \coding_exception('The \'competencyid\' value must be set.');
 132          }
 133  
 134          if (!isset($this->other['planid'])) {
 135              throw new \coding_exception('The \'planid\' value must be set.');
 136          }
 137      }
 138  
 139  }