Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 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   * Event for when blog entries are viewed.
  18   *
  19   * @package    core
  20   * @copyright  2013 onwards Ankit Agarwal
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  namespace core\event;
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Class for event to be triggered when blog entries are viewed.
  29   *
  30   * @property-read array $other {
  31   *      Extra information about event.
  32   *
  33   *      - int entryid: (optional) id of the entry.
  34   *      - int tagid: (optional) id of the tag.
  35   *      - int userid: (optional) id of the user.
  36   *      - int modid: (optional) id of the mod.
  37   *      - int groupid: (optional) id of the group.
  38   *      - int courseid: (optional) id of associated course.
  39   *      - string search: (optional) the string used to search.
  40   *      - int fromstart: (optional) the time to search from.
  41   * }
  42   *
  43   * @package    core
  44   * @since      Moodle 2.7
  45   * @copyright  2013 onwards Ankit Agarwal
  46   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  47   */
  48  class blog_entries_viewed extends base {
  49  
  50      /** @var array List of url params accepted*/
  51      private $validparams = array('entryid', 'tagid', 'userid', 'modid', 'groupid', 'courseid', 'search', 'fromstart');
  52  
  53      /**
  54       * Set basic properties for the event.
  55       */
  56      protected function init() {
  57          $this->context = \context_system::instance();
  58          $this->data['crud'] = 'r';
  59          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  60      }
  61  
  62      /**
  63       * Returns localised general event name.
  64       *
  65       * @return string
  66       */
  67      public static function get_name() {
  68          return get_string('eventblogentriesviewed', 'core_blog');
  69      }
  70  
  71      /**
  72       * Returns non-localised event description with id's for admin use only.
  73       *
  74       * @return string
  75       */
  76      public function get_description() {
  77          return "The user with id '$this->userid' viewed blog entries.";
  78      }
  79  
  80      /**
  81       * Returns relevant URL.
  82       * @return \moodle_url
  83       */
  84      public function get_url() {
  85          $params = array();
  86          foreach ($this->validparams as $param) {
  87              if (!empty($this->other[$param])) {
  88                  $params[$param] = $this->other[$param];
  89              }
  90          }
  91          return new \moodle_url('/blog/index.php', $params);
  92      }
  93  
  94      /**
  95       * replace add_to_log() statement.
  96       *
  97       * @return array of parameters to be passed to legacy add_to_log() function.
  98       */
  99      protected function get_legacy_logdata() {
 100          $params = array();
 101          foreach ($this->validparams as $param) {
 102              if (!empty($this->other[$param])) {
 103                  $params[$param] = $this->other[$param];
 104              }
 105          }
 106          $url = new \moodle_url('index.php', $params);
 107          return array (SITEID, 'blog', 'view', $url->out(), 'view blog entry');
 108      }
 109  
 110      public static function get_other_mapping() {
 111          $othermapped = array();
 112          $othermapped['entryid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED);
 113          $othermapped['tagid'] = array('db' => 'tag', 'restore' => base::NOT_MAPPED);
 114          $othermapped['userid'] = array('db' => 'user', 'restore' => 'user');
 115          $othermapped['modid'] = array('db' => 'course_modules', 'restore' => 'course_module');
 116          $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
 117          $othermapped['courseid'] = array('db' => 'course', 'restore' => 'course');
 118  
 119          return $othermapped;
 120      }
 121  }