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  /**
  18   * The mod_assign marker updated event.
  19   *
  20   * @package    mod_assign
  21   * @copyright  2013 Frédéric Massart
  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 marker updated event class.
  31   *
  32   * @property-read array $other {
  33   *      Extra information about event.
  34   *
  35   *      - int markerid: user id of marker.
  36   * }
  37   *
  38   * @package    mod_assign
  39   * @since      Moodle 2.6
  40   * @copyright  2013 Frédéric Massart
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class marker_updated extends base {
  44      /**
  45       * Flag for prevention of direct create() call.
  46       * @var bool
  47       */
  48      protected static $preventcreatecall = true;
  49  
  50      /**
  51       * Create instance of event.
  52       *
  53       * @since Moodle 2.7
  54       *
  55       * @param \assign $assign
  56       * @param \stdClass $user
  57       * @param \stdClass $marker
  58       * @return marker_updated
  59       */
  60      public static function create_from_marker(\assign $assign, \stdClass $user, \stdClass $marker) {
  61          $data = array(
  62              'context' => $assign->get_context(),
  63              'objectid' => $assign->get_instance()->id,
  64              'relateduserid' => $user->id,
  65              'other' => array(
  66                  'markerid' => $marker->id,
  67              ),
  68          );
  69          self::$preventcreatecall = false;
  70          /** @var marker_updated $event */
  71          $event = self::create($data);
  72          self::$preventcreatecall = true;
  73          $event->set_assign($assign);
  74          $event->add_record_snapshot('user', $user);
  75          $event->add_record_snapshot('user', $marker);
  76          return $event;
  77      }
  78  
  79      /**
  80       * Returns description of what happened.
  81       *
  82       * @return string
  83       */
  84      public function get_description() {
  85          return "The user with id '$this->userid' has set the marker for the user with id '$this->relateduserid' to " .
  86              "'{$this->other['markerid']}' for the assignment with course module id '$this->contextinstanceid'.";
  87      }
  88  
  89      /**
  90       * Return localised event name.
  91       *
  92       * @return string
  93       */
  94      public static function get_name() {
  95          return get_string('eventmarkerupdated', 'mod_assign');
  96      }
  97  
  98      /**
  99       * Init method.
 100       *
 101       * @return void
 102       */
 103      protected function init() {
 104          $this->data['crud'] = 'u';
 105          $this->data['edulevel'] = self::LEVEL_TEACHING;
 106          $this->data['objecttable'] = 'assign';
 107      }
 108  
 109      /**
 110       * Return legacy data for add_to_log().
 111       *
 112       * @return array
 113       */
 114      protected function get_legacy_logdata() {
 115          $user = $this->get_record_snapshot('user', $this->relateduserid);
 116          $marker = $this->get_record_snapshot('user', $this->other['markerid']);
 117          $a = array('id' => $user->id, 'fullname' => fullname($user), 'marker' => fullname($marker));
 118          $logmessage = get_string('setmarkerallocationforlog', 'assign', $a);
 119          $this->set_legacy_logdata('set marking allocation', $logmessage);
 120          return parent::get_legacy_logdata();
 121      }
 122  
 123      /**
 124       * Custom validation.
 125       *
 126       * @throws \coding_exception
 127       */
 128      protected function validate_data() {
 129          if (self::$preventcreatecall) {
 130              throw new \coding_exception('cannot call marker_updated::create() directly, use marker_updated::create_from_marker() instead.');
 131          }
 132  
 133          parent::validate_data();
 134  
 135          if (!isset($this->relateduserid)) {
 136              throw new \coding_exception('The \'relateduserid\' must be set.');
 137          }
 138  
 139          if (!isset($this->other['markerid'])) {
 140              throw new \coding_exception('The \'markerid\' value must be set in other.');
 141          }
 142      }
 143  
 144      public static function get_objectid_mapping() {
 145          return array('db' => 'assign', 'restore' => 'assign');
 146      }
 147  
 148      public static function get_other_mapping() {
 149          $othermapped = array();
 150          $othermapped['markerid'] = array('db' => 'user', 'restore' => 'user');
 151  
 152          return $othermapped;
 153      }
 154  }