Skip to content

Commit

Permalink
Fix Moodle plugin CI errors in block_microsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Oct 25, 2024
1 parent 8e6c37a commit 246a1c4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 147 deletions.
59 changes: 33 additions & 26 deletions blocks/microsoft/block_microsoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* Block Microsoft block
*
* @package block_microsoft
* @author James McQuillan <[email protected]>
* @author Lai Wei <[email protected]>
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 .= '<h5>'.$langconnected.'</h5>';
$html .= '<h5>' . $langconnected . '</h5>';

$odburl = get_config('local_o365', 'odburl');
$o365object = $DB->get_record('local_o365_objects', ['type' => 'user', 'moodleid' => $USER->id]);
Expand All @@ -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 .= '<div class="profilepicture">';
$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.
Expand All @@ -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[] = '<hr/>';
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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');
Expand Down Expand Up @@ -465,6 +466,7 @@ protected function get_user_content_not_connected() {
}

$html .= html_writer::alist($items);

return $html;
}

Expand All @@ -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('');
Expand All @@ -510,6 +514,7 @@ protected function get_onenote_notebook(\local_onenote\api\base $onenoteapi) {
break;
}
}

return $moodlenotebook;
}

Expand All @@ -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).'<br /><br />';
$output .= $onenoteapi->render_action_button($workstr, $this->page->cm->id) . '<br /><br />';
}
// Find moodle notebook, create if not found.
$moodlenotebook = null;
Expand All @@ -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 '<span class="block_microsoft_onenote servicelink">'.get_string('linkonenote_unavailable', 'block_microsoft')
.'<br /><small>'.get_string('contactadmin', 'block_microsoft').'</small></span>';

return '<span class="block_microsoft_onenote servicelink">' .
get_string('linkonenote_unavailable', 'block_microsoft') . '<br /><small>' .
get_string('contactadmin', 'block_microsoft') . '</small></span>';
}
}
}
9 changes: 5 additions & 4 deletions blocks/microsoft/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@
* @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 = [
'block/microsoft:myaddinstance' => [
'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,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/site:manageblocks'
'clonepermissionsfrom' => 'moodle/site:manageblocks',
],
];
4 changes: 3 additions & 1 deletion blocks/microsoft/db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
8 changes: 7 additions & 1 deletion blocks/microsoft/lang/en/block_microsoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down Expand Up @@ -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
88 changes: 0 additions & 88 deletions blocks/microsoft/sass/styles.scss

This file was deleted.

Loading

0 comments on commit 246a1c4

Please sign in to comment.