Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

   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   * The mod_forum discussion unpinned event.
  18   *
  19   * @package    mod_forum
  20   * @copyright  2014 Charles Fulton <fultonc@lafayette.edu>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  namespace mod_forum\event;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * The mod_forum discussion unpinned event.
  29   *
  30   * @package    mod_forum
  31   * @copyright  2014 Charles Fulton <fultonc@lafayette.edu>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class discussion_unpinned extends \core\event\base {
  35      /**
  36       * Init method.
  37       *
  38       * @return void
  39       */
  40      protected function init() {
  41          $this->data['crud'] = 'u';
  42          $this->data['edulevel'] = self::LEVEL_OTHER;
  43          $this->data['objecttable'] = 'forum_discussions';
  44      }
  45  
  46      /**
  47       * Returns description of what happened.
  48       *
  49       * @return string
  50       */
  51      public function get_description() {
  52          return "The user {$this->userid} has unpinned the discussion {$this->objectid} in the forum {$this->other['forumid']}";
  53      }
  54  
  55      /**
  56       * Return localised event name.
  57       *
  58       * @return string
  59       */
  60      public static function get_name() {
  61          return get_string('eventdiscussionunpinned', 'mod_forum');
  62      }
  63  
  64      /**
  65       * Get URL related to the action
  66       *
  67       * @return \moodle_url
  68       */
  69      public function get_url() {
  70          return new \moodle_url('/mod/forum/discuss.php', array('d' => $this->objectid));
  71      }
  72  
  73      /**
  74       * Return the legacy event log data.
  75       *
  76       * @return array|null
  77       */
  78      protected function get_legacy_logdata() {
  79          // The legacy log table expects a relative path to /mod/forum/.
  80          $logurl = substr($this->get_url()->out_as_local_url(), strlen('/mod/forum/'));
  81          return array($this->courseid, 'forum', 'unpin discussion', $logurl, $this->objectid, $this->contextinstanceid);
  82      }
  83  
  84      /**
  85       * Custom validation.
  86       *
  87       * @throws \coding_exception
  88       * @return void
  89       */
  90      protected function validate_data() {
  91          parent::validate_data();
  92          if (!isset($this->other['forumid'])) {
  93              throw new \coding_exception('forumid must be set in $other.');
  94          }
  95          if ($this->contextlevel != CONTEXT_MODULE) {
  96              throw new \coding_exception('Context passed must be module context.');
  97          }
  98          if (!isset($this->objectid)) {
  99              throw new \coding_exception('objectid must be set to the discussionid.');
 100          }
 101      }
 102  
 103      /**
 104       * Forum discussion object id mappings.
 105       *
 106       * @return array
 107       */
 108      public static function get_objectid_mapping() {
 109          return array('db' => 'forum_discussions', 'restore' => 'forum_discussion');
 110      }
 111  
 112      /**
 113       * Forum id mappings.
 114       *
 115       * @return array
 116       */
 117      public static function get_other_mapping() {
 118          $othermapped = array();
 119          $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum');
 120  
 121          return $othermapped;
 122      }
 123  }