Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
namespace mod_bigbluebuttonbn\local\helpers;
18
 
19
use calendar_event;
20
use mod_bigbluebuttonbn\instance;
21
use mod_bigbluebuttonbn\logger;
22
use mod_bigbluebuttonbn\plugin;
23
use stdClass;
24
 
25
/**
26
 * Utility class for all instance (module) routines helper.
27
 *
28
 * @package   mod_bigbluebuttonbn
29
 * @copyright 2021 onwards, Blindside Networks Inc
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @author    Laurent David  (laurent [at] call-learning [dt] fr)
32
 */
33
class mod_helper {
34
 
35
    /**
36
     * Runs any processes that must run before a bigbluebuttonbn insert/update.
37
     *
38
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
39
     **/
40
    public static function process_pre_save(stdClass $bigbluebuttonbn) {
41
        self::process_pre_save_instance($bigbluebuttonbn);
42
        self::process_pre_save_checkboxes($bigbluebuttonbn);
43
        self::process_pre_save_common($bigbluebuttonbn);
44
        $bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants, ENT_COMPAT);
1441 ariadna 45
        // Conditionally force grade type to none if the activity is recording only.
46
        if ($bigbluebuttonbn->type == instance::TYPE_RECORDING_ONLY) {
47
            $bigbluebuttonbn->grade = GRADE_TYPE_NONE;
48
        }
1 efrain 49
    }
50
 
51
    /**
52
     * Runs process for defining the instance (insert/update).
53
     *
54
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
55
     **/
56
    protected static function process_pre_save_instance(stdClass $bigbluebuttonbn): void {
57
        $bigbluebuttonbn->timemodified = time();
58
        if ((integer) $bigbluebuttonbn->instance == 0) {
59
            $bigbluebuttonbn->meetingid = 0;
60
            $bigbluebuttonbn->timecreated = time();
61
            $bigbluebuttonbn->timemodified = 0;
62
            // As it is a new activity, assign passwords.
63
            $bigbluebuttonbn->moderatorpass = plugin::random_password(12);
64
            $bigbluebuttonbn->viewerpass = plugin::random_password(12, $bigbluebuttonbn->moderatorpass);
65
        }
66
    }
67
 
68
    /**
69
     * Runs process for assigning default value to checkboxes.
70
     *
71
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
72
     **/
73
    protected static function process_pre_save_checkboxes($bigbluebuttonbn) {
74
        if (!isset($bigbluebuttonbn->wait)) {
75
            $bigbluebuttonbn->wait = 0;
76
        }
77
        if (!isset($bigbluebuttonbn->record)) {
78
            $bigbluebuttonbn->record = 0;
79
        }
80
        if (!isset($bigbluebuttonbn->recordallfromstart)) {
81
            $bigbluebuttonbn->recordallfromstart = 0;
82
        }
83
        if (!isset($bigbluebuttonbn->recordhidebutton)) {
84
            $bigbluebuttonbn->recordhidebutton = 0;
85
        }
86
        if (!isset($bigbluebuttonbn->recordings_html)) {
87
            $bigbluebuttonbn->recordings_html = 0;
88
        }
89
        if (!isset($bigbluebuttonbn->recordings_deleted)) {
90
            $bigbluebuttonbn->recordings_deleted = 0;
91
        }
92
        if (!isset($bigbluebuttonbn->recordings_imported)) {
93
            $bigbluebuttonbn->recordings_imported = 0;
94
        }
95
        if (!isset($bigbluebuttonbn->recordings_preview)) {
96
            $bigbluebuttonbn->recordings_preview = 0;
97
        }
98
        if (!isset($bigbluebuttonbn->muteonstart)) {
99
            $bigbluebuttonbn->muteonstart = 0;
100
        }
101
        if (!isset($bigbluebuttonbn->disablecam)) {
102
            $bigbluebuttonbn->disablecam = 0;
103
        }
104
        if (!isset($bigbluebuttonbn->disablemic)) {
105
            $bigbluebuttonbn->disablemic = 0;
106
        }
107
        if (!isset($bigbluebuttonbn->disableprivatechat)) {
108
            $bigbluebuttonbn->disableprivatechat = 0;
109
        }
110
        if (!isset($bigbluebuttonbn->disablepublicchat)) {
111
            $bigbluebuttonbn->disablepublicchat = 0;
112
        }
113
        if (!isset($bigbluebuttonbn->disablenote)) {
114
            $bigbluebuttonbn->disablenote = 0;
115
        }
116
        if (!isset($bigbluebuttonbn->hideuserlist)) {
117
            $bigbluebuttonbn->hideuserlist = 0;
118
        }
119
    }
120
 
121
    /**
122
     * Runs process for wipping common settings when 'recordings only'.
123
     *
124
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
125
     **/
126
    protected static function process_pre_save_common(stdClass $bigbluebuttonbn): void {
127
        // Make sure common settings are removed when 'recordings only'.
128
        if ($bigbluebuttonbn->type == instance::TYPE_RECORDING_ONLY) {
129
            $bigbluebuttonbn->groupmode = 0;
130
            $bigbluebuttonbn->groupingid = 0;
131
        }
132
    }
133
 
134
    /**
135
     * Runs any processes that must be run after a bigbluebuttonbn insert/update.
136
     *
137
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
138
     **/
139
    public static function process_post_save(stdClass $bigbluebuttonbn): void {
140
        self::process_post_save_event($bigbluebuttonbn);
141
        self::process_post_save_completion($bigbluebuttonbn);
142
    }
143
 
144
    /**
145
     * Generates an event after a bigbluebuttonbn insert/update.
146
     *
147
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
148
     **/
149
    protected static function process_post_save_event(stdClass $bigbluebuttonbn): void {
150
        global $CFG, $DB;
151
 
152
        require_once($CFG->dirroot . '/calendar/lib.php');
153
        $eventid = $DB->get_field('event', 'id', [
154
            'modulename' => 'bigbluebuttonbn',
155
            'instance' => $bigbluebuttonbn->id,
156
            'eventtype' => logger::EVENT_MEETING_START
157
        ]);
158
 
159
        // Delete the event from calendar when/if openingtime is NOT set.
160
        if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) {
161
            if ($eventid) {
162
                $calendarevent = calendar_event::load($eventid);
163
                $calendarevent->delete();
164
            }
165
            return;
166
        }
167
 
168
        // Add event to the calendar as openingtime is set.
169
        $event = (object) [
170
            'eventtype' => logger::EVENT_MEETING_START,
171
            'type' => CALENDAR_EVENT_TYPE_ACTION,
172
            'name' => get_string('calendarstarts', 'bigbluebuttonbn', $bigbluebuttonbn->name),
173
            'description' => format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $bigbluebuttonbn->coursemodule, false),
174
            'format' => FORMAT_HTML,
175
            'courseid' => $bigbluebuttonbn->course,
176
            'groupid' => 0,
177
            'userid' => 0,
178
            'modulename' => 'bigbluebuttonbn',
179
            'instance' => $bigbluebuttonbn->id,
180
            'timestart' => $bigbluebuttonbn->openingtime,
181
            'timeduration' => 0,
182
            'timesort' => $bigbluebuttonbn->openingtime,
183
            'visible' => instance_is_visible('bigbluebuttonbn', $bigbluebuttonbn),
184
            'priority' => null,
185
        ];
186
 
187
        // Update the event in calendar when/if eventid was found.
188
        if ($eventid) {
189
            $event->id = $eventid;
190
            $calendarevent = calendar_event::load($eventid);
191
            $calendarevent->update($event);
192
            return;
193
        }
194
        calendar_event::create($event);
195
    }
196
 
197
    /**
198
     * Generates an event after a bigbluebuttonbn activity is completed.
199
     *
200
     * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
201
     **/
202
    protected static function process_post_save_completion(stdClass $bigbluebuttonbn): void {
203
        if (empty($bigbluebuttonbn->completionexpected)) {
204
            return;
205
        }
206
        \core_completion\api::update_completion_date_event(
207
            $bigbluebuttonbn->coursemodule,
208
            'bigbluebuttonbn',
209
            $bigbluebuttonbn->id,
210
            $bigbluebuttonbn->completionexpected
211
        );
212
    }
213
}