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   * calendar subscription deleted 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 a calendar subscription is deleted.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about the event.
  33   *
  34   *      - int courseid: The ID of the course (SITEID, User(0) or actual course)
  35   * }
  36   *
  37   * @package    core
  38   * @since      Moodle 3.2
  39   * @copyright  2016 Stephen Bourget
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class calendar_subscription_deleted extends base
  43  {
  44  
  45      /**
  46       * Init method.
  47       *
  48       * @return void
  49       */
  50      protected function init() {
  51          $this->data['crud'] = 'd';
  52          $this->data['edulevel'] = self::LEVEL_OTHER;
  53          $this->data['objecttable'] = 'event_subscriptions';
  54      }
  55  
  56      /**
  57       * Returns localised general event name.
  58       *
  59       * @return string
  60       */
  61      public static function get_name() {
  62          return get_string('eventsubscriptiondeleted', 'calendar');
  63      }
  64  
  65      /**
  66       * Returns description of what happened.
  67       *
  68       * @return string
  69       */
  70      public function get_description() {
  71          return "User {$this->userid} has deleted a calendar
  72           subscription with id {$this->objectid}.";
  73      }
  74  
  75      /**
  76       * Returns relevant URL.
  77       *
  78       * @return \moodle_url
  79       */
  80      public function get_url() {
  81          $params = [];
  82          if (isset($this->other['eventtype'])) {
  83              if ($this->other['eventtype'] == 'course' || $this->other['eventtype'] == 'group') {
  84                  $params['course'] = $this->other['courseid'];
  85                  if ($this->other['eventtype'] == 'group' && isset($this->other['groupid'])) {
  86                      $params['group'] = $this->other['groupid'];
  87                  }
  88              }
  89              if ($this->other['eventtype'] == 'category' && isset($this->other['categoryid'])) {
  90                  $params['category'] = $this->other['categoryid'];
  91              }
  92          } else {
  93              // This is a legacy event.
  94              // Prior to specification of the eventtype there were only two params.
  95              if (($this->other['courseid'] != SITEID) && ($this->other['courseid'] != 0)) {
  96                  $params['course'] = $this->other['courseid'];
  97              }
  98          }
  99          return new \moodle_url('/calendar/managesubscriptions.php', $params);
 100  
 101      }
 102  
 103      /**
 104       * Custom validations.
 105       *
 106       * @throws \coding_exception
 107       * @return void
 108       */
 109      protected function validate_data() {
 110          parent::validate_data();
 111          if (!isset($this->context)) {
 112              throw new \coding_exception('The \'context\' must be set.');
 113          }
 114          if (!isset($this->objectid)) {
 115              throw new \coding_exception('The \'objectid\' must be set.');
 116          }
 117          if (!isset($this->other['eventtype'])) {
 118              throw new \coding_exception('The \'eventtype\' value must be set in other.');
 119          }
 120          if ($this->other['eventtype'] == 'course' || $this->other['eventtype'] == 'group') {
 121              if (!isset($this->other['courseid'])) {
 122                  throw new \coding_exception('The \'courseid\' value must be set in other.');
 123              }
 124              if ($this->other['eventtype'] == 'group' && !isset($this->other['groupid'])) {
 125                  throw new \coding_exception('The \'groupid\' value must be set in other.');
 126              }
 127          }
 128          if ($this->other['eventtype'] == 'category' && !isset($this->other['categoryid'])) {
 129              throw new \coding_exception('The \'categoryid\' value must be set in other.');
 130          }
 131      }
 132  
 133      /**
 134       * Returns mappings for restore
 135       *
 136       * @return array
 137       */
 138      public static function get_objectid_mapping() {
 139          return array('db' => 'event_subscriptions', 'restore' => 'event_subscriptions');
 140      }
 141  }