Skip to content

Commit

Permalink
phpcs: small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchamp committed Sep 30, 2023
1 parent 2ec0e5b commit e232bba
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 47 deletions.
22 changes: 11 additions & 11 deletions classes/task/get_meeting_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ public function format_participant($participant, $detailsid, $names, $emails) {
}
}

if ($participant->user_email == '') {
if ($participant->user_email === '') {
if (!empty($moodleuserid)) {
$participant->user_email = $DB->get_field('user', 'email', ['id' => $moodleuserid]);
} else {
$participant->user_email = null;
}
}

if ($participant->id == '') {
if ($participant->id === '') {
$participant->id = null;
}

Expand Down Expand Up @@ -484,7 +484,7 @@ public function debugmsg($msg) {
* @return boolean
*/
public function process_meeting_reports($meeting) {
global $DB, $CFG;
global $DB;

$this->debugmsg(sprintf(
'Processing meeting %s|%s that occurred at %s',
Expand Down Expand Up @@ -558,7 +558,7 @@ public function process_meeting_reports($meeting) {
'detailsid' => $participant['detailsid'],
'zoomuserid' => $participant['zoomuserid'],
'join_time' => $participant['join_time'],
'leave_time' => $participant['leave_time']
'leave_time' => $participant['leave_time'],
];

// Check if the record already exists.
Expand Down Expand Up @@ -648,7 +648,7 @@ public function grading_participant_upon_duration($zoomrecord, $detailsid) {

// Check if there is old duration stored for this user.
if (!empty($durations[$userid])) {
$old = new \stdClass;
$old = new \stdClass();
$old->duration = $durations[$userid];
$old->join_time = $join[$userid];
$old->leave_time = $leave[$userid];
Expand Down Expand Up @@ -725,7 +725,6 @@ public function grading_participant_upon_duration($zoomrecord, $detailsid) {
} else {
$notenrolled[$userid] = fullname(\core_user::get_user($userid));
}

} else {
// This means that this user was not identified.
// Provide information about participants that need to be graded manually.
Expand Down Expand Up @@ -825,7 +824,7 @@ public function notify_teachers($data) {
$needgradenumber = count($data['needgrade']);
// List of users need grading.
$needstring = get_string('grading_needgrade', 'mod_zoom');
$needgrade = (!empty($data['needgrade'])) ? $needstring.implode('<br>', $data['needgrade'])."\n" : '';
$needgrade = (!empty($data['needgrade'])) ? $needstring . implode('<br>', $data['needgrade']) . "\n" : '';

$zoomid = $data['zoomid'];
$itemid = $data['itemid'];
Expand Down Expand Up @@ -903,7 +902,7 @@ public function notify_teachers($data) {
$message->contexturl = $gurl; // This link redirect the teacher to the page of item's grades.
$message->contexturlname = get_string('gradinglink', 'mod_zoom');
// Email content.
$content = array('*' => array('header' => $message->subject, 'footer' => ''));
$content = ['*' => ['header' => $message->subject, 'footer' => '']];
$message->set_additional_content('email', $content);
$messageids = [];
if (!empty($teachers)) {
Expand Down Expand Up @@ -995,9 +994,10 @@ public function get_users_clicked_join($zoomrecord) {

$userids = [];
foreach ($events as $event) {
if ($event->other['meetingid'] == $zoomrecord->meeting_id &&
!in_array($event->userid, $userids)) {

if (
$event->other['meetingid'] === $zoomrecord->meeting_id &&
!in_array($event->userid, $userids, true)
) {
$userids[] = $event->userid;
}
}
Expand Down
26 changes: 19 additions & 7 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,13 @@
'idfullname' => get_string('displayidfullname', 'mod_zoom'),
'id' => get_string('displayid', 'mod_zoom'),
];
$settings->add(new admin_setting_configselect('zoom/unamedisplay', get_string('unamedisplay', 'mod_zoom'),
get_string('unamedisplay_help', 'mod_zoom'), 'fullname', $options));
$settings->add(new admin_setting_configselect(
'zoom/unamedisplay',
get_string('unamedisplay', 'mod_zoom'),
get_string('unamedisplay_help', 'mod_zoom'),
'fullname',
$options
));

// Supplementary features settings.
$settings->add(new admin_setting_heading(
Expand Down Expand Up @@ -627,16 +632,23 @@
}

// Adding options for grading methods.
$settings->add(new admin_setting_heading('zoom/gradingmethod',
get_string('gradingmethod_heading', 'mod_zoom'),
get_string('gradingmethod_heading_help', 'mod_zoom')));
$settings->add(new admin_setting_heading(
'zoom/gradingmethod',
get_string('gradingmethod_heading', 'mod_zoom'),
get_string('gradingmethod_heading_help', 'mod_zoom')
));

// Grading method upon entry: the user gets the full score when clicking to join the session through Moodle.
// Grading method upon period: the user is graded based on how long they attended the actual session.
$options = [
'entry' => get_string('gradingentry', 'mod_zoom'),
'period' => get_string('gradingperiod', 'mod_zoom'),
];
$settings->add(new admin_setting_configselect('zoom/gradingmethod', get_string('gradingmethod', 'mod_zoom'),
get_string('gradingmethod_help', 'mod_zoom'), 'entry', $options));
$settings->add(new admin_setting_configselect(
'zoom/gradingmethod',
get_string('gradingmethod', 'mod_zoom'),
get_string('gradingmethod_help', 'mod_zoom'),
'entry',
$options
));
}
60 changes: 31 additions & 29 deletions tests/get_meeting_reports_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public function test_grading_method() {
$context = \context_course::instance($course->id);
$graders = get_users_by_capability($context, 'moodle/grade:edit');
$this->assertEquals(1, count($graders));
$firstkey = array_key_first($graders);
$firstkey = key($graders);
$this->assertEquals($graders[$firstkey]->id, $teacher->id);
// Now fake the meeting details.
$meeting = new stdClass();
Expand All @@ -444,14 +444,14 @@ public function test_grading_method() {

// Create a new zoom instance.
$params = [
'course' => $course->id,
'meeting_id' => $meeting->id,
'grade' => 60,
'name' => 'Zoom',
'exists_on_zoom' => ZOOM_MEETING_EXISTS,
'start_time' => strtotime('2020-04-01T15:00:00Z'),
'duration' => 120 * 60, // In seconds.
];
'course' => $course->id,
'meeting_id' => $meeting->id,
'grade' => 60,
'name' => 'Zoom',
'exists_on_zoom' => ZOOM_MEETING_EXISTS,
'start_time' => strtotime('2020-04-01T15:00:00Z'),
'duration' => 120 * 60, // In seconds.
];

$generator = $this->getDataGenerator()->get_plugin_generator('mod_zoom');
$instance = $generator->create_instance($params);
Expand Down Expand Up @@ -494,7 +494,7 @@ public function test_grading_method() {
foreach ($users as $user) {
$this->getDataGenerator()->enrol_user($user->id, $course->id);
}
list($names, $emails) = $this->meetingtask->get_enrollments($course->id);
[$names, $emails] = $this->meetingtask->get_enrollments($course->id);

// Create a participant with 5 min overlap.
// Total time 35 min, total grade 17.5 .
Expand All @@ -505,7 +505,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:05:00Z',
'leave_time' => '2023-05-01T15:35:00Z',
'duration' => 30 * 60
'duration' => 30 * 60,
];
$participants[1] = (object)$this->meetingtask->format_participant($rawparticipants[1], $detailsid, $names, $emails);
$rawparticipants[2] = (object)[
Expand All @@ -515,7 +515,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:30:00Z',
'leave_time' => '2023-05-01T15:40:00Z',
'duration' => 10 * 60
'duration' => 10 * 60,
];
$participants[2] = (object)$this->meetingtask->format_participant($rawparticipants[2], $detailsid, $names, $emails);
$overlap = $this->meetingtask->get_participant_overlap_time($participants[1], $participants[2]);
Expand All @@ -533,7 +533,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:00:00Z',
'leave_time' => '2023-05-01T16:00:00Z',
'duration' => 60 * 60
'duration' => 60 * 60,
];
$participants[3] = (object)$this->meetingtask->format_participant($rawparticipants[3], $detailsid, $names, $emails);
$rawparticipants[4] = (object)[
Expand All @@ -543,7 +543,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:30:00Z',
'leave_time' => '2023-05-01T16:00:00Z',
'duration' => 30 * 60
'duration' => 30 * 60,
];
$participants[4] = (object)$this->meetingtask->format_participant($rawparticipants[4], $detailsid, $names, $emails);
$overlap = $this->meetingtask->get_participant_overlap_time($participants[3], $participants[4]);
Expand All @@ -561,7 +561,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:10:00Z',
'leave_time' => '2023-05-01T16:00:00Z',
'duration' => 50 * 60
'duration' => 50 * 60,
];
$participants[5] = (object)$this->meetingtask->format_participant($rawparticipants[5], $detailsid, $names, $emails);
$rawparticipants[6] = (object)[
Expand All @@ -571,7 +571,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T16:30:00Z',
'leave_time' => '2023-05-01T16:40:00Z',
'duration' => 10 * 60
'duration' => 10 * 60,
];
$participants[6] = (object)$this->meetingtask->format_participant($rawparticipants[6], $detailsid, $names, $emails);

Expand All @@ -590,7 +590,7 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:30:00Z',
'leave_time' => '2023-05-01T17:00:00Z',
'duration' => 90 * 60
'duration' => 90 * 60,
];

// Adding a participant at which matching names will fail.
Expand All @@ -602,19 +602,21 @@ public function test_grading_method() {
'user_email' => '',
'join_time' => '2023-05-01T15:10:00Z',
'leave_time' => '2023-05-01T17:00:00Z',
'duration' => 110 * 60
'duration' => 110 * 60,
];
$this->mockparticipantsdata['someuuid123'] = $rawparticipants;
// First mock the webservice object, so we can inject the return values
// for get_meeting_participants.
$mockwwebservice = $this->createMock('\mod_zoom_webservice');
$mockwwebservice = $this->createMock('\mod_zoom\webservice');
$this->meetingtask->service = $mockwwebservice;
// Make get_meeting_participants() return our results array.
$mockwwebservice->method('get_meeting_participants')
->will($this->returnCallback([$this, 'mock_get_meeting_participants']));

$this->assertEquals($this->mockparticipantsdata['someuuid123'],
$mockwwebservice->get_meeting_participants('someuuid123', false));
$this->assertEquals(
$this->mockparticipantsdata['someuuid123'],
$mockwwebservice->get_meeting_participants('someuuid123', false)
);

// Now let's test the grads.
set_config('gradingmethod', 'period', 'zoom');
Expand Down Expand Up @@ -661,13 +663,13 @@ public function test_grading_method() {
// Check the content of the message.
// Grading item url.
$gurl = new \moodle_url(
'/grade/report/singleview/index.php',
[
'id' => $course->id,
'item' => 'grade',
'itemid' => $gradelistitems[0]->id,
]
);
'/grade/report/singleview/index.php',
[
'id' => $course->id,
'item' => 'grade',
'itemid' => $gradelistitems[0]->id,
]
);
$gradeurl = \html_writer::link($gurl, get_string('gradinglink', 'mod_zoom'));

// Zoom instance url.
Expand All @@ -676,7 +678,7 @@ public function test_grading_method() {
// The user need grading.
$needgradestr = get_string('grading_needgrade', 'mod_zoom');
$needgrade[] = '(Name: Farouk, grade: 55)';
$needgrade = $needgradestr.implode('<br>', $needgrade)."\n";
$needgrade = $needgradestr . implode('<br>', $needgrade) . "\n";

$a = (object)[
'name' => $zoomrecord->name,
Expand Down

0 comments on commit e232bba

Please sign in to comment.