Completed
Push — master ( 1d1df5...87b1fe )
by Jesus
07:01
created

base::validate_data()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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_bigbluebuttonbn abstract base event.
19
  *
20
  * @package   mod_bigbluebuttonbn
21
  * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
22
  * @copyright 2017 - present, Blindside Networks Inc
23
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
  */
25
26
namespace mod_bigbluebuttonbn\event;
27
28
defined('MOODLE_INTERNAL') || die();
29
30
/**
31
 * The mod_bigbluebuttonbn abstract base event class.
32
 *
33
 * Most mod_assign events can extend this class.
34
 *
35
 * @package   mod_bigbluebuttonbn
36
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
37
 * @copyright 2017 - present, Blindside Networks Inc
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
abstract class base extends \core\event\base {
41
42
    /** @var \bigbluebuttonbn */
43
    protected $bigbluebuttonbn;
44
45
    /**
46
     * Description.
47
     *
48
     * @var string
49
     */
50
    protected $description;
51
52
    /**
53
     * Object Id Mapping.
54
     *
55
     * @var array
56
     */
57
    protected static $objectidmapping = array('db' => 'bigbluebuttonbn', 'restore' => 'bigbluebuttonbn');
58
59
    /**
60
     * Legacy log data.
61
     *
62
     * @var array
63
     */
64
    protected $legacylogdata;
65
  
66
    /**
67
     * Init method.
68
     */
69
    protected function init() {
70
        $this->data['crud'] = 'r';
71
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
72
        $this->data['objecttable'] = 'bigbluebuttonbn';
73
    }
74
75
    /**
76
     * Returns description of what happened.
77
     *
78
     * @return string
79
     */
80
    public function get_description() {
81
        return $this->description;
82
    }
83
84
    /**
85
     * Returns relevant URL.
86
     *
87
     * @return \moodle_url
88
     */
89
    public function get_url() {
90
        return new \moodle_url('/mod/bigbluebuttonbn/view.php', array('id' => $this->contextinstanceid));
91
    }
92
93
    /**
94
     * Sets the legacy event log data.
95
     *
96
     * @param string $action The current action
97
     * @param string $info A detailed description of the change. But no more than 255 characters.
98
     * @param string $url The url to the assign module instance.
99
     */
100
    public function set_legacy_logdata($action = '', $info = '', $url = '') {
101
        $fullurl = 'view.php?id=' . $this->contextinstanceid;
102
        if ($url != '') {
103
            $fullurl .= '&' . $url;
104
        }
105
106
        $this->legacylogdata = array($this->courseid, 'bigbluebuttonbn', $action, $fullurl, $info, $this->contextinstanceid);
107
    }
108
109
    /**
110
     * Return legacy data for add_to_log().
111
     *
112
     * @return array
113
     */
114
    protected function get_legacy_logdata() {
115
        if (isset($this->legacylogdata)) {
116
            return $this->legacylogdata;
117
        }
118
119
        return null;
120
    }
121
122
    /**
123
     * Custom validation.
124
     *
125
     * @throws \coding_exception
126
     */
127
    protected function validate_data() {
128
        parent::validate_data();
129
130
        if ($this->contextlevel != CONTEXT_MODULE) {
131
            throw new \coding_exception('Context level must be CONTEXT_MODULE.');
132
        }
133
    }
134
}
135