From 246a1c4f4d97eeeec9719045a3f4cfd4a7f238ef Mon Sep 17 00:00:00 2001 From: Lai Wei Date: Fri, 25 Oct 2024 16:44:37 +0100 Subject: [PATCH] Fix Moodle plugin CI errors in block_microsoft --- blocks/microsoft/block_microsoft.php | 59 +++++++------ blocks/microsoft/db/access.php | 9 +- blocks/microsoft/db/caches.php | 4 +- blocks/microsoft/lang/en/block_microsoft.php | 8 +- blocks/microsoft/sass/styles.scss | 88 -------------------- blocks/microsoft/styles.css | 79 ++++++++++++------ 6 files changed, 100 insertions(+), 147 deletions(-) delete mode 100644 blocks/microsoft/sass/styles.scss diff --git a/blocks/microsoft/block_microsoft.php b/blocks/microsoft/block_microsoft.php index 59c1eca55..832f15afc 100644 --- a/blocks/microsoft/block_microsoft.php +++ b/blocks/microsoft/block_microsoft.php @@ -16,6 +16,7 @@ /** * Block Microsoft block + * * @package block_microsoft * @author James McQuillan * @author Lai Wei @@ -24,12 +25,13 @@ */ use local_o365\feature\coursesync\utils; +use local_onenote\api\base; defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot.'/blocks/microsoft/lib.php'); -require_once($CFG->dirroot.'/auth/oidc/lib.php'); -require_once($CFG->dirroot.'/local/o365/lib.php'); +require_once($CFG->dirroot . '/blocks/microsoft/lib.php'); +require_once($CFG->dirroot . '/auth/oidc/lib.php'); +require_once($CFG->dirroot . '/local/o365/lib.php'); /** * Microsoft Block. @@ -58,7 +60,7 @@ public function has_config() { /** * Get the content of the block. * - * @return stdClass|stdObject|null + * @return stdClass|null */ public function get_content() { global $USER, $DB; @@ -160,8 +162,7 @@ protected function get_course_content() { if ($iscoursecontext && $coursesyncenabled && $iscoursesyncenabled) { $canmanage = (has_capability('local/o365:managegroups', $this->page->context) === true) ? true : false; - $canview = (is_enrolled($this->page->context) && has_capability('local/o365:viewgroups', $this->page->context)) ? - true : false; + $canview = is_enrolled($this->page->context) && has_capability('local/o365:viewgroups', $this->page->context); if ($canmanage === true || $canview === true) { [$courseheader, $o365record] = $this->get_course_header_and_o365object($courseid); @@ -269,9 +270,9 @@ protected function get_user_content_connected() { $o365config = get_config('local_o365'); $html = ''; - $user = $DB->get_record('user', array('id' => $USER->id)); + $user = $DB->get_record('user', ['id' => $USER->id]); $langconnected = get_string('o365connected', 'block_microsoft', $user); - $html .= '
'.$langconnected.'
'; + $html .= '
' . $langconnected . '
'; $odburl = get_config('local_o365', 'odburl'); $o365object = $DB->get_record('local_o365_objects', ['type' => 'user', 'moodleid' => $USER->id]); @@ -284,13 +285,13 @@ protected function get_user_content_connected() { if (!empty($odburl) && !empty($this->globalconfig->settings_showmydelve)) { if (!empty($o365object)) { - $delveurl = 'https://'.$odburl.'/_layouts/15/me.aspx?u='.$o365object->objectid.'&v=work'; + $delveurl = 'https://' . $odburl . '/_layouts/15/me.aspx?u=' . $o365object->objectid . '&v=work'; } } if (!empty($user->picture)) { $html .= '
'; - $picturehtml = $OUTPUT->user_picture($user, array('size' => 100, 'class' => 'block_microsoft_profile')); + $picturehtml = $OUTPUT->user_picture($user, ['size' => 100, 'class' => 'block_microsoft_profile']); $profileurl = new moodle_url('/user/profile.php', ['id' => $USER->id]); if (!empty($delveurl)) { // If "My Delve" is enabled, clicking the user picture should take you to their Delve page. @@ -313,7 +314,7 @@ protected function get_user_content_connected() { if (!empty($coursespsite)) { $spsite = \local_o365\rest\sharepoint::get_tokenresource(); if (!empty($spsite)) { - $spurl = $spsite.'/'.$coursespsite->siteurl; + $spurl = $spsite . '/' . $coursespsite->siteurl; $spattrs = ['class' => 'servicelink block_microsoft_sharepoint', 'target' => '_blank']; $items[] = html_writer::link($spurl, $sharepointstr, $spattrs); $items[] = '
'; @@ -358,7 +359,7 @@ protected function get_user_content_connected() { ]; $stronedrive = get_string('linkonedrive', 'block_microsoft'); if (!empty($odburl)) { - $items[] = html_writer::link('https://'.$odburl, $stronedrive, $odbattrs); + $items[] = html_writer::link('https://' . $odburl, $stronedrive, $odbattrs); } } @@ -386,7 +387,7 @@ protected function get_user_content_connected() { // My Sways. if (!empty($this->globalconfig->settings_showsways) && !empty($userupn)) { - $swayurl = 'https://www.sway.com/my?auth_pvr=OrgId&auth_upn='.$userupn; + $swayurl = 'https://www.sway.com/my?auth_pvr=OrgId&auth_upn=' . $userupn; $swayattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_sway']; $items[] = html_writer::link($swayurl, get_string('linksways', 'block_microsoft'), $swayattrs); } @@ -406,9 +407,9 @@ protected function get_user_content_connected() { } if (auth_oidc_connectioncapability($USER->id, 'connect') === true - || auth_oidc_connectioncapability($USER->id, 'disconnect') === true - || local_o365_connectioncapability($USER->id, 'link') - || local_o365_connectioncapability($USER->id, 'unlink')) { + || auth_oidc_connectioncapability($USER->id, 'disconnect') === true + || local_o365_connectioncapability($USER->id, 'link') + || local_o365_connectioncapability($USER->id, 'unlink')) { if (!empty($this->globalconfig->settings_showmanageo365conection)) { $connecturl = new moodle_url('/local/o365/ucp.php', ['action' => 'connection']); $connectstr = get_string('linkconnection', 'block_microsoft'); @@ -465,6 +466,7 @@ protected function get_user_content_not_connected() { } $html .= html_writer::alist($items); + return $html; } @@ -480,18 +482,20 @@ protected function get_content_o365download() { $url = get_config('block_microsoft', 'settings_geto365link'); $str = get_string('install_office', 'block_microsoft'); + return [ - html_writer::link($url, $str, ['class' => 'servicelink block_microsoft_downloado365', 'target' => '_blank']), + html_writer::link($url, $str, + ['class' => 'servicelink block_microsoft_downloado365', 'target' => '_blank']), ]; } /** * Get the user's Moodle OneNote Notebook. * - * @param \local_onenote\api\base $onenoteapi A constructed OneNote API to use. + * @param base $onenoteapi A constructed OneNote API to use. * @return array Array of information about the user's OneNote notebook used for Moodle. */ - protected function get_onenote_notebook(\local_onenote\api\base $onenoteapi) { + protected function get_onenote_notebook(base $onenoteapi) { $moodlenotebook = null; for ($i = 0; $i < 2; $i++) { $notebooks = $onenoteapi->get_items_list(''); @@ -510,6 +514,7 @@ protected function get_onenote_notebook(\local_onenote\api\base $onenoteapi) { break; } } + return $moodlenotebook; } @@ -532,21 +537,20 @@ protected function render_onenote() { 'onclick' => 'window.open(this.href,\'_blank\'); return false;', 'class' => 'servicelink block_microsoft_onenote', ]; + return html_writer::link($url->out(false), $stropennotebook, $linkattrs); } $action = optional_param('action', '', PARAM_TEXT); try { - $onenoteapi = \local_onenote\api\base::getinstance(); + $onenoteapi = base::getinstance(); $output = ''; if ($onenoteapi->is_logged_in()) { // Add the "save to onenote" button if we are on an assignment page. - $onassignpage = ($this->page->cm - && $this->page->cm->modname == 'assign' - && $action == 'editsubmission') ? true : false; + $onassignpage = $this->page->cm && $this->page->cm->modname == 'assign' && $action == 'editsubmission'; if ($onassignpage === true && $onenoteapi->is_student($this->page->cm->id, $USER->id)) { $workstr = get_string('workonthis', 'block_microsoft'); - $output .= $onenoteapi->render_action_button($workstr, $this->page->cm->id).'

'; + $output .= $onenoteapi->render_action_button($workstr, $this->page->cm->id) . '

'; } // Find moodle notebook, create if not found. $moodlenotebook = null; @@ -570,13 +574,16 @@ protected function render_onenote() { $output .= get_string('error_nomoodlenotebook', 'block_microsoft'); } } + return $output; } catch (moodle_exception $e) { if (class_exists('\local_o365\utils')) { \local_o365\utils::debug($e->getMessage(), __METHOD__, $e); } - return ''.get_string('linkonenote_unavailable', 'block_microsoft') - .'
'.get_string('contactadmin', 'block_microsoft').'
'; + + return '' . + get_string('linkonenote_unavailable', 'block_microsoft') . '
' . + get_string('contactadmin', 'block_microsoft') . '
'; } } } diff --git a/blocks/microsoft/db/access.php b/blocks/microsoft/db/access.php index ad5a180cf..56088ea73 100644 --- a/blocks/microsoft/db/access.php +++ b/blocks/microsoft/db/access.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ + defined('MOODLE_INTERNAL') || die(); $capabilities = [ @@ -29,9 +30,9 @@ 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ - 'user' => CAP_ALLOW + 'user' => CAP_ALLOW, ], - 'clonepermissionsfrom' => 'moodle/my:manageblocks' + 'clonepermissionsfrom' => 'moodle/my:manageblocks', ], 'block/microsoft:addinstance' => [ 'riskbitmask' => RISK_SPAM | RISK_XSS, @@ -39,8 +40,8 @@ 'contextlevel' => CONTEXT_BLOCK, 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW + 'manager' => CAP_ALLOW, ], - 'clonepermissionsfrom' => 'moodle/site:manageblocks' + 'clonepermissionsfrom' => 'moodle/site:manageblocks', ], ]; diff --git a/blocks/microsoft/db/caches.php b/blocks/microsoft/db/caches.php index 9001e3f63..04e56e6ee 100644 --- a/blocks/microsoft/db/caches.php +++ b/blocks/microsoft/db/caches.php @@ -22,9 +22,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ + defined('MOODLE_INTERNAL') || die(); + $definitions = [ 'onenotenotebook' => [ - 'mode' => cache_store::MODE_SESSION + 'mode' => cache_store::MODE_SESSION, ], ]; diff --git a/blocks/microsoft/lang/en/block_microsoft.php b/blocks/microsoft/lang/en/block_microsoft.php index e2d30b88c..18f27e76f 100644 --- a/blocks/microsoft/lang/en/block_microsoft.php +++ b/blocks/microsoft/lang/en/block_microsoft.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder -- The strings are organised by features. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment -- The strings are organised by features. + $string['pluginname'] = 'Microsoft block'; $string['contactadmin'] = 'Contact administrator for more information.'; $string['error_nomoodlenotebook'] = 'Could not find your Moodle notebook.'; @@ -140,7 +143,10 @@ $string['error_connected_team_missing'] = 'The course is configured to be synced, but the Team cannot be found.'; $string['error_course_sync_disabled'] = 'The course is not configured to be synced.'; -// Course request +// Course request. $string['linkcourserequest'] = 'Request course from Teams'; $string['settings_courserequest'] = 'Request course from Teams'; $string['settings_courserequest_desc'] = 'Request a new course from Microsoft Teams. After approval, the course will be created and connected to a Team. Microsoft Team members will be enrolled in the course.'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment diff --git a/blocks/microsoft/sass/styles.scss b/blocks/microsoft/sass/styles.scss deleted file mode 100644 index 0e195a8ad..000000000 --- a/blocks/microsoft/sass/styles.scss +++ /dev/null @@ -1,88 +0,0 @@ -.block_microsoft { - h5 { - font-size: 95%; - text-align: center; - } - ul { - list-style: none; - padding-left: 0; - margin-left: 0; - .servicelink { - background-position: 2px 0px; - background-size: 28px; - background-repeat: no-repeat; - background-color: transparent; - display: inline-block; - padding: 4px 4px 4px 40px; - margin: 0.2rem 0; - &:active, &:hover, &:visited { - text-decoration: none !important; - } - } - } - .block_microsoft_onedrive { - background-image: url([[pix:block_microsoft|onedriveicon]]); - } - .block_microsoft_sway { - background-image: url([[pix:block_microsoft|sway]]); - } - .block_microsoft_msstream { - background-image: url([[pix:block_microsoft|msstream]]); - } - .block_microsoft_msteams { - background-image: url([[pix:block_microsoft|msteams]]); - } - .block_microsoft_onenote { - background-image: url([[pix:block_microsoft|onenotecolor]]); - } - .block_microsoft_outlook { - background-image: url([[pix:block_microsoft|outlookcolor]]); - } - .block_microsoft_connection { - background-image: url([[pix:block_microsoft|o365color]]); - } - .block_microsoft_delve { - background-image: url([[pix:block_microsoft|delvecolor]]); - } - .block_microsoft_forms { - background-image: url([[pix:block_microsoft|formscolor]]); - } - .block_microsoft_sharepoint { - background-image: url([[pix:block_microsoft|sharepointcolor]]); - } - .block_microsoft_preferences { - background-image: url([[pix:moodle|i/settings]]); - } - .block_microsoft_msasignin { - background-image: url([[pix:block_microsoft|msftcolor]]); - } - .block_microsoft_downloado365 { - background-image: url([[pix:moodle|i/restore]]); - } - .block_microsoft_team { - background-image: url([[pix:block_microsoft|msteams]]); - } - .block_microsoft_conversations { - background-image: url([[pix:block_microsoft|outlookcolor]]); - } - .block_microsoft_calendar { - background-image: url([[pix:block_microsoft|calendar]]); - } - .block_microsoft_notebook { - background-image: url([[pix:block_microsoft|onenotecolor]]); - } - .block_microsoft_sync { - background-image: url([[pix:moodle|i/settings]]); - } - .block_microsoft_reset { - background-image: url([[pix:moodle|t/reset]]); - } - .block_microsoft_profile { - border-radius: 50%; - display: block; - margin: 1rem auto 2rem; - } - hr { - margin: 1rem 0 !important; - } -} diff --git a/blocks/microsoft/styles.css b/blocks/microsoft/styles.css index 27fcd7403..2098de930 100644 --- a/blocks/microsoft/styles.css +++ b/blocks/microsoft/styles.css @@ -1,12 +1,14 @@ .block_microsoft h5 { - font-size: 95%; - text-align: center; + font-size: 95%; + text-align: center; } + .block_microsoft ul { - list-style: none; - padding-left: 0; - margin-left: 0; + list-style: none; + padding-left: 0; + margin-left: 0; } + .block_microsoft ul .servicelink { background-position: 2px 0px; background-size: 28px; @@ -16,68 +18,91 @@ padding: 4px 4px 4px 40px; margin: 0.2rem 0; } + .block_microsoft ul .servicelink:active, .block_microsoft ul .servicelink:hover, .block_microsoft ul .servicelink:visited { - text-decoration: none !important; + text-decoration: none !important; } + .block_microsoft .block_microsoft_onedrive { - background-image: url([[pix:block_microsoft|onedriveicon]]); + background-image: url([[pix:block_microsoft|onedriveicon]]); } + .block_microsoft .block_microsoft_sway { - background-image: url([[pix:block_microsoft|sway]]); + background-image: url([[pix:block_microsoft|sway]]); } + .block_microsoft .block_microsoft_msstream { - background-image: url([[pix:block_microsoft|msstream]]); + background-image: url([[pix:block_microsoft|msstream]]); } + .block_microsoft .block_microsoft_msteams { - background-image: url([[pix:block_microsoft|msteams]]); + background-image: url([[pix:block_microsoft|msteams]]); } + .block_microsoft .block_microsoft_onenote { - background-image: url([[pix:block_microsoft|onenotecolor]]); + background-image: url([[pix:block_microsoft|onenotecolor]]); } + .block_microsoft .block_microsoft_outlook { - background-image: url([[pix:block_microsoft|outlookcolor]]); + background-image: url([[pix:block_microsoft|outlookcolor]]); } + .block_microsoft .block_microsoft_connection { - background-image: url([[pix:block_microsoft|o365color]]); + background-image: url([[pix:block_microsoft|o365color]]); } + .block_microsoft .block_microsoft_delve { - background-image: url([[pix:block_microsoft|delvecolor]]); + background-image: url([[pix:block_microsoft|delvecolor]]); } + .block_microsoft .block_microsoft_forms { - background-image: url([[pix:block_microsoft|formscolor]]); + background-image: url([[pix:block_microsoft|formscolor]]); } + .block_microsoft .block_microsoft_sharepoint { - background-image: url([[pix:block_microsoft|sharepointcolor]]); + background-image: url([[pix:block_microsoft|sharepointcolor]]); } + .block_microsoft .block_microsoft_preferences { - background-image: url([[pix:moodle|i/settings]]); + background-image: url([[pix:moodle|i/settings]]); } + .block_microsoft .block_microsoft_msasignin { - background-image: url([[pix:block_microsoft|msftcolor]]); + background-image: url([[pix:block_microsoft|msftcolor]]); } + .block_microsoft .block_microsoft_downloado365 { - background-image: url([[pix:moodle|i/restore]]); + background-image: url([[pix:moodle|i/restore]]); } + .block_microsoft .block_microsoft_team { - background-image: url([[pix:block_microsoft|msteams]]); + background-image: url([[pix:block_microsoft|msteams]]); } + .block_microsoft .block_microsoft_conversations { - background-image: url([[pix:block_microsoft|outlookcolor]]); + background-image: url([[pix:block_microsoft|outlookcolor]]); } + .block_microsoft .block_microsoft_calendar { - background-image: url([[pix:block_microsoft|calendar]]); + background-image: url([[pix:block_microsoft|calendar]]); } + .block_microsoft .block_microsoft_notebook { - background-image: url([[pix:block_microsoft|onenotecolor]]); + background-image: url([[pix:block_microsoft|onenotecolor]]); } + .block_microsoft .block_microsoft_sync { - background-image: url([[pix:moodle|i/settings]]); + background-image: url([[pix:moodle|i/settings]]); } + .block_microsoft .block_microsoft_reset { - background-image: url([[pix:moodle|t/reset]]); + background-image: url([[pix:moodle|t/reset]]); } + .block_microsoft .block_microsoft_courserequest { - background-image: url([[pix:block_microsoft|courserequest]]); + background-image: url([[pix:block_microsoft|courserequest]]); } + .block_microsoft hr { - margin: 1rem 0 !important; } + margin: 1rem 0 !important; +}