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 abstract base event.
19
 *
20
 * @package    mod_assign
21
 * @copyright  2014 Mark Nelson
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 abstract base event class.
31
 *
32
 * Most mod_assign events can extend this class.
33
 *
34
 * @package    mod_assign
35
 * @since      Moodle 2.7
36
 * @copyright  2014 Mark Nelson
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
abstract class base extends \core\event\base {
40
 
41
    /** @var \assign */
42
    protected $assign;
43
 
44
    /**
45
     * Legacy log data.
46
     *
47
     * @var array
48
     */
49
    protected $legacylogdata;
50
 
51
    /**
52
     * Set assign instance for this event.
53
     * @param \assign $assign
54
     * @throws \coding_exception
55
     */
56
    public function set_assign(\assign $assign) {
57
        if ($this->is_triggered()) {
58
            throw new \coding_exception('set_assign() must be done before triggerring of event');
59
        }
60
        if ($assign->get_context()->id != $this->get_context()->id) {
61
            throw new \coding_exception('Invalid assign isntance supplied!');
62
        }
63
        if ($assign->is_blind_marking()) {
64
            $this->data['anonymous'] = 1;
65
        }
66
        $this->assign = $assign;
67
    }
68
 
69
    /**
70
     * Get assign instance.
71
     *
72
     * NOTE: to be used from observers only.
73
     *
74
     * @throws \coding_exception
75
     * @return \assign
76
     */
77
    public function get_assign() {
78
        if ($this->is_restored()) {
79
            throw new \coding_exception('get_assign() is intended for event observers only');
80
        }
81
        if (!isset($this->assign)) {
82
            debugging('assign property should be initialised in each event', DEBUG_DEVELOPER);
83
            global $CFG;
84
            require_once($CFG->dirroot . '/mod/assign/locallib.php');
85
            $cm = get_coursemodule_from_id('assign', $this->contextinstanceid, 0, false, MUST_EXIST);
86
            $course = get_course($cm->course);
87
            $this->assign = new \assign($this->get_context(), $cm, $course);
88
        }
89
        return $this->assign;
90
    }
91
 
92
 
93
    /**
94
     * Returns relevant URL.
95
     *
96
     * @return \moodle_url
97
     */
98
    public function get_url() {
99
        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
100
    }
101
 
102
    /**
103
     * Custom validation.
104
     *
105
     * @throws \coding_exception
106
     */
107
    protected function validate_data() {
108
        parent::validate_data();
109
 
110
        if ($this->contextlevel != CONTEXT_MODULE) {
111
            throw new \coding_exception('Context level must be CONTEXT_MODULE.');
112
        }
113
    }
114
}