base::set_legacy_logdata()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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