Skip to content

Commit

Permalink
Fix Moodle plugin CI errors in local_o365
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Oct 24, 2024
1 parent 9a49bba commit 361dc3a
Show file tree
Hide file tree
Showing 99 changed files with 1,097 additions and 1,067 deletions.
4 changes: 1 addition & 3 deletions local/o365/classes/adminsetting/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use moodle_url;
use tabobject;

defined('MOODLE_INTERNAL') || die();

/**
* A tab in the plugin configuration page.
*/
Expand Down Expand Up @@ -136,7 +134,7 @@ public function write_setting($data) {
* @param moodle_url|null $url An explicit URL to use instead of settings page section.
* @uses $CFG
*/
public function addtab($id, $name, moodle_url $url = null) {
public function addtab($id, $name, ?moodle_url $url = null) {
if (empty($url)) {
$urlparams = [
'section' => $this->section,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function __construct($name, $visiblename, $description, $defaultsetting)
];
$order = 0;
while ($order++ < 15) {
$this->remotefields['extensionAttribute' . $order] = get_string('settings_fieldmap_field_extensionattribute', 'auth_oidc',
$order);
$this->remotefields['extensionAttribute' . $order] = get_string('settings_fieldmap_field_extensionattribute',
'auth_oidc', $order);
}

return parent::__construct($name, $visiblename, $description, $defaultsetting);
Expand Down
10 changes: 5 additions & 5 deletions local/o365/classes/adminsetting/usersyncoptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ public function __construct($name, $visiblename, $description) {
*/
public function output_html($data, $query = '') {
global $OUTPUT;
if (!$this->load_choices() or empty($this->choices)) {
if (!$this->load_choices() || empty($this->choices)) {
return '';
}
$default = $this->get_defaultsetting();
if (is_null($default)) {
$default = array();
$default = [];
}
if (is_null($data)) {
$data = array();
$data = [];
}
$options = array();
$defaults = array();
$options = [];
$defaults = [];
foreach ($this->choices as $key => $description) {
if (!empty($data[$key])) {
$checked = 'checked="checked"';
Expand Down
8 changes: 2 additions & 6 deletions local/o365/classes/adminsetting/verifysetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,10 @@ public function output_html($data, $query = '') {
if (\local_o365\adminsetting\detectoidc::setup_step_complete() === true) {
$existingsetting = $this->config_read($this->name);
if (!empty($existingsetting)) {
$messageattrs = [
'class' => 'permmessage'
];
$messageattrs = ['class' => 'permmessage'];
$message = \html_writer::tag('span', get_string('settings_detectperms_valid', 'local_o365'), $messageattrs);
} else {
$messageattrs = [
'class' => 'permmessage'
];
$messageattrs = ['class' => 'permmessage'];
$message = \html_writer::tag('span', get_string('settings_detectperms_invalid', 'local_o365'), $messageattrs);
}
} else {
Expand Down
2 changes: 0 additions & 2 deletions local/o365/classes/event/api_call_failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_o365\event;

defined('MOODLE_INTERNAL') || die();

/**
* Event fired whenever a user subscribes to a calendar.
*/
Expand Down
2 changes: 0 additions & 2 deletions local/o365/classes/event/calendar_subscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_o365\event;

defined('MOODLE_INTERNAL') || die();

/**
* Event fired whenever a user subscribes to a calendar.
*/
Expand Down
2 changes: 0 additions & 2 deletions local/o365/classes/event/calendar_unsubscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_o365\event;

defined('MOODLE_INTERNAL') || die();

/**
* Event fired whenever a user unsubscribes from a calendar.
*/
Expand Down
16 changes: 11 additions & 5 deletions local/o365/classes/feature/calsync/form/element/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

require_once("$CFG->libdir/form/advcheckbox.php");

// phpcs:disable moodle.NamingConventions.ValidVariableName.VariableNameLowerCase -- Parent class uses uppercase variable names.
// phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod -- Parent class uses uppercase method names.

/**
* Calendar form element. Provides checkbox to enable/disable calendar and options for sync behavior.
*/
Expand All @@ -50,15 +53,15 @@ class calendar extends \HTML_QuickForm_advcheckbox {
/**
* Constructor, accessed through __call constructor workaround.
*
* @param string $elementName The name of the element.
* @param string $elementLabel The label of the element.
* @param string $elementname The name of the element.
* @param string $elementlabel The label of the element.
* @param string $text Text that appears after the checkbox.
* @param array $attributes Array of checkbox attributes.
* @param array $customdata Array of form custom data.
*/
public function calendarconstruct($elementName = null, $elementLabel = null, $text = null, $attributes = null,
public function calendarconstruct($elementname = null, $elementlabel = null, $text = null, $attributes = null,
$customdata = []) {
parent::__construct($elementName, $elementLabel, $text, $attributes, null);
parent::__construct($elementname, $elementlabel, $text, $attributes, null);
$this->customdata = $customdata;
$this->_type = 'advcheckbox';
}
Expand Down Expand Up @@ -112,7 +115,7 @@ public function setValue($value) {
*
* @return string html for help button
*/
function getHelpButton(){
public function getHelpButton() {
return $this->_helpbutton;
}

Expand Down Expand Up @@ -183,3 +186,6 @@ public function toHtml() {
return $html;
}
}

// phpcs:enable moodle.NamingConventions.ValidVariableName.VariableNameLowerCase
// phpcs:enable moodle.NamingConventions.ValidFunctionName.LowercaseMethod
20 changes: 10 additions & 10 deletions local/o365/classes/feature/calsync/form/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$newsetting = [
'user_id' => $USER->id,
'o365calid' => $sitecalenderid,
'timecreated' => time()
'timecreated' => time(),
];
$newsetting['id'] = $DB->insert_record('local_o365_calsettings', (object)$newsetting);
} else if (empty($fromform->settingcal) && !empty($usersetting)) {
$DB->delete_records('local_o365_calsettings', array('user_id' => $USER->id));
$DB->delete_records('local_o365_calsettings', ['user_id' => $USER->id]);
}

// Determine and organize existing subscriptions.
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $currentcaldata[$caltype]['recid'],
'userid' => $USER->id,
'other' => ['caltype' => $caltype]
'other' => ['caltype' => $caltype],
];
$event = \local_o365\event\calendar_unsubscribed::create($eventdata);
$event->trigger();
Expand All @@ -202,13 +202,13 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
'o365calid' => $syncwith,
'syncbehav' => $syncbehav,
'isprimary' => ($syncwith == $primarycalid) ? '1' : '0',
'timecreated' => time()
'timecreated' => time(),
];
$newsub['id'] = $DB->insert_record('local_o365_calsub', (object)$newsub);
$eventdata = [
'objectid' => $newsub['id'],
'userid' => $USER->id,
'other' => ['caltype' => $caltype]
'other' => ['caltype' => $caltype],
];
} else {
// Already subscribed, update behavior.
Expand All @@ -222,7 +222,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $currentcaldata[$caltype]['recid'],
'userid' => $USER->id,
'other' => ['caltype' => $caltype]
'other' => ['caltype' => $caltype],
];
}
$event = \local_o365\event\calendar_subscribed::create($eventdata);
Expand All @@ -241,13 +241,13 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
}
}
$todelete = (empty($fromform->settingcal)) ? $existingcoursesubs : array_diff_key($existingcoursesubs, $newcoursesubs);
$toadd = (empty($fromform->settingcal)) ? array() : array_diff_key($newcoursesubs, $existingcoursesubs);
$toadd = (empty($fromform->settingcal)) ? [] : array_diff_key($newcoursesubs, $existingcoursesubs);
foreach ($todelete as $courseid => $unused) {
$DB->delete_records('local_o365_calsub', ['user_id' => $USER->id, 'caltype' => 'course', 'caltypeid' => $courseid]);
$eventdata = [
'objectid' => $USER->id,
'userid' => $USER->id,
'other' => ['caltype' => 'course', 'caltypeid' => $courseid]
'other' => ['caltype' => 'course', 'caltypeid' => $courseid],
];
$event = \local_o365\event\calendar_unsubscribed::create($eventdata);
$event->trigger();
Expand All @@ -273,7 +273,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $USER->id,
'userid' => $USER->id,
'other' => ['caltype' => 'course', 'caltypeid' => $courseid]
'other' => ['caltype' => 'course', 'caltypeid' => $courseid],
];
$event = \local_o365\event\calendar_subscribed::create($eventdata);
$event->trigger();
Expand All @@ -297,7 +297,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $USER->id,
'userid' => $USER->id,
'other' => ['caltype' => 'course', 'caltypeid' => $courseid]
'other' => ['caltype' => 'course', 'caltypeid' => $courseid],
];
$event = \local_o365\event\calendar_subscribed::create($eventdata);
$event->trigger();
Expand Down
33 changes: 4 additions & 29 deletions local/o365/classes/feature/calsync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
use local_o365\utils;
use moodle_exception;

defined('MOODLE_INTERNAL') || die();

/**
* Calendar sync feature.
*/
Expand All @@ -54,7 +52,7 @@ class main {
* @param httpclient|null $httpclient
* @throws moodle_exception
*/
public function __construct(clientdata $clientdata = null, httpclient $httpclient = null) {
public function __construct(?clientdata $clientdata = null, ?httpclient $httpclient = null) {
$this->clientdata = (!empty($clientdata)) ? $clientdata : clientdata::instance_from_oidc();
$this->httpclient = (!empty($httpclient)) ? $httpclient : new httpclient();
}
Expand Down Expand Up @@ -293,7 +291,7 @@ public function create_outlook_event_from_moodle_event($moodleventid) {
'emailAddress' => [
'name' => $groupobject->o365name,
'address' => $outlookgroupemail,
]
],
],
'responseRequested' => false,
'isOrganizer' => true,
Expand All @@ -313,6 +311,7 @@ public function create_outlook_event_from_moodle_event($moodleventid) {
}
} catch (moodle_exception $e) {
// No token found, nothing to do.
debugging('Error creating group event. Details: ' . $e->getMessage());
}
}
}
Expand Down Expand Up @@ -478,7 +477,7 @@ public function update_outlook_event($moodleeventid) {
try {
$apiclient->update_event($idmaprec->outlookeventid, $updated, $o365upn);
} catch (moodle_exception $e) {
// Do nothing.
mtrace('Error updating event: '.$e->getMessage());
}
}
}
Expand Down Expand Up @@ -539,30 +538,6 @@ protected function construct_outlook_group_email($courseid) {
return $groupemail;
}

/**
* Get group first and last name.
* @param string $groupname The o365 group name.
* @return array The first index is the first name and the second index is the last name.
*/
protected function group_first_last_name($groupname) {
$firstname = '';
$lastname = '';
if (empty($groupname)) {
return array($firstname, $lastname);
}

$pos = strpos($groupname, ': ');

if (false === $pos) {
return array($firstname, $lastname);
}

$firstname = substr($groupname, 0, $pos + 1);
$lastname = substr($groupname, $pos + 1);
$lastname = trim($lastname);
return array($firstname, $lastname);
}

/**
* Create a new calendar in the user's o365 calendars.
*
Expand Down
4 changes: 2 additions & 2 deletions local/o365/classes/feature/calsync/observers.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static function handle_user_enrolment_deleted(\core\event\user_enrolment_
'userid' => $userid,
'other' => [
'caltype' => 'course',
'caltypeid' => $courseid
]
'caltypeid' => $courseid,
],
];
$event = \local_o365\event\calendar_unsubscribed::create($eventdata);
$event->trigger();
Expand Down
6 changes: 2 additions & 4 deletions local/o365/classes/feature/calsync/task/importfromoutlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use core_date;
use moodle_exception;

defined('MOODLE_INTERNAL') || die();

/**
* Scheduled task to check for new o365 events and sync them into Moodle.
*/
Expand Down Expand Up @@ -111,7 +109,7 @@ public function execute() {
// If all day event time is stored in Outlook only as UTC time and not in the local user time.
if (isset($event['isAllDay']) && $event['isAllDay'] == '1') {
// Need to make the time the same as the user preference so no time conversion.
$user = $DB->get_record('user', array('id' => $calsub->user_id));
$user = $DB->get_record('user', ['id' => $calsub->user_id]);
if ($user->timezone == 99) {
$user->timezone = core_date::get_server_timezone();
}
Expand All @@ -137,7 +135,7 @@ public function execute() {
'eventid' => $moodleevent->id,
'outlookeventid' => $event['id'],
'origin' => 'o365',
'userid' => $calsub->user_id
'userid' => $calsub->user_id,
];
$DB->insert_record('local_o365_calidmap', (object)$idmaprec);
mtrace('Successfully imported event #'.$moodleevent->id);
Expand Down
9 changes: 4 additions & 5 deletions local/o365/classes/feature/calsync/task/syncoldevents.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use local_o365\utils;
use moodle_exception;

defined('MOODLE_INTERNAL') || die();

/**
* AdHoc task to sync existing Moodle calendar events with Microsoft 365.
*
Expand Down Expand Up @@ -125,7 +123,7 @@ protected function sync_siteevents($timecreated) {
$calsync->update_event_raw($event->eventuserid, $event->outlookeventid,
['attendees' => $subscribersprimary]);
} catch (moodle_exception $e) {
// Do nothing.
mtrace('ERROR: ' . $e->getMessage());
}
} else {
$calid = null;
Expand All @@ -146,7 +144,7 @@ protected function sync_siteevents($timecreated) {
$subscribersprimary, [], $calid);
}
} catch (moodle_exception $e) {
mtrace('ERROR: '.$e->getMessage());
mtrace('ERROR: ' . $e->getMessage());
}
}

Expand Down Expand Up @@ -269,6 +267,7 @@ protected function sync_courseevents($courseid, $timecreated) {
['attendees' => $eventattendees]);
} catch (moodle_exception $e) {
// Do nothing.
mtrace('Error updating event #' . $event->eventid . ': ' . $e->getMessage());
}
} else {
$calid = null;
Expand Down Expand Up @@ -327,7 +326,7 @@ protected function sync_courseevents($courseid, $timecreated) {
}
} catch (moodle_exception $e) {
// Could not sync this course event. Log and continue.
mtrace('Error syncing course event #'.$event->eventid.': '.$e->getMessage());
mtrace('Error syncing course event #' . $event->eventid . ': ' . $e->getMessage());
}
}
$events->close();
Expand Down
Loading

0 comments on commit 361dc3a

Please sign in to comment.