grading_table_viewed.php 3.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

17
18
19
20
21
22
23
24
25
26
27
28
/**
 * The mod_assign grading table viewed event.
 *
 * @package    mod_assign
 * @copyright  2014 Mark Nelson <markn@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace mod_assign\event;

defined('MOODLE_INTERNAL') || die();

29
/**
30
 * The mod_assign grading table viewed event class.
31
32
33
34
35
36
37
38
39
40
41
42
43
 *
 * @property-read array $other {
 *      Extra information about event.
 *
 *      - int assignid: the id of the assignment.
 * }
 *
 * @package    mod_assign
 * @since      Moodle 2.7
 * @copyright  2014 Mark Nelson <markn@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class grading_table_viewed extends base {
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    /**
     * Flag for prevention of direct create() call.
     * @var bool
     */
    protected static $preventcreatecall = true;

    /**
     * Create instance of event.
     *
     * @param \assign $assign
     * @return grading_table_viewed
     */
    public static function create_from_assign(\assign $assign) {
        $data = array(
            'context' => $assign->get_context(),
            'other' => array(
                'assignid' => $assign->get_instance()->id,
            ),
        );
        self::$preventcreatecall = false;
        /** @var grading_table_viewed $event */
        $event = self::create($data);
        self::$preventcreatecall = true;
67
        $event->set_assign($assign);
68
69
70
        return $event;
    }

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    /**
     * Init method.
     */
    protected function init() {
        $this->data['crud'] = 'r';
        $this->data['edulevel'] = self::LEVEL_TEACHING;
    }

    /**
     * Returns localised general event name.
     *
     * @return string
     */
    public static function get_name() {
        return get_string('eventgradingtableviewed', 'mod_assign');
    }

    /**
     * Returns description of what happened.
     *
     * @return string
     */
    public function get_description() {
94
        return "The user with id '$this->userid' viewed the grading table for the assignment with course module " .
95
            "id '$this->contextinstanceid'.";
96
97
    }

98
99
100
101
102
103
104
105
106
107
108
    /**
     * Return legacy data for add_to_log().
     *
     * @return array
     */
    protected function get_legacy_logdata() {
        $logmessage = get_string('viewsubmissiongradingtable', 'assign');
        $this->set_legacy_logdata('view submission grading table', $logmessage);
        return parent::get_legacy_logdata();
    }

109
110
111
112
    /**
     * Custom validation.
     *
     * @throws \coding_exception
113
     * @return void
114
115
     */
    protected function validate_data() {
116
117
118
119
        if (self::$preventcreatecall) {
            throw new \coding_exception('cannot call grading_table_viewed::create() directly, use grading_table_viewed::create_from_assign() instead.');
        }

120
121
122
        parent::validate_data();

        if (!isset($this->other['assignid'])) {
123
            throw new \coding_exception('The \'assignid\' value must be set in other.');
124
125
        }
    }
126
127
128
129
130
131
132

    public static function get_other_mapping() {
        $othermapped = array();
        $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');

        return $othermapped;
    }
133
}