Skip to content

Commit 8136026

Browse files
authored
Merge pull request #615 from ncstate-delta/enhancement/moodle-filters-adaption
Add moodle filter adaption to the meeting topic and description
2 parents fab6dd0 + 0ca435c commit 8136026

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

backup/moodle2/restore_zoom_stepslib.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ protected function process_zoom($data) {
6565

6666
// Either create a new meeting or set meeting as expired.
6767
try {
68-
$updateddata = zoom_webservice()->create_meeting($data);
68+
// FIXME: Do we provide course context? That won't have the right activity names etc.
69+
$cmid = null;
70+
$updateddata = zoom_webservice()->create_meeting($data, $cmid);
6971
$data = populate_zoom_from_response($data, $updateddata);
7072
$data->exists_on_zoom = ZOOM_MEETING_EXISTS;
7173
} catch (moodle_exception $e) {

classes/webservice.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
defined('MOODLE_INTERNAL') || die();
2828

29+
require_once($CFG->dirroot . '/mod/zoom/lib.php');
2930
require_once($CFG->dirroot . '/mod/zoom/locallib.php');
3031
require_once($CFG->libdir . '/filelib.php');
3132

@@ -585,20 +586,32 @@ public function get_schedule_for_users($identifier) {
585586
* database fields to the appropriate API request fields.
586587
*
587588
* @param stdClass $zoom The zoom meeting to format.
589+
* @param ?int $cmid The cmid if available.
588590
* @return array The formatted meetings for the meeting.
589591
*/
590-
private function database_to_api($zoom) {
592+
private function database_to_api($zoom, $cmid) {
591593
global $CFG;
592594

595+
$options = [];
596+
if (!empty($cmid)) {
597+
$options['context'] = \context_module::instance($cmid);
598+
}
599+
593600
$data = [
594-
'topic' => $zoom->name,
601+
// Process the meeting topic with proper filter.
602+
'topic' => zoom_apply_filter_on_meeting_name($zoom->name, $options),
595603
'settings' => [
596604
'host_video' => (bool) ($zoom->option_host_video),
597605
'audio' => $zoom->option_audio,
598606
],
599607
];
600608
if (isset($zoom->intro)) {
601-
$data['agenda'] = content_to_text($zoom->intro, FORMAT_MOODLE);
609+
// Process the description text with proper filter and then convert to plain text.
610+
$data['agenda'] = substr(content_to_text(format_text(
611+
$zoom->intro,
612+
FORMAT_MOODLE,
613+
$options
614+
), false), 0, 2000);
602615
}
603616

604617
if (isset($CFG->timezone) && !empty($CFG->timezone)) {
@@ -765,9 +778,10 @@ public function provide_license($zoomuserid) {
765778
* Take a $zoom object as returned from the Moodle form and respond with an object that can be saved to the database.
766779
*
767780
* @param stdClass $zoom The meeting to create.
781+
* @param ?int $cmid The cmid if available.
768782
* @return stdClass The call response.
769783
*/
770-
public function create_meeting($zoom) {
784+
public function create_meeting($zoom, $cmid) {
771785
// Provide license if needed.
772786
$this->provide_license($zoom->host_id);
773787

@@ -776,22 +790,23 @@ public function create_meeting($zoom) {
776790
// Classic: webinar:write:admin.
777791
// Granular: webinar:write:webinar:admin.
778792
$url = "users/$zoom->host_id/" . (!empty($zoom->webinar) ? 'webinars' : 'meetings');
779-
return $this->make_call($url, $this->database_to_api($zoom), 'post');
793+
return $this->make_call($url, $this->database_to_api($zoom, $cmid), 'post');
780794
}
781795

782796
/**
783797
* Update a meeting/webinar on Zoom.
784798
*
785799
* @param stdClass $zoom The meeting to update.
800+
* @param ?int $cmid The cmid if available.
786801
* @return void
787802
*/
788-
public function update_meeting($zoom) {
803+
public function update_meeting($zoom, $cmid) {
789804
// Classic: meeting:write:admin.
790805
// Granular: meeting:update:meeting:admin.
791806
// Classic: webinar:write:admin.
792807
// Granular: webinar:update:webinar:admin.
793808
$url = ($zoom->webinar ? 'webinars/' : 'meetings/') . $zoom->meeting_id;
794-
$this->make_call($url, $this->database_to_api($zoom), 'patch');
809+
$this->make_call($url, $this->database_to_api($zoom, $cmid), 'patch');
795810
}
796811

797812
/**

lib.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function zoom_add_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null) {
9999
$zoom->breakoutrooms = $breakoutrooms['zoom'];
100100
}
101101

102-
$response = zoom_webservice()->create_meeting($zoom);
102+
$response = zoom_webservice()->create_meeting($zoom, $zoom->coursemodule);
103103
$zoom = populate_zoom_from_response($zoom, $response);
104104
$zoom->timemodified = time();
105105
if (!empty($zoom->schedule_for)) {
@@ -187,7 +187,7 @@ function zoom_update_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null)
187187

188188
// Update meeting on Zoom.
189189
try {
190-
zoom_webservice()->update_meeting($zoom);
190+
zoom_webservice()->update_meeting($zoom, $zoom->coursemodule);
191191
if (!empty($zoom->schedule_for)) {
192192
// Only update this if we actually get a valid user.
193193
if ($correcthostzoomuser = zoom_get_user($zoom->schedule_for)) {
@@ -290,7 +290,8 @@ function populate_zoom_from_response(stdClass $zoom, stdClass $response) {
290290
}
291291

292292
$newzoom->meeting_id = $response->id;
293-
$newzoom->name = $response->topic;
293+
// Need to get the meeting name from API call for comparison in the refresh_events function.
294+
$newzoom->apiresponsename = $response->topic;
294295
if (isset($response->start_time)) {
295296
$newzoom->start_time = strtotime($response->start_time);
296297
}
@@ -423,9 +424,11 @@ function zoom_refresh_events($courseid, $zoom, $cm) {
423424
$fullzoom = populate_zoom_from_response($zoom, $response);
424425

425426
// Only if the name has changed, update meeting on Zoom.
426-
if ($zoom->name !== $fullzoom->name) {
427-
$fullzoom->name = $zoom->name;
428-
zoom_webservice()->update_meeting($zoom);
427+
// Before comparing, need to apply filter on the name if applicable.
428+
$options = [];
429+
$options['context'] = \context_module::instance($cm->id);
430+
if (zoom_apply_filter_on_meeting_name($zoom->name, $options) !== $fullzoom->apiresponsename) {
431+
zoom_webservice()->update_meeting($zoom, $cm->id);
429432
}
430433

431434
zoom_calendar_item_update($fullzoom);
@@ -1338,3 +1341,14 @@ function zoom_cm_info_dynamic(cm_info $cm) {
13381341
}
13391342
}
13401343
}
1344+
1345+
/**
1346+
* Apply filter(s) on Zoom activity name if applicable.
1347+
*
1348+
* @param string $name Original name to be processed
1349+
* @param array $options Format_string options
1350+
* @return string Filtered name
1351+
*/
1352+
function zoom_apply_filter_on_meeting_name($name, $options) {
1353+
return substr(format_string($name, true, $options + ['escape' => false]), 0, 200);
1354+
}

recreate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
}
5050

5151
// Set the current zoom table entry to use the new meeting (meeting_id/etc).
52-
$response = zoom_webservice()->create_meeting($zoom);
52+
$response = zoom_webservice()->create_meeting($zoom, $cm->id);
5353
$zoom = populate_zoom_from_response($zoom, $response);
5454
$zoom->exists_on_zoom = ZOOM_MEETING_EXISTS;
5555
$zoom->timemodified = time();

0 commit comments

Comments
 (0)