Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: move zoom_get_user_display_name function from view.php to locallib #584

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on: [push, pull_request]
jobs:
test:
runs-on: 'ubuntu-latest'

services:
postgres:
image: postgres:13
Expand All @@ -31,7 +32,7 @@ jobs:
matrix:
include:
- php: '8.2'
moodle-branch: 'master'
moodle-branch: 'main'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
Expand All @@ -54,7 +55,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -64,7 +65,8 @@ jobs:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# none to use phpdbg fallback. Specify pcov (Moodle 3.10 and up) or xdebug to use them instead.
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
coverage: none

- name: Initialise moodle-plugin-ci
Expand Down Expand Up @@ -92,16 +94,13 @@ jobs:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
MUSTACHE_IGNORE_NAMES: 'mobile_view_page_latest.mustache,mobile_view_page_ionic3.mustache'
# Uncomment this to run Behat tests using the Moodle App.
# MOODLE_APP: 'true'

- name: PHP Lint
if: ${{ !cancelled() && steps.install_ci.outcome == 'success' }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ !cancelled() && steps.install_ci.outcome == 'success' }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ !cancelled() && steps.install_ci.outcome == 'success' }}
Expand Down Expand Up @@ -142,9 +141,19 @@ jobs:
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
id: behat
if: ${{ !cancelled() && steps.install_ci.outcome == 'success' }}
run: moodle-plugin-ci behat --profile chrome

- name: Upload Behat Faildump
if: ${{ failure() && steps.behat.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: Behat Faildump (${{ join(matrix.*, ', ') }})
path: ${{ github.workspace }}/moodledata/behat_dump
retention-days: 7
if-no-files-found: ignore

- name: Make sure cancelled jobs are marked as failures.
if: ${{ cancelled() }}
run: exit 1
4 changes: 2 additions & 2 deletions classes/invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function __construct($invitation) {
*
* @param int $coursemoduleid Course module where the user will view the invitation.
* @param int|null $userid Optionally supply the intended user to view the string. Defaults to global $USER.
* @return string|null
* @return ?string
*/
public function get_display_string(int $coursemoduleid, int $userid = null) {
public function get_display_string(int $coursemoduleid, ?int $userid = null) {
if (empty($this->invitation)) {
return null;
}
Expand Down
176 changes: 88 additions & 88 deletions lang/en/zoom.php

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ function zoom_supports($feature) {
* will create a new instance and return the id number of the new instance.
*
* @param stdClass $zoom Submitted data from the form in mod_form.php
* @param mod_zoom_mod_form $mform The form instance (included because the function is used as a callback)
* @param mod_zoom_mod_form|null $mform The form instance (included because the function is used as a callback)
* @return int The id of the newly inserted zoom record
*/
function zoom_add_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
function zoom_add_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

Expand Down Expand Up @@ -143,10 +143,10 @@ function zoom_add_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
* will update an existing instance with new data.
*
* @param stdClass $zoom An object from the form in mod_form.php
* @param mod_zoom_mod_form $mform The form instance (included because the function is used as a callback)
* @param mod_zoom_mod_form|null $mform The form instance (included because the function is used as a callback)
* @return boolean Success/Failure
*/
function zoom_update_instance(stdClass $zoom, mod_zoom_mod_form $mform = null) {
function zoom_update_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

Expand Down Expand Up @@ -586,10 +586,10 @@ function zoom_get_monthweek_options() {
* Populate the calendar event object, based on the zoom instance
*
* @param stdClass $zoom The zoom instance.
* @param stdClass $occurrence The occurrence object passed from the zoom api.
* @param stdClass|null $occurrence The occurrence object passed from the zoom api.
* @return stdClass The calendar event object.
*/
function zoom_populate_calender_item(stdClass $zoom, stdClass $occurrence = null) {
function zoom_populate_calender_item(stdClass $zoom, ?stdClass $occurrence = null) {
$event = new stdClass();
$event->type = CALENDAR_EVENT_TYPE_ACTION;
$event->modulename = 'zoom';
Expand Down Expand Up @@ -873,7 +873,7 @@ function zoom_reset_userdata($data) {
*
* @param object $mform the course reset form that is being built.
*/
function zoom_reset_course_form_definition(&$mform) {
function zoom_reset_course_form_definition($mform) {
$mform->addElement('header', 'zoomheader', get_string('modulenameplural', 'zoom'));

$mform->addElement('checkbox', 'reset_zoom_all', get_string('resetzoomsall', 'zoom'));
Expand Down Expand Up @@ -973,9 +973,9 @@ function zoom_extend_navigation(navigation_node $navref, stdClass $course, stdCl
* so it is safe to rely on the $PAGE.
*
* @param settings_navigation $settingsnav complete settings navigation tree
* @param navigation_node $zoomnode zoom administration node
* @param navigation_node|null $zoomnode zoom administration node
*/
function zoom_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $zoomnode = null) {
function zoom_extend_settings_navigation(settings_navigation $settingsnav, ?navigation_node $zoomnode = null) {
}

/**
Expand Down
26 changes: 26 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1314,3 +1314,29 @@ function zoom_get_registrant_join_url($useremail, $meetingid, $iswebinar) {

return false;
}

/**
* Get the display name for a Zoom user.
* This is wrapped in a function to avoid unnecessary API calls.
*
* @param string $zoomuserid Zoom user ID.
* @return ?string
*/
function zoom_get_user_display_name($zoomuserid) {
try {
$hostuser = zoom_get_user($zoomuserid);

// Compose Moodle user object for host.
$hostmoodleuser = new stdClass();
$hostmoodleuser->firstname = $hostuser->first_name;
$hostmoodleuser->lastname = $hostuser->last_name;
$hostmoodleuser->alternatename = '';
$hostmoodleuser->firstnamephonetic = '';
$hostmoodleuser->lastnamephonetic = '';
$hostmoodleuser->middlename = '';

return fullname($hostmoodleuser);
} catch (moodle_exception $error) {
return null;
}
}
8 changes: 6 additions & 2 deletions participants.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @copyright 2015 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
require_once(__DIR__ . '/locallib.php');
Expand Down Expand Up @@ -166,8 +167,11 @@
'export' => 'xls',
]);
$xlsstring = get_string('application/vnd.ms-excel', 'mimetypes');
$xlsicon = html_writer::img($OUTPUT->image_url('f/spreadsheet'), $xlsstring,
['title' => $xlsstring, 'class' => 'mimetypeicon']);
$xlsicon = html_writer::img(
$OUTPUT->image_url('f/spreadsheet'),
$xlsstring,
['title' => $xlsstring, 'class' => 'mimetypeicon']
);
echo get_string('export', 'mod_zoom') . ': ' . html_writer::link($exporturl, $xlsicon);

echo $OUTPUT->footer();
Expand Down
1 change: 1 addition & 0 deletions recreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @copyright 2017 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
require_once(__DIR__ . '/locallib.php');
Expand Down
1 change: 1 addition & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @copyright 2015 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
require_once(__DIR__ . '/locallib.php');
Expand Down
4 changes: 2 additions & 2 deletions tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class mod_zoom_generator extends testing_module_generator {
/**
* Creates new Zoom module instance.
* @param array|stdClass $record
* @param array $options
* @param array|null $options
* @return stdClass Zoom instance
*/
public function create_instance($record = null, array $options = null) {
public function create_instance($record = null, ?array $options = null) {
global $CFG;
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

Expand Down
12 changes: 6 additions & 6 deletions tests/mod_zoom_webservice_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function setUp(): void {
set_config('clientsecret', 'test', 'zoom');
set_config('accountid', 'test', 'zoom');

// @codingStandardsIgnoreStart
$this->notfoundmockcurl = new class {
// @codingStandardsIgnoreStart
/**
* Stub for curl setHeader().
* @param string $unusedparam
Expand Down Expand Up @@ -169,8 +169,8 @@ public function test_user_not_found_exception(): void {
* Tests whether invalid user errors are parsed properly
*/
public function test_invalid_user_exception(): void {
// @codingStandardsIgnoreStart
$invalidmockcurl = new class {
// @codingStandardsIgnoreStart
/**
* Stub for curl setHeader().
* @param string $unusedparam
Expand Down Expand Up @@ -230,9 +230,9 @@ public function get_info() {
* is in the curl response to specify the time that the retry should be sent.
*/
public function test_retry_with_header(): void {
// @codingStandardsIgnoreStart
$retrywithheadermockcurl = new class {
public $numgetinfocalls = 0;
// @codingStandardsIgnoreStart
/**
* Stub for curl setHeader().
* @param string $unusedparam
Expand Down Expand Up @@ -309,9 +309,9 @@ public function getResponse() {
* header is not sent in the curl response.
*/
public function test_retry_without_header(): void {
// @codingStandardsIgnoreStart
$retrynoheadermockcurl = new class {
public $numgetinfocalls = 0;
// @codingStandardsIgnoreStart
/**
* Stub for curl setHeader().
* @param string $unusedparam
Expand Down Expand Up @@ -377,9 +377,9 @@ public function getResponse() {
* Tests that we throw error if we tried more than max retries.
*/
public function test_retry_exception(): void {
// @codingStandardsIgnoreStart
$retryfailuremockcurl = new class {
public $urlpath = null;
// @codingStandardsIgnoreStart
/**
* Stub for curl setHeader().
* @param string $unusedparam
Expand Down Expand Up @@ -464,9 +464,9 @@ public function getResponse() {
* Tests that we are waiting 1 minute for QPS rate limit types.
*/
public function test_retryqps_exception(): void {
// @codingStandardsIgnoreStart
$retryqpsmockcurl = new class {
public $urlpath = null;
// @codingStandardsIgnoreStart
/**
* Stub for curl setHeader().
* @param string $unusedparam
Expand Down
28 changes: 1 addition & 27 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @copyright 2015 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
require_once(__DIR__ . '/locallib.php');
Expand Down Expand Up @@ -90,33 +91,6 @@
}
}

/**
* Get the display name for a Zoom user.
* This is wrapped in a function to avoid unnecessary API calls.
*
* @package mod_zoom
* @param string $zoomuserid Zoom user ID.
* @return ?string
*/
function zoom_get_user_display_name($zoomuserid) {
try {
$hostuser = zoom_get_user($zoomuserid);

// Compose Moodle user object for host.
$hostmoodleuser = new stdClass();
$hostmoodleuser->firstname = $hostuser->first_name;
$hostmoodleuser->lastname = $hostuser->last_name;
$hostmoodleuser->alternatename = '';
$hostmoodleuser->firstnamephonetic = '';
$hostmoodleuser->lastnamephonetic = '';
$hostmoodleuser->middlename = '';

return fullname($hostmoodleuser);
} catch (moodle_exception $error) {
return null;
}
}

$isrecurringnotime = ($zoom->recurring && $zoom->recurrence_type == ZOOM_RECURRINGTYPE_NOTIME);

$stryes = get_string('yes');
Expand Down