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   * The mod_assign feedback viewed event.
  19   *
  20   * @package    mod_assign
  21   * @copyright  2014 Mark Nelson <markn@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_assign\event;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * The mod_assign feedback viewed event class.
  31   *
  32   * @property-read array $other {
  33   *      Extra information about event.
  34   *
  35   *      - int assignid: the id of the assignment.
  36   * }
  37   *
  38   * @package    mod_assign
  39   * @since      Moodle 2.7
  40   * @copyright  2014 Mark Nelson <markn@moodle.com>
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class feedback_viewed extends base {
  44      /**
  45       * Create instance of event.
  46       *
  47       * @param \assign $assign
  48       * @param \stdClass $grade
  49       * @return feedback_viewed
  50       */
  51      public static function create_from_grade(\assign $assign, \stdClass $grade) {
  52          $data = array(
  53              'objectid' => $grade->id,
  54              'relateduserid' => $grade->userid,
  55              'context' => $assign->get_context(),
  56              'other' => array(
  57                  'assignid' => $assign->get_instance()->id,
  58              ),
  59          );
  60          /** @var feedback_viewed $event */
  61          $event = self::create($data);
  62          $event->set_assign($assign);
  63          $event->add_record_snapshot('assign_grades', $grade);
  64          return $event;
  65      }
  66  
  67      /**
  68       * Init method.
  69       */
  70      protected function init() {
  71          $this->data['objecttable'] = 'assign_grades';
  72          $this->data['crud'] = 'r';
  73          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  74      }
  75  
  76      /**
  77       * Returns localised general event name.
  78       *
  79       * @return string
  80       */
  81      public static function get_name() {
  82          return get_string('eventfeedbackviewed', 'mod_assign');
  83      }
  84  
  85      /**
  86       * Returns description of what happened.
  87       *
  88       * @return string
  89       */
  90      public function get_description() {
  91          return "The user with id '$this->userid' viewed the feedback for the user with id '$this->relateduserid' " .
  92              "for the assignment with course module id '$this->contextinstanceid'.";
  93      }
  94  
  95      /**
  96       * Return legacy data for add_to_log().
  97       *
  98       * @return array
  99       */
 100      protected function get_legacy_logdata() {
 101          $logmessage = get_string('viewfeedbackforuser', 'assign', $this->relateduserid);
 102          $this->set_legacy_logdata('view feedback', $logmessage);
 103          return parent::get_legacy_logdata();
 104      }
 105  
 106      /**
 107       * Custom validation.
 108       *
 109       * @throws \coding_exception
 110       */
 111      protected function validate_data() {
 112          parent::validate_data();
 113  
 114          if (!isset($this->relateduserid)) {
 115              throw new \coding_exception('The \'relateduserid\' must be set.');
 116          }
 117  
 118          if (!isset($this->other['assignid'])) {
 119              throw new \coding_exception('The \'assignid\' value must be set in other.');
 120          }
 121      }
 122  
 123      public static function get_objectid_mapping() {
 124          return array('db' => 'assign_grades', 'restore' => 'grade');
 125      }
 126  
 127      public static function get_other_mapping() {
 128          $othermapped = array();
 129          $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
 130  
 131          return $othermapped;
 132      }
 133  }