Skip to content

Commit

Permalink
bringing in new feature updates for zoom plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
joel1124 committed Apr 8, 2024
1 parent 27e7953 commit bb663d6
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 48 deletions.
33 changes: 29 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function zoom_supports($feature) {
* @return int The id of the newly inserted zoom record
*/
function zoom_add_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
global $CFG, $DB;
global $CFG, $DB, $USER;
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) {
Expand All @@ -93,10 +93,25 @@ function zoom_add_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {

$zoom->course = (int) $zoom->course;

//UOFR HACK Added for assign
/**
* Joel Dapiawen
* March 16, 2024
* Update assign form for host and try other methods to verify the host.
*/
if(isset($zoom->assign)){
$newhost = zoom_webservice()->get_user($zoom->assign);
print_r($newhost->id);

if (!$newhost) {
$zoomuser = zoom_get_user_zoomemail($USER);
// error_log($zoomuser);
// error_log(print_r($zoomuser), 1);
$newhost = zoom_webservice()->get_user($zoomuser->id);

}

//check if hostid matches selected host

if($zoom->host_id != $newhost->id){
$zoom->host_id= $newhost->id;
}
Expand Down Expand Up @@ -157,7 +172,7 @@ function zoom_add_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
* @return boolean Success/Failure
*/
function zoom_update_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
global $CFG, $DB;
global $CFG, $DB, $USER;
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

// The object received from mod_form.php returns instance instead of id for some reason.
Expand Down Expand Up @@ -196,9 +211,19 @@ function zoom_update_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
$zoom->webinar = $updatedzoomrecord->webinar;

$changehost = FALSE;
//Added for assign
/**
* Joel Dapiawen
* March 16, 2024
* Update assign form for host and try other methods to verify the host.
*/
if(isset($zoom->assign)){
$newhost = zoom_webservice()->get_user($zoom->assign);
if (!$newhost) {
$zoomuser = zoom_get_user_zoomemail($USER);
// error_log($zoomuser);
// error_log(print_r($zoomuser), 1);

}
//check if hostid matches selected host
if($zoom->host_id != $newhost->id){
$zoom->host_id= $newhost->id;
Expand Down
44 changes: 32 additions & 12 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ function zoom_get_sessions_for_display($zoomid) {
$sessions = [];
$format = get_string('strftimedatetimeshort', 'langconfig');

// Sort sessions in start_time ascending order.
$instances = $DB->get_records('zoom_meeting_details', ['zoomid' => $zoomid], 'start_time');
$instances = $DB->get_records('zoom_meeting_details', ['zoomid' => $zoomid]);

foreach ($instances as $instance) {
// The meeting uuid, not the participant's uuid.
Expand Down Expand Up @@ -417,25 +416,33 @@ function zoom_get_user_id($required = true) {
return $zoomuserid;
}

function zoom_get_user_zoomemail($user,$service) {
/**
* Joel Dapiawen
* February 18, 2024
* Updated this function to be called again in modform.php to try other methods to login the user.
*/
function zoom_get_user_zoomemail($user) {

$config = get_config('mod_zoom');

$emailchk = explode('@',$user->email);



if (strpos($emailchk[0],'.')===false) {
$zoom_email = strtolower($user->firstname.'.'.$user->lastname.'@'.ZOOM_USER_DOMAIN);

} else {
$zoom_email = strtolower($user->email);
// error_log(print_r($zoom_email));
}

//try user with first.last@ZOOM_USER_DOMAIN
$zoomuser = $service->get_user($zoom_email);

$zoomuser = zoom_webservice()->get_user($zoom_email);
//print_r($zoomuser);
if ($zoomuser === false) {
//try titlcase
$zoom_email = ucfirst($user->firstname).'.'.ucfirst($user->lastname).'@'.ZOOM_USER_DOMAIN;
$zoomuser = $service->get_user($zoom_email);
$zoomuser = zoom_webservice()->get_user($zoom_email);
}

if ($zoomuser === false) {
Expand All @@ -444,11 +451,11 @@ function zoom_get_user_zoomemail($user,$service) {
$alias = zoom_email_alias($user);

//check if alias emails are connected to zoom account
$zoomuser = $service->get_user(strtolower($alias));
$zoomuser = zoom_webservice()->get_user(strtolower($alias));

if ($zoomuser === false) {
//check the actual email field, just in case it works
$zoomuser = $service->get_user(strtolower($user->email));
$zoomuser = zoom_webservice()->get_user(strtolower($user->email));

if ($zoomuser === false) {
return false;
Expand Down Expand Up @@ -552,12 +559,25 @@ function zoom_get_course_instructors($courseid) {
global $DB;

$role = $DB->get_record('role', array('shortname' => 'editingteacher'));
// Get the 'teacher' role
$teacher_role = $DB->get_record('role', array('shortname' => 'teacher'));
// Get the 'teaching assistant' role
$role_ta = $DB->get_record('role', array('shortname' => 'teachingassistant'));


$context = context_course::instance($courseid);
$teachers = get_role_users($role->id, $context);

$teachers = get_role_users($teacher_role->id, $context);
$teacher = get_role_users($role->id, $context);
// Get users with the 'teaching assistant' role
$teachers_ta = get_role_users($role_ta->id, $context);


// Merge the two arrays of teachers
$all_teachers = array_merge($teacher, $teachers, $teachers_ta);
$teachersmenu = array();
if ($teachers) {
foreach ($teachers as $teacher) {
if ( $all_teachers) {
foreach ( $all_teachers as $teacher) {
$teacherarray=new stdClass;
$teacherarray->email = $teacher->email;
$teacherarray->name = fullname($teacher);
Expand Down
140 changes: 108 additions & 32 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,31 @@ public function definition() {
$PAGE->requires->js_call_amd("mod_zoom/form", 'init');

$isnew = empty($this->_cm);


$zoomuserid = zoom_get_user_id(false);


$zoomuserid = zoom_get_user_id(false);

// If creating a new instance, but the Zoom user does not exist.
if ($isnew && $zoomuserid === false) {
// Assume user is using Zoom for the first time.
$errstring = 'zoomerr_usernotfound';
// After they set up their account, the user should continue to the page they were on.
$nexturl = $PAGE->url;
zoom_fatal_error($errstring, 'mod_zoom', $nexturl, $config->zoomurl);
/**
* Joel Dapiawen
* February 12, 2024
* Try to use other methods to login the user!
*/
$zoomuser = zoom_get_user_zoomemail($USER);
$zoomuser_id = $zoomuser->id;
if ($isnew && $zoomuser !== false) {
$zoomuserid = $zoomuser_id;
}else {

//Assume user is using Zoom for the first time.
$errstring = 'zoomerr_usernotfound';
// After they set up their account, the user should continue to the page they were on.
$nexturl = $PAGE->url;
zoom_fatal_error($errstring, 'mod_zoom', $nexturl, $config->zoomurl);
}

}

// Array of emails and proper names of Moodle users in this course that
Expand All @@ -82,8 +97,17 @@ public function definition() {
if ($zoomuserid !== false) {
// Get the array of users they can schedule.
$canschedule = zoom_webservice()->get_schedule_for_users($zoomuserid);
error_log(print_r($canschedule, 1));
}

//else {
// $zoomuser = zoom_get_user_zoomemail($USER);
// $zoomuser_id = $zoomuser->id;
//$canschedule = zoom_webservice()->get_schedule_for_users($zoomuserid);
// print_r($canschedule);
//error_log(print_r($canschedule, 1));

// }

if (!empty($canschedule)) {
// Add the current user.
$canschedule[$zoomuserid] = new stdClass();
Expand Down Expand Up @@ -174,11 +198,58 @@ public function definition() {
if (has_capability('mod/zoom:assign', $context)) {

$teacherarray = zoom_get_course_instructors($this->_course->id);
/**
* Joel Dapiawen
* February 12, 2024
* If the email format is incorrect, correct it and add it to the dropdown menu
*/
$teachersmenu = array();
foreach ($teacherarray as $teacher) {
// Split the name into first and last name
$name_parts = explode(' ', $teacher->name);
$first_name = strtolower($name_parts[0]);
$last_name = strtolower($name_parts[count($name_parts) - 1]);

// Construct the expected email address format
$expected_email = $first_name . '.' . $last_name . '@uregina.ca';

// Check if the email matches the expected format
if (strtolower($teacher->email) === $expected_email) {
// If the email matches the expected format, add it to the dropdown menu
$teachersmenu[$teacher->email] = $teacher->name;
} else {
// If the email format is incorrect, correct it and add it to the dropdown menu
$corrected_email = $expected_email;
$teachersmenu[$corrected_email] = $teacher->name;
}
}
// error_log(print_r($teacherarray, 1));
// error_log(print_r($teachersmenu, 1));

$select = $mform->addElement('select', 'assign', get_string('assign', 'zoom'), $teachersmenu);
//Dont need to call anything we just want to get the user who is the host of the meeting.
$zoomuser = zoom_webservice()->get_user($this->current->host_id);

if ($zoomuser) {
if (!$isnew) {
$select->setSelected(strtolower($zoomuser->email));
}else {
$select->setSelected(strtolower($zoomuser->email));
}

}

/*
Add an assign instructor field if user has the capbility to do so
$context = context_course::instance($this->_course->id);
if (has_capability('mod/zoom:assign', $context)) {
$teacherarray = zoom_get_course_instructors($this->_course->id);
$teachersmenu = array($USER->email => fullname($USER));
foreach ($teacherarray as $teacher) {
$teachersmenu[$teacher->email] = $teacher->name;
}
foreach ($teacherarray as $teacher) {
$teachersmenu[$teacher->email] = $teacher->name;
}
$select = $mform->addElement('select', 'assign', get_string('assign', 'zoom'), $teachersmenu);
//need to set current host here
if(!$isnew){
Expand All @@ -201,8 +272,10 @@ public function definition() {
// $select->setSelected($zoomuser->email);
}
}
*/
}


//var_dump($this->current->host_id);
// Add title (stored in database as 'name').
$mform->addElement('text', 'name', get_string('title', 'zoom'), ['size' => '64']);
$mform->setType('name', PARAM_TEXT);
Expand Down Expand Up @@ -456,10 +529,7 @@ public function definition() {
// Getting Course participants.
$courseparticipants = [];
foreach ($participants as $participant) {
$courseparticipants[] = [
'participantid' => $participant->id,
'participantname' => fullname($participant) . ' <' . $participant->email . '>',
];
$courseparticipants[] = ['participantid' => $participant->id, 'participantemail' => $participant->email];
}

// Getting Course groups.
Expand Down Expand Up @@ -815,7 +885,7 @@ public function definition() {
get_string('recordingvisibility', 'mod_zoom'),
get_string('yes')
);
$mform->setDefault('recordings_visible_default', 1);
$mform->setDefault('recordings_visible_default', 0);
$mform->addHelpButton('recordings_visible_default', 'recordingvisibility', 'mod_zoom');
}

Expand Down Expand Up @@ -906,11 +976,11 @@ public function data_postprocessing($data) {
global $DB;

parent::data_postprocessing($data);
error_log(print_r($data));

// Get config.
$config = get_config('zoom');

// If the admin did show the alternative hosts user picker.
// If the admin did show the alternative hosts user picker.
if ($config->showalternativehosts == ZOOM_ALTERNATIVEHOSTS_PICKER) {
// If there was at least one alternative host selected, process these users.
if (count($data->alternative_hosts_picker) > 0) {
Expand All @@ -933,7 +1003,9 @@ public function data_postprocessing($data) {

// Get latest list of alternative hosts from the DB.
$result = $DB->get_field('zoom', 'alternative_hosts', ['meeting_id' => $data->meeting_id], IGNORE_MISSING);

print_r($result);
error_log(print_r($config->showalternativehosts));
error_log(print_r($result));
// Proceed only if there is a field of alternative hosts already.
if ($result !== false) {
$alternativehostsdb = zoom_get_alternative_host_array_from_string($result);
Expand Down Expand Up @@ -1184,24 +1256,28 @@ public function validation($data, $files) {

/**
* Joel Dapiawen
* January 8, 2024
* Check host capability
* April 7, 2024
* Need to update this Validate assign field form if user account is found in zoom
*/
if (isset($data['assign'])) {
$useremail = $data['assign'];
if($useremail != $USER->email){
$user = zoom_get_user_info($useremail);
if($user){
error_log($useremail);
// if($useremail != $USER->email){
//$user = zoom_get_user_info($useremail);
// error_log(print_r($user, 1));
// error_log(print_r($teachersmenu, 1));
// if($user){
// we dont need to call class here anymore.
// call the function right away.
$zoomuser = zoom_email_alias($user);
// $zoomuser = zoom_email_alias($user);

if(!$zoomuser){
$errors['assign'] = $useremail.get_string('err_account_invalid', 'mod_zoom');
}
}else
$errors['assign'] = $useremail.get_string('err_account_invalid', 'mod_zoom');
}
// if(!$zoomuser){
// $errors['assign'] = $useremail.get_string('err_account_invalid', 'mod_zoom');
// } else {
// $errors['assign'] = $useremail.get_string('err_account_invalid', 'mod_zoom');
// }
// }
// }
} //END of ADDED
return $errors;
}
Expand Down

0 comments on commit bb663d6

Please sign in to comment.