Differences Between: [Versions 310 and 402] [Versions 310 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 * mod_assign workflow state 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 * mod_assign workflow state updated event class. 31 * 32 * @property-read array $other { 33 * Extra information about event. 34 * 35 * - string newstate: state of submission. 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 workflow_state_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 string $state 58 * @return workflow_state_updated 59 */ 60 public static function create_from_user(\assign $assign, \stdClass $user, $state) { 61 $data = array( 62 'context' => $assign->get_context(), 63 'objectid' => $assign->get_instance()->id, 64 'relateduserid' => $user->id, 65 'other' => array( 66 'newstate' => $state, 67 ), 68 ); 69 self::$preventcreatecall = false; 70 /** @var workflow_state_updated $event */ 71 $event = self::create($data); 72 self::$preventcreatecall = true; 73 $event->set_assign($assign); 74 $event->add_record_snapshot('user', $user); 75 return $event; 76 } 77 78 /** 79 * Returns description of what happened. 80 * 81 * @return string 82 */ 83 public function get_description() { 84 return "The user with id '$this->userid' has set the workflow state of the user with id '$this->relateduserid' " . 85 "to the state '{$this->other['newstate']}' for the assignment with course module id '$this->contextinstanceid'."; 86 } 87 88 /** 89 * Return localised event name. 90 * 91 * @return string 92 */ 93 public static function get_name() { 94 return get_string('eventworkflowstateupdated', 'mod_assign'); 95 } 96 97 /** 98 * Init method. 99 * 100 * @return void 101 */ 102 protected function init() { 103 $this->data['crud'] = 'u'; 104 $this->data['edulevel'] = self::LEVEL_TEACHING; 105 $this->data['objecttable'] = 'assign'; 106 } 107 108 /** 109 * Return legacy data for add_to_log(). 110 * 111 * @return array 112 */ 113 protected function get_legacy_logdata() { 114 $user = $this->get_record_snapshot('user', $this->relateduserid); 115 $a = array('id' => $user->id, 'fullname' => fullname($user), 'state' => $this->other['newstate']); 116 $logmessage = get_string('setmarkingworkflowstateforlog', 'assign', $a); 117 $this->set_legacy_logdata('set marking workflow state', $logmessage); 118 return parent::get_legacy_logdata(); 119 } 120 121 /** 122 * Custom validation. 123 * 124 * @throws \coding_exception 125 */ 126 protected function validate_data() { 127 if (self::$preventcreatecall) { 128 throw new \coding_exception('cannot call workflow_state_updated::create() directly, use workflow_state_updated::create_from_user() instead.'); 129 } 130 131 parent::validate_data(); 132 133 if (!isset($this->relateduserid)) { 134 throw new \coding_exception('The \'relateduserid\' must be set.'); 135 } 136 137 if (!isset($this->other['newstate'])) { 138 throw new \coding_exception('The \'newstate\' value must be set in other.'); 139 } 140 } 141 142 public static function get_objectid_mapping() { 143 return array('db' => 'assign', 'restore' => 'assign'); 144 } 145 146 public static function get_other_mapping() { 147 // Nothing to map. 148 return false; 149 } 150 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body