Skip to content

Commit

Permalink
Implement PR feedback
Browse files Browse the repository at this point in the history
Implement PR feedback
  • Loading branch information
paulandm committed Nov 11, 2024
1 parent 4ac56e6 commit 31ae11c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 48 deletions.
62 changes: 15 additions & 47 deletions classes/task/send_ical_notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

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

require_once($CFG->dirroot.'/calendar/lib.php');
require_once($CFG->libdir.'/bennu/bennu.inc.php');
require_once($CFG->libdir.'/bennu/iCalendar_components.php');
require_once($CFG->dirroot . '/calendar/lib.php');
require_once($CFG->libdir . '/bennu/bennu.inc.php');
require_once($CFG->libdir . '/bennu/iCalendar_components.php');
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

/**
Expand Down Expand Up @@ -202,14 +202,18 @@ private function create_ical_object($zoomevent, $zoom, $user) {

$icalevent = zoom_helper_icalendar_event($zoomevent, $zoomevent->description);

$cm = get_fast_modinfo($zoomevent->courseid, $user->id)->instances['zoom'][$zoomevent->instance];

$zoomurl = new \moodle_url('/mod/zoom/view.php', ['id' => $cm->id]);

if ($zoom->registration == ZOOM_REGISTRATION_OFF) {
$icalevent->add_property('location', $zoom->join_url);
$icalevent->add_property('location', $zoomurl->out(false));
} else {
$registrantjoinurl = zoom_get_registrant_join_url($user->email, $zoom->meeting_id, $zoom->webinar);
if ($registrantjoinurl) {
$icalevent->add_property('location', $registrantjoinurl);
} else {
$icalevent->add_property('location', $zoom->join_url);
$icalevent->add_property('location', $zoomurl->out(false));
}
}

Expand All @@ -234,51 +238,15 @@ private function create_ical_object($zoomevent, $zoom, $user) {
* @return array An array of users.
*/
private function get_users_to_notify($zoomid, $courseid) {
global $DB;
$users = [];

$sql = 'SELECT distinct ue.userid
FROM {zoom} z
JOIN {enrol} e
ON e.courseid = z.course
JOIN {user_enrolments} ue
ON ue.enrolid = e.id
WHERE z.id = :zoom_id';

$zoomparticipantsids = $DB->get_records_sql($sql, ['zoom_id' => $zoomid]);
if ($zoomparticipantsids) {
foreach ($zoomparticipantsids as $zoomparticipantid) {
$users += [$zoomparticipantid->userid => \core_user::get_user($zoomparticipantid->userid)];
}
}
$cm = get_fast_modinfo($courseid)->instances['zoom'][$zoomid];
$users = get_users_by_capability($cm->context, 'mod/zoom:view');

if (count($users) > 0) {
$users = $this->filter_users($zoomid, $courseid, $users);
if (empty($users)) {
return [];
}

return $users;
}

/**
* Filter the zoom users based on availability restrictions.
* @param string $zoomid The zoom instance id.
* @param string $courseid The course id of the course in which the zoom event occurred.
* @param array $users An array of users that potentially has access to the Zoom activity.
* @return array A filtered array of users.
*/
private function filter_users($zoomid, $courseid, $users) {
$modinfo = get_fast_modinfo($courseid);
$coursemodules = $modinfo->get_cms();
if ($coursemodules) {
foreach ($coursemodules as $coursemod) {
if ($coursemod->modname == 'zoom' && $coursemod->instance == $zoomid) {
$availinfo = new \core_availability\info_module($coursemod);
$users = $availinfo->filter_user_list($users);
break;
}
}
}
return $users;
$info = new \core_availability\info_module($cm);
return $info->filter_user_list($users);
}

/**
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<KEYS>
<KEY NAME="id_primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="fk_zoomeventid" TYPE="foreign" FIELDS="zoomeventid" REFTABLE="event" REFFIELDS="id"/>
<KEY NAME="zoomeventid" TYPE="unique" FIELDS="zoomeventid"/>
</KEYS>
</TABLE>
</TABLES>
Expand Down
2 changes: 1 addition & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,13 +1007,13 @@ function xmldb_zoom_upgrade($oldversion) {
$table = new xmldb_table('zoom_ical_notifications');

if (!$dbman->table_exists($table)) {

$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('zoomeventid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('executiontime', XMLDB_TYPE_INTEGER, '12', null, null, null, null);

$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
$table->add_key('fk_zoomeventid', XMLDB_KEY_FOREIGN, ['zoomeventid'], 'event', ['id']);
$table->add_key('unique_zoomeventid', XMLDB_KEY_UNIQUE, ['zoomeventid']);

$dbman->create_table($table);
}
Expand Down

0 comments on commit 31ae11c

Please sign in to comment.