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 * 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 * Custom validation. 110 * 111 * @throws \coding_exception 112 */ 113 protected function validate_data() { 114 if (self::$preventcreatecall) { 115 throw new \coding_exception('cannot call workflow_state_updated::create() directly, use workflow_state_updated::create_from_user() instead.'); 116 } 117 118 parent::validate_data(); 119 120 if (!isset($this->relateduserid)) { 121 throw new \coding_exception('The \'relateduserid\' must be set.'); 122 } 123 124 if (!isset($this->other['newstate'])) { 125 throw new \coding_exception('The \'newstate\' value must be set in other.'); 126 } 127 } 128 129 public static function get_objectid_mapping() { 130 return array('db' => 'assign', 'restore' => 'assign'); 131 } 132 133 public static function get_other_mapping() { 134 // Nothing to map. 135 return false; 136 } 137 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body