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.

Differences Between: [Versions 401 and 402] [Versions 401 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  /**
  18   * Event to be triggered when a blog entry is updated.
  19   *
  20   * @package    core
  21   * @copyright  2013 Ankit Agarwal
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core\event;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Class blog_entry_updated
  29   *
  30   * Event to be triggered when a blog entry is updated.
  31   *
  32   * @package    core
  33   * @since      Moodle 2.6
  34   * @copyright  2013 Ankit Agarwal
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class blog_entry_updated extends base {
  38  
  39      /** @var \blog_entry A reference to the active blog_entry object. */
  40      protected $blogentry;
  41  
  42      /**
  43       * Set basic event properties.
  44       */
  45      protected function init() {
  46          $this->context = \context_system::instance();
  47          $this->data['objecttable'] = 'post';
  48          $this->data['crud'] = 'u';
  49          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  50      }
  51  
  52      /**
  53       * Sets blog_entry object to be used by observers.
  54       *
  55       * @param \blog_entry $blogentry A reference to the active blog_entry object.
  56       */
  57      public function set_blog_entry(\blog_entry $blogentry) {
  58          $this->blogentry = $blogentry;
  59      }
  60  
  61      /**
  62       * Returns updated blog entry for event observers.
  63       *
  64       * @throws \coding_exception
  65       * @return \blog_entry
  66       */
  67      public function get_blog_entry() {
  68          if ($this->is_restored()) {
  69              throw new \coding_exception('Function get_blog_entry() can not be used on restored events.');
  70          }
  71          return $this->blogentry;
  72      }
  73  
  74      /**
  75       * Returns localised general event name.
  76       *
  77       * @return string
  78       */
  79      public static function get_name() {
  80          return get_string('evententryupdated', 'core_blog');
  81      }
  82  
  83      /**
  84       * Returns non-localised description of what happened.
  85       *
  86       * @return string
  87       */
  88      public function get_description() {
  89          return "The user with id '$this->userid' updated the blog entry with id '$this->objectid'.";
  90      }
  91  
  92      /**
  93       * Returns relevant URL.
  94       * @return \moodle_url
  95       */
  96      public function get_url() {
  97          return new \moodle_url('/blog/index.php', array('entryid' => $this->objectid));
  98      }
  99  
 100      /**
 101       * Legacy event data if get_legacy_eventname() is not empty.
 102       *
 103       * @return \blog_entry
 104       */
 105      protected function get_legacy_eventdata() {
 106          return $this->blogentry;
 107      }
 108  
 109      /**
 110       * Legacy event name.
 111       *
 112       * @return string legacy event name
 113       */
 114      public static function get_legacy_eventname() {
 115          return 'blog_entry_edited';
 116      }
 117  
 118      /**
 119       * Replace legacy add_to_log() statement.
 120       *
 121       * @return array of parameters to be passed to legacy add_to_log() function.
 122       */
 123      protected function get_legacy_logdata() {
 124          return array(SITEID, 'blog', 'update', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
 125                   $this->blogentry->subject);
 126      }
 127  
 128      /**
 129       * Custom validations.
 130       *
 131       * @throws \coding_exception
 132       * @return void
 133       */
 134      protected function validate_data() {
 135          parent::validate_data();
 136  
 137          if (!isset($this->relateduserid)) {
 138              throw new \coding_exception('The \'relateduserid\' must be set.');
 139          }
 140      }
 141  
 142      public static function get_objectid_mapping() {
 143          // Blogs are not backed up, so no need for mapping for restore.
 144          return array('db' => 'post', 'restore' => NOT_MAPPED);
 145      }
 146  }
 147