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 remove submission form viewed event. 19 * 20 * @package mod_assign 21 * @copyright 2019 Damyon Wiese 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 remove submission form viewed event class. 31 * 32 * @package mod_assign 33 * @copyright 2019 Damyon Wiese 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class remove_submission_form_viewed extends base { 37 38 /** 39 * Flag for prevention of direct create() call. 40 * @var bool 41 */ 42 protected static $preventcreatecall = true; 43 44 /** 45 * Create instance of event. 46 * 47 * @param \assign $assign 48 * @param \stdClass $user 49 * @return remove_submission_form_viewed 50 */ 51 public static function create_from_user(\assign $assign, \stdClass $user) { 52 $data = array( 53 'relateduserid' => $user->id, 54 'context' => $assign->get_context(), 55 'other' => array( 56 'assignid' => $assign->get_instance()->id, 57 ), 58 ); 59 self::$preventcreatecall = false; 60 /** @var remove_submission_form_viewed $event */ 61 $event = self::create($data); 62 self::$preventcreatecall = true; 63 $event->set_assign($assign); 64 $event->add_record_snapshot('user', $user); 65 return $event; 66 } 67 68 /** 69 * Init method. 70 */ 71 protected function init() { 72 $this->data['crud'] = 'r'; 73 $this->data['edulevel'] = self::LEVEL_OTHER; 74 } 75 76 /** 77 * Returns localised general event name. 78 * 79 * @return string 80 */ 81 public static function get_name() { 82 return get_string('eventremovesubmissionformviewed', 'mod_assign'); 83 } 84 85 /** 86 * Returns description of what happened. 87 * 88 * @return string 89 */ 90 public function get_description() { 91 if ($this->userid != $this->relateduserid) { 92 return "The user with id '$this->userid' viewed the " . 93 "remove submission form for the user with id '$this->relateduserid' " . 94 "for the assignment with course module id '$this->contextinstanceid'."; 95 } 96 97 return "The user with id '$this->userid' viewed their remove submission form for the assignment with course module id " . 98 "'$this->contextinstanceid'."; 99 } 100 101 /** 102 * Custom validation. 103 * 104 * @throws \coding_exception 105 */ 106 protected function validate_data() { 107 if (self::$preventcreatecall) { 108 throw new \coding_exception('cannot call remove_submission_form_viewed::create() directly, use ' . 109 'remove_submission_form_viewed::create_from_user() instead.'); 110 } 111 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 /** 124 * This is documented in the parent class. 125 * 126 * @return array an array of other values and their corresponding mapping 127 */ 128 public static function get_other_mapping() { 129 $othermapped = array(); 130 $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); 131 132 return $othermapped; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body