MDL-41101 mod_assign: replaced 'view submit assignment form' add_to_log call with...
[moodle.git] / mod / assign / classes / event / submission_form_viewed.php
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/>.
17 /**
18  * The mod_assign submission form viewed event.
19  *
20  * @property-read array $other {
21  *      Extra information about event.
22  *
23  *      - int assignid: the id of the assignment.
24  * }
25  *
26  * @package    mod_assign
27  * @since      Moodle 2.7
28  * @copyright  2014 Mark Nelson <markn@moodle.com>
29  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30  */
32 namespace mod_assign\event;
34 defined('MOODLE_INTERNAL') || die();
36 class submission_form_viewed extends base {
38     /**
39      * Init method.
40      */
41     protected function init() {
42         $this->data['crud'] = 'r';
43         $this->data['edulevel'] = self::LEVEL_OTHER;
44     }
46     /**
47      * Returns localised general event name.
48      *
49      * @return string
50      */
51     public static function get_name() {
52         return get_string('eventsubmissionformviewed', 'mod_assign');
53     }
55     /**
56      * Returns description of what happened.
57      *
58      * @return string
59      */
60     public function get_description() {
61         if ($this->userid != $this->relateduserid) {
62             return "The user with the id {$this->userid} viewed the submission form for the user with the id {$this->relateduserid}
63                 for the assignment with the id {$this->other['assignid']}.";
64         }
66         return "The user with the id {$this->userid} viewed their submission for the assignment with the id
67             {$this->other['assignid']}.";
68     }
70     /**
71      * Custom validation.
72      *
73      * @throws \coding_exception
74      */
75     protected function validate_data() {
76         parent::validate_data();
78         if (!isset($this->relateduserid)) {
79             throw new \coding_exception('The \'relateduserid\' must be set.');
80         }
82         if (!isset($this->other['assignid'])) {
83             throw new \coding_exception('The \'assignid\' must be set in other.');
84         }
85     }
86 }