Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 marker 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
 * The mod_assign marker updated event class.
31
 *
32
 * @property-read array $other {
33
 *      Extra information about event.
34
 *
35
 *      - int markerid: user id of marker.
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 marker_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 \stdClass $marker
58
     * @return marker_updated
59
     */
60
    public static function create_from_marker(\assign $assign, \stdClass $user, \stdClass $marker) {
61
        $data = array(
62
            'context' => $assign->get_context(),
63
            'objectid' => $assign->get_instance()->id,
64
            'relateduserid' => $user->id,
65
            'other' => array(
66
                'markerid' => $marker->id,
67
            ),
68
        );
69
        self::$preventcreatecall = false;
70
        /** @var marker_updated $event */
71
        $event = self::create($data);
72
        self::$preventcreatecall = true;
73
        $event->set_assign($assign);
74
        $event->add_record_snapshot('user', $user);
75
        $event->add_record_snapshot('user', $marker);
76
        return $event;
77
    }
78
 
79
    /**
80
     * Returns description of what happened.
81
     *
82
     * @return string
83
     */
84
    public function get_description() {
85
        return "The user with id '$this->userid' has set the marker for the user with id '$this->relateduserid' to " .
86
            "'{$this->other['markerid']}' for the assignment with course module id '$this->contextinstanceid'.";
87
    }
88
 
89
    /**
90
     * Return localised event name.
91
     *
92
     * @return string
93
     */
94
    public static function get_name() {
95
        return get_string('eventmarkerupdated', 'mod_assign');
96
    }
97
 
98
    /**
99
     * Init method.
100
     *
101
     * @return void
102
     */
103
    protected function init() {
104
        $this->data['crud'] = 'u';
105
        $this->data['edulevel'] = self::LEVEL_TEACHING;
106
        $this->data['objecttable'] = 'assign';
107
    }
108
 
109
    /**
110
     * Custom validation.
111
     *
112
     * @throws \coding_exception
113
     */
114
    protected function validate_data() {
115
        if (self::$preventcreatecall) {
116
            throw new \coding_exception('cannot call marker_updated::create() directly, use marker_updated::create_from_marker() instead.');
117
        }
118
 
119
        parent::validate_data();
120
 
121
        if (!isset($this->relateduserid)) {
122
            throw new \coding_exception('The \'relateduserid\' must be set.');
123
        }
124
 
125
        if (!isset($this->other['markerid'])) {
126
            throw new \coding_exception('The \'markerid\' value must be set in other.');
127
        }
128
    }
129
 
130
    public static function get_objectid_mapping() {
131
        return array('db' => 'assign', 'restore' => 'assign');
132
    }
133
 
134
    public static function get_other_mapping() {
135
        $othermapped = array();
136
        $othermapped['markerid'] = array('db' => 'user', 'restore' => 'user');
137
 
138
        return $othermapped;
139
    }
140
}