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.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

   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 pinned 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 pinned 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_pinned 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 pinned 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('eventdiscussionpinned', '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       * Custom validation.
  75       *
  76       * @throws \coding_exception
  77       * @return void
  78       */
  79      protected function validate_data() {
  80          parent::validate_data();
  81          if (!isset($this->other['forumid'])) {
  82              throw new \coding_exception('forumid must be set in $other.');
  83          }
  84          if ($this->contextlevel != CONTEXT_MODULE) {
  85              throw new \coding_exception('Context passed must be module context.');
  86          }
  87          if (!isset($this->objectid)) {
  88              throw new \coding_exception('objectid must be set to the discussionid.');
  89          }
  90      }
  91  
  92      /**
  93       * Forum discussion object id mappings.
  94       *
  95       * @return array
  96       */
  97      public static function get_objectid_mapping() {
  98          return array('db' => 'forum_discussions', 'restore' => 'forum_discussion');
  99      }
 100  
 101      /**
 102       * Forum id mappings.
 103       *
 104       * @return array
 105       */
 106      public static function get_other_mapping() {
 107          $othermapped = array();
 108          $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum');
 109  
 110          return $othermapped;
 111      }
 112  }