Skip to content

Commit

Permalink
filter: update cm variables and add filter helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
karenliulll committed Sep 25, 2024
1 parent bdcfec0 commit 96ff33a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ private function database_to_api($zoom, $cmid) {

$data = [
// Process the meeting topic with proper filter.
'topic' => substr(format_string($zoom->name, true, $options + ['escape' => false]), 0, 200),
'topic' => zoom_apply_filter_on_meeting_name($zoom->name, $options),
'settings' => [
'host_video' => (bool) ($zoom->option_host_video),
'audio' => $zoom->option_audio,
Expand Down
23 changes: 19 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function zoom_add_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null) {
$zoom->breakoutrooms = $breakoutrooms['zoom'];
}

$response = zoom_webservice()->create_meeting($zoom, $mform->_cm->id);
$response = zoom_webservice()->create_meeting($zoom, $zoom->coursemodule);
$zoom = populate_zoom_from_response($zoom, $response);
$zoom->timemodified = time();
if (!empty($zoom->schedule_for)) {
Expand Down Expand Up @@ -187,7 +187,7 @@ function zoom_update_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null)

// Update meeting on Zoom.
try {
zoom_webservice()->update_meeting($zoom, $mform->_cm->id);
zoom_webservice()->update_meeting($zoom, $zoom->coursemodule);
if (!empty($zoom->schedule_for)) {
// Only update this if we actually get a valid user.
if ($correcthostzoomuser = zoom_get_user($zoom->schedule_for)) {
Expand Down Expand Up @@ -290,6 +290,8 @@ function populate_zoom_from_response(stdClass $zoom, stdClass $response) {
}

$newzoom->meeting_id = $response->id;
// Need to get the meeting name from API call for comparison in the refresh_events function.
$newzoom->apiresponsename = $response->topic;
if (isset($response->start_time)) {
$newzoom->start_time = strtotime($response->start_time);
}
Expand Down Expand Up @@ -422,8 +424,10 @@ function zoom_refresh_events($courseid, $zoom, $cm) {
$fullzoom = populate_zoom_from_response($zoom, $response);

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

Expand Down Expand Up @@ -1337,3 +1341,14 @@ function zoom_cm_info_dynamic(cm_info $cm) {
}
}
}

/**
* Apply filter(s) on Zoom activity name if applicable.
*
* @param string $name Original name to be processed
* @param array $options Format_string options
* @return string Filtered name
*/
function zoom_apply_filter_on_meeting_name($name, $options) {
return substr(format_string($name, true, $options + ['escape' => false]), 0, 200);
}

0 comments on commit 96ff33a

Please sign in to comment.