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  /**
  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       * Custom validation.
  97       *
  98       * @throws \coding_exception
  99       */
 100      protected function validate_data() {
 101          parent::validate_data();
 102  
 103          if (!isset($this->relateduserid)) {
 104              throw new \coding_exception('The \'relateduserid\' must be set.');
 105          }
 106  
 107          if (!isset($this->other['assignid'])) {
 108              throw new \coding_exception('The \'assignid\' value must be set in other.');
 109          }
 110      }
 111  
 112      public static function get_objectid_mapping() {
 113          return array('db' => 'assign_grades', 'restore' => 'grade');
 114      }
 115  
 116      public static function get_other_mapping() {
 117          $othermapped = array();
 118          $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
 119  
 120          return $othermapped;
 121      }
 122  }