Issue #390: Code cleanup to fix code standards codesniffer errors.

This commit is contained in:
abhinavgandham
2026-01-12 15:08:32 +10:00
parent 42dbec5b4d
commit 7f968b2365
52 changed files with 481 additions and 363 deletions

View File

@@ -20,7 +20,7 @@ use auth_outage\local\outage;
use calendar_event;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/calendar/lib.php');
require_once($CFG->dirroot . '/calendar/lib.php');
/**
* calendar class.
@@ -53,7 +53,7 @@ class calendar {
$event = self::load($outage->id);
if (is_null($event)) {
debugging('Cannot update calendar entry for outage #'.$outage->id.', event not found. Creating it...');
debugging('Cannot update calendar entry for outage #' . $outage->id . ', event not found. Creating it...');
self::create($outage);
} else {
$event->update(self::create_data($outage), false);
@@ -69,7 +69,7 @@ class calendar {
// If not found (was not created before) ignore it.
if (is_null($event)) {
debugging('Cannot delete calendar entry for outage #'.$outageid.', event not found. Ignoring it...');
debugging('Cannot delete calendar entry for outage #' . $outageid . ', event not found. Ignoring it...');
} else {
$event->delete();
}

View File

@@ -26,7 +26,7 @@ use coding_exception;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/calendar/lib.php');
require_once($CFG->dirroot . '/calendar/lib.php');
/**
* outagedb class.
@@ -118,7 +118,6 @@ class outagedb {
// Create calendar entry.
calendar::create($outage);
} else {
$other = (array) $outage;
$other['title'] = $outage->get_title();
$event = outage_updated::create([
@@ -208,8 +207,10 @@ class outagedb {
$outagecache = new outage(json_decode($outageinfo));
}
if ($outagecache && $outagecache->warntime <= $time && $outagecache->stoptime >= $time
&& (!$outagecache->finished || $outagecache->finished >= $time)) {
if (
$outagecache && $outagecache->warntime <= $time && $outagecache->stoptime >= $time
&& (!$outagecache->finished || $outagecache->finished >= $time)
) {
return $outagecache;
}
return null;
@@ -238,7 +239,8 @@ class outagedb {
':datetime1 < stoptime AND (finished IS NULL OR :datetime2 < finished)',
['datetime1' => $time, 'datetime2' => $time],
'starttime ASC, stoptime DESC, title ASC',
'*');
'*'
);
foreach ($rs as $r) {
$outages[] = new outage($r);
}
@@ -270,7 +272,8 @@ class outagedb {
'NOT (:datetime1 < stoptime AND (finished IS NULL OR :datetime2 < finished))',
['datetime1' => $time, 'datetime2' => $time],
'stoptime DESC, starttime DESC, title ASC',
'*');
'*'
);
foreach ($rs as $r) {
$outages[] = new outage($r);
}
@@ -295,12 +298,12 @@ class outagedb {
$outage = self::get_by_id($id);
if (is_null($outage)) {
debugging('Cannot finish outage #'.$id.': outage not found.');
debugging('Cannot finish outage #' . $id . ': outage not found.');
return;
}
if (!$outage->is_ongoing($time)) {
debugging('Cannot finish outage #'.$id.': outage not ongoing.');
debugging('Cannot finish outage #' . $id . ': outage not ongoing.');
return;
}

View File

@@ -17,7 +17,7 @@
namespace auth_outage\form\outage;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir . '/formslib.php');
/**
* delete class.

View File

@@ -22,7 +22,7 @@ use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir . '/formslib.php');
/**
* edit class.
@@ -64,7 +64,7 @@ class edit extends moodleform {
'text',
'title',
get_string('title', 'auth_outage'),
'maxlength="'.self::TITLE_MAX_CHARS.'" size="60"'
'maxlength="' . self::TITLE_MAX_CHARS . '" size="60"'
);
$mform->setType('title', PARAM_TEXT);
$mform->addHelpButton('title', 'title', 'auth_outage');
@@ -75,8 +75,13 @@ class edit extends moodleform {
$mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage'));
$mform->addElement('static', 'warningreenablemaintenancemode', '');
$mform->addElement('advcheckbox', 'useaccesskey', get_string('useaccesskey', 'auth_outage'),
get_string('useaccesskey:desc', 'auth_outage'), 0);
$mform->addElement(
'advcheckbox',
'useaccesskey',
get_string('useaccesskey', 'auth_outage'),
get_string('useaccesskey:desc', 'auth_outage'),
0
);
$mform->addElement('text', 'accesskey', get_string('accesskey', 'auth_outage'));
$mform->setType('accesskey', PARAM_TEXT);
@@ -125,7 +130,7 @@ class edit extends moodleform {
return null;
}
if ($data->description['format'] != '1') {
debugging('Not implemented for format '.$data->description['format'], DEBUG_DEVELOPER);
debugging('Not implemented for format ' . $data->description['format'], DEBUG_DEVELOPER);
return null;
}
$outagedata = [
@@ -165,8 +170,10 @@ class edit extends moodleform {
]);
// If the default_autostart is configured in config, then force autostart to be the default value.
if (array_key_exists('auth_outage', $CFG->forced_plugin_settings)
&& array_key_exists('default_autostart', $CFG->forced_plugin_settings['auth_outage'])) {
if (
array_key_exists('auth_outage', $CFG->forced_plugin_settings)
&& array_key_exists('default_autostart', $CFG->forced_plugin_settings['auth_outage'])
) {
$this->_form->setDefaults([
'autostart' => $CFG->forced_plugin_settings['auth_outage']['default_autostart'],
]);
@@ -175,8 +182,10 @@ class edit extends moodleform {
if (!empty($outage->id) && $outage->autostart && $outage->starttime < time() && $outage->stoptime > time()) {
$warning = $mform->getElement('warningreenablemaintenancemode');
$warning->setValue($OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'),
'notifywarning'));
$warning->setValue($OUTPUT->notification(
get_string('warningreenablemaintenancemode', 'auth_outage'),
'notifywarning'
));
}
} else {
throw new coding_exception('$outage must be an outage object.', $outage);

View File

@@ -20,7 +20,7 @@ use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir . '/formslib.php');
/**
* finish class.

View File

@@ -28,7 +28,6 @@ use core\hook\output\before_standard_top_of_body_html_generation;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class hook_callbacks {
/**
* Inject the warning bar into the page if there is currently an outage.
*

View File

@@ -79,6 +79,6 @@ class cli_exception extends Exception {
* @param Exception|null $previous Another exception as reference or null.
*/
public function __construct($message, $code = 1, ?Exception $previous = null) {
parent::__construct('*ERROR* '.$message, $code, $previous = null);
parent::__construct('*ERROR* ' . $message, $code, $previous = null);
}
}

View File

@@ -46,7 +46,7 @@ abstract class clibase {
*/
public function __construct(?array $options = null) {
global $CFG;
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->libdir . '/clilib.php');
$warning = outagelib::generate_plugin_configuration_warning();
if ($warning) {
@@ -57,11 +57,13 @@ abstract class clibase {
if (is_null($options)) {
// Using Moodle CLI API to read the parameters.
list($options, $unrecognized) = cli_get_params($this->generate_options(), $this->generate_shortcuts());
[$options, $unrecognized] = cli_get_params($this->generate_options(), $this->generate_shortcuts());
if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized);
throw new cli_exception(get_string('cliunknowoption', 'admin', $unrecognized),
cli_exception::ERROR_PARAMETER_UNKNOWN);
throw new cli_exception(
get_string('cliunknowoption', 'admin', $unrecognized),
cli_exception::ERROR_PARAMETER_UNKNOWN
);
}
} else {
// If not using Moodle CLI API to read parameters, ensure all keys exist.
@@ -129,13 +131,13 @@ abstract class clibase {
$options = $this->generate_options();
$shorts = array_flip($this->generate_shortcuts());
printf("%s\n\n", get_string('cli'.$cliname.'help', 'auth_outage'));
printf("%s\n\n", get_string('cli' . $cliname . 'help', 'auth_outage'));
foreach (array_keys($options) as $long) {
$text = get_string('cli'.$cliname.'param'.$long, 'auth_outage');
$short = isset($shorts[$long]) ? ('-'.$shorts[$long].',') : '';
$long = '--'.$long;
$text = get_string('cli' . $cliname . 'param' . $long, 'auth_outage');
$short = isset($shorts[$long]) ? ('-' . $shorts[$long] . ',') : '';
$long = '--' . $long;
printf(" %-4s %-20s %s\n", $short, $long, $text);
}
printf("\n%s\n\n", get_string('cli'.$cliname.'examples', 'auth_outage'));
printf("\n%s\n\n", get_string('cli' . $cliname . 'examples', 'auth_outage'));
}
}

View File

@@ -83,7 +83,7 @@ class create extends clibase {
// Check if any extra parameter was given.
foreach (array_keys($defaults) as $key) {
if (!array_key_exists($key, $missing)) {
throw new coding_exception('$default['.$key.'] is not valid.');
throw new coding_exception('$default[' . $key . '] is not valid.');
}
unset($missing[$key]);
}
@@ -91,7 +91,7 @@ class create extends clibase {
// Check if any required parameter is missing.
foreach (array_keys($missing) as $k => $v) {
if (is_null($v)) {
throw new coding_exception('$default[] missing: '.$k);
throw new coding_exception('$default[] missing: ' . $k);
}
}
@@ -110,8 +110,10 @@ class create extends clibase {
// If not help mode, 'start' is required and cannot use default.
if (is_null($this->options['start'])) {
throw new cli_exception(get_string('clierrormissingparamaters', 'auth_outage'),
cli_exception::ERROR_PARAMETER_MISSING);
throw new cli_exception(
get_string('clierrormissingparamaters', 'auth_outage'),
cli_exception::ERROR_PARAMETER_MISSING
);
}
// If cloning, set defaults to outage being cloned.
@@ -189,8 +191,10 @@ class create extends clibase {
private function clone_defaults() {
$id = $this->options['clone'];
if (!is_number($id) || ($id <= 0)) {
throw new cli_exception(get_string('clierrorinvalidvaluenotid', 'auth_outage', ['param' => 'clone']),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvaluenotid', 'auth_outage', ['param' => 'clone']),
cli_exception::ERROR_PARAMETER_INVALID
);
}
$outage = outagedb::get_by_id((int)$id);
@@ -234,13 +238,17 @@ class create extends clibase {
*/
private function merge_options_check_parameters_int_nonnegative($option, $param) {
if (!is_number($option)) {
throw new cli_exception(get_string('clierrorinvalidvaluenotnumber', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvaluenotnumber', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID
);
}
$option = (int)$option;
if ($option < 0) {
throw new cli_exception(get_string('clierrorinvalidvaluenegativenumber', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvaluenegativenumber', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID
);
}
return $option;
}
@@ -254,13 +262,17 @@ class create extends clibase {
*/
private function merge_options_check_parameters_string_nonempty($option, $param) {
if (!is_string($option)) {
throw new cli_exception(get_string('clierrorinvalidvaluenotstring', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvaluenotstring', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID
);
}
$option = trim($option);
if (strlen($option) == 0) {
throw new cli_exception(get_string('clierrorinvalidvalueemptystring', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvalueemptystring', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID
);
}
return $option;
}
@@ -287,7 +299,9 @@ class create extends clibase {
}
}
throw new cli_exception(get_string('clierrorinvalidvaluenotbool', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvaluenotbool', 'auth_outage', ['param' => $param]),
cli_exception::ERROR_PARAMETER_INVALID
);
}
}

View File

@@ -66,16 +66,20 @@ class finish extends clibase {
// Cannot run during CLI_MAINTENANCE mode.
if (CLI_MAINTENANCE) {
throw new cli_exception(get_string('cliinmaintenancemode', 'auth_outage'),
cli_exception::ERROR_MAINTENANCE_MODE);
throw new cli_exception(
get_string('cliinmaintenancemode', 'auth_outage'),
cli_exception::ERROR_MAINTENANCE_MODE
);
}
// Requires outageid or active but not both at the same time.
$byid = !is_null($this->options['outageid']);
$byactive = $this->options['active'];
if ($byid == $byactive) {
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'),
cli_exception::ERROR_PARAMETER_MISSING);
throw new cli_exception(
get_string('cliwaitforiterroridxoractive', 'auth_outage'),
cli_exception::ERROR_PARAMETER_MISSING
);
}
$outage = $this->get_outage();
@@ -97,8 +101,10 @@ class finish extends clibase {
} else {
$id = $this->options['outageid'];
if (!is_number($id) || ($id <= 0)) {
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']),
cli_exception::ERROR_PARAMETER_INVALID
);
}
$outage = outagedb::get_by_id((int)$id);
}

View File

@@ -90,8 +90,10 @@ class waitforit extends clibase {
$byid = !is_null($this->options['outageid']);
$byactive = $this->options['active'];
if ($byid == $byactive) {
throw new cli_exception(get_string('cliwaitforiterroridxoractive', 'auth_outage'),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('cliwaitforiterroridxoractive', 'auth_outage'),
cli_exception::ERROR_PARAMETER_INVALID
);
}
$this->verbose('Verbose mode activated.');
@@ -100,11 +102,11 @@ class waitforit extends clibase {
while ($sleep = $this->wait_for_outage_to_start($outage)) {
if (is_null($this->sleepcallback)) {
$this->verbose('Sleeping for '.$sleep.' second(s).');
$this->verbose('Sleeping for ' . $sleep . ' second(s).');
sleep($sleep);
$this->time = time();
} else {
$this->verbose('Calling callback to sleep '.$sleep.' second(s).');
$this->verbose('Calling callback to sleep ' . $sleep . ' second(s).');
$callback = $this->sleepcallback;
$this->time = $callback($sleep);
}
@@ -136,10 +138,12 @@ class waitforit extends clibase {
} else {
$id = $this->options['outageid'];
if (!is_number($id) || ($id <= 0)) {
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']),
cli_exception::ERROR_PARAMETER_INVALID);
throw new cli_exception(
get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'outageid']),
cli_exception::ERROR_PARAMETER_INVALID
);
}
$this->verbose('Querying database for outage #'.$id.'...');
$this->verbose('Querying database for outage #' . $id . '...');
$outage = outagedb::get_by_id((int)$id);
}
@@ -147,7 +151,7 @@ class waitforit extends clibase {
throw new cli_exception(get_string('clierroroutagenotfound', 'auth_outage'), cli_exception::ERROR_OUTAGE_NOT_FOUND);
}
$this->verbose('Found outage #'.$outage->id.': '.$outage->get_title());
$this->verbose('Found outage #' . $outage->id . ': ' . $outage->get_title());
return $outage;
}

View File

@@ -114,7 +114,7 @@ class infopage {
'admin' => is_siteadmin(),
'outage' => $this->outage,
];
require($CFG->dirroot.'/auth/outage/views/info/content.php');
require($CFG->dirroot . '/auth/outage/views/info/content.php');
// Moodle 2.7 did not check for CLI mode, which was fixed later.
if (!($CFG->branch == '27' && CLI_SCRIPT)) {
@@ -133,7 +133,7 @@ class infopage {
}
if (!is_null($params['id']) && !is_null($params['outage']) && ($params['id'] !== $params['outage']->id)) {
throw new coding_exception('Provided id and outage->id do not match.', $params['id'].'/'.$params['outage']->id);
throw new coding_exception('Provided id and outage->id do not match.', $params['id'] . '/' . $params['outage']->id);
}
if (is_null($params['id']) && is_null($params['outage'])) {

View File

@@ -50,7 +50,8 @@ class maintenance_static_page {
$html = '<html></html>';
} else {
$data = maintenance_static_page_io::file_get_data(
$CFG->wwwroot.'/auth/outage/info.php?auth_outage_hide_warning=1&static=1&id='.$outage->id);
$CFG->wwwroot . '/auth/outage/info.php?auth_outage_hide_warning=1&static=1&id=' . $outage->id
);
$html = $data['contents'];
}

View File

@@ -74,7 +74,6 @@ class maintenance_static_page_generator {
$this->io->cleanup();
if (!is_null($this->dom)) {
// This can take a while to process using repeated curls.
core_php_time_limit::raise();
@@ -184,9 +183,9 @@ class maintenance_static_page_generator {
$fullurl = $originalurl;
} else if ($originalurl[0] == '/') {
$rooturl = parse_url($CFG->wwwroot);
$fullurl = $rooturl['scheme'].'://'.$rooturl['host'].$originalurl;
$fullurl = $rooturl['scheme'] . '://' . $rooturl['host'] . $originalurl;
} else {
$fullurl = $baseref.'/'.$originalurl;
$fullurl = $baseref . '/' . $originalurl;
}
$saved = $this->io->save_url_file($fullurl);
@@ -253,7 +252,7 @@ class maintenance_static_page_generator {
$fullurl = (string) new moodle_url($matches[1]);
}
$newurl = $this->io->generate_file_url($fullurl);
$updated = preg_replace(self::PATTERN, ' url('.$newurl.') ', $style);
$updated = preg_replace(self::PATTERN, ' url(' . $newurl . ') ', $style);
$element->setAttribute('style', $updated);
}
}

View File

@@ -61,7 +61,7 @@ class maintenance_static_page_io {
}
if ($result['contents'] === false) {
debugging('Cannot fetch: '.$file);
debugging('Cannot fetch: ' . $file);
$result = ['contents' => '', 'mime' => 'unknown'];
}
return $result;
@@ -85,9 +85,9 @@ class maintenance_static_page_io {
public function get_template_file() {
global $CFG;
if ($this->preview) {
return $this->get_resources_folder().'/climaintenance.html';
return $this->get_resources_folder() . '/climaintenance.html';
} else {
return $CFG->dataroot.'/climaintenance.template.html';
return $CFG->dataroot . '/climaintenance.template.html';
}
}
@@ -102,10 +102,10 @@ class maintenance_static_page_io {
global $CFG;
// If you change the path, also change file auth/outage/bootstrap.php as it does not use this reference.
$dir = $CFG->dataroot.'/auth_outage/climaintenance';
$dir = $CFG->dataroot . '/auth_outage/climaintenance';
if ($this->preview) {
$dir = $dir.'/preview';
$dir = $dir . '/preview';
}
return $dir;
}
@@ -155,18 +155,18 @@ class maintenance_static_page_io {
$dir = realpath($dir);
$safedir = $this->get_resources_folder();
if (substr($dir, 0, strlen($safedir)) !== $safedir) {
throw new invalid_parameter_exception('Unsafe to delete: '.$dir);
throw new invalid_parameter_exception('Unsafe to delete: ' . $dir);
}
if (!is_dir($dir)) {
throw new coding_exception('Not a directory: '.$dir);
throw new coding_exception('Not a directory: ' . $dir);
}
$files = scandir($dir);
foreach ($files as $file) {
if (($file == '.') || ($file == '..')) {
continue;
}
$file = $dir.'/'.$file;
$file = $dir . '/' . $file;
if (is_file($file)) {
unlink($file);
continue;
@@ -175,7 +175,7 @@ class maintenance_static_page_io {
$this->delete_directory_recursively($file);
continue;
}
throw new coding_exception('Not a file or directory: '.$file);
throw new coding_exception('Not a file or directory: ' . $file);
}
rmdir($dir);
}
@@ -211,7 +211,7 @@ class maintenance_static_page_io {
global $CFG;
if (!self::is_url($url)) {
debugging('Found a relative url ('.$url.') -- is it using moodle_url()?');
debugging('Found a relative url (' . $url . ') -- is it using moodle_url()?');
return null; // Leave hardcoded URLs as it is.
}
@@ -227,12 +227,12 @@ class maintenance_static_page_io {
$data = self::file_get_data($url);
$mime = trim(base64_encode($data['mime']), '=');
$url = sha1($data['contents']).'.'.$mime;
$filepath = $this->get_resources_folder().'/'.$url;
$url = sha1($data['contents']) . '.' . $mime;
$filepath = $this->get_resources_folder() . '/' . $url;
file_put_contents($filepath, $data['contents']);
if ($this->preview) {
$url = 'preview/'.$url;
$url = 'preview/' . $url;
}
return ['file' => $filepath, 'url' => $url];

View File

@@ -26,7 +26,7 @@ use invalid_parameter_exception;
use stdClass;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../lib.php');
require_once(__DIR__ . '/../../lib.php');
/**
* outagelib class.
@@ -37,7 +37,6 @@ require_once(__DIR__.'/../../lib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class outagelib {
/** Outage start. */
const OUTAGE_START = '<!-- OUTAGESTART -->';
@@ -135,7 +134,7 @@ class outagelib {
$renderer = $PAGE->get_renderer('auth_outage');
return $renderer->render_warningbar($active, $time, false, $preview);
} catch (Exception $e) {
debugging('Exception occured while injecting our code: '.$e->getMessage());
debugging('Exception occured while injecting our code: ' . $e->getMessage());
debugging($e->getTraceAsString(), DEBUG_DEVELOPER);
}
}
@@ -230,7 +229,7 @@ class outagelib {
$message = get_config('moodle', 'maintenance_message');
if ($message) {
debugging('Disabling $CFG->maintenance_message to allow our template page to take place.');
debugging('Previous value: '.$message);
debugging('Previous value: ' . $message);
// We cannot do much if forced config, but the logs will show the error.
unset_config('maintenance_message');
}
@@ -253,7 +252,7 @@ class outagelib {
self::$injectcalled = true;
// Do not inject into admin/settings.php.
if ($_SERVER['SCRIPT_NAME'] == '/'.$CFG->admin.'/settings.php') {
if ($_SERVER['SCRIPT_NAME'] == '/' . $CFG->admin . '/settings.php') {
if (optional_param('section', '', PARAM_RAW) === 'additionalhtml') {
return false;
}
@@ -381,7 +380,7 @@ EOT;
*/
public static function update_climaintenance_code($outage) {
global $CFG;
$file = $CFG->dataroot.'/climaintenance.php';
$file = $CFG->dataroot . '/climaintenance.php';
if (!is_null($outage) && !($outage instanceof outage)) {
throw new coding_exception('$outage must be null or an outage object.');
@@ -401,7 +400,7 @@ EOT;
$dir = dirname($file);
if (!file_exists($dir) || !is_dir($dir)) {
throw new file_exception('Directory must exists: '.$dir);
throw new file_exception('Directory must exists: ' . $dir);
}
file_put_contents($file, $code);
}
@@ -417,8 +416,10 @@ EOT;
$message = [];
if (trim(self::get_config()->allowedips) != ''
&& (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded)) {
if (
trim(self::get_config()->allowedips) != ''
&& (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded)
) {
$message[] = get_string('configurationwarning', 'auth_outage');
}

View File

@@ -22,7 +22,7 @@ use html_writer;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir . '/tablelib.php');
/**
* base_table class.
@@ -58,7 +58,7 @@ class base_table extends flexible_table {
global $PAGE;
$id = (is_null($id) ? self::$autoid++ : $id);
parent::__construct('auth_outage_manage_'.$id);
parent::__construct('auth_outage_manage_' . $id);
$this->define_baseurl($PAGE->url);
$this->set_attribute('class', 'generaltable admintable');
@@ -77,7 +77,7 @@ class base_table extends flexible_table {
// View button.
$buttons .= html_writer::link(
new moodle_url('/auth/outage/info.php', ['id' => $outage->id]),
$OUTPUT->pix_icon('t/preview', get_string('view'), 'moodle', array('class' => 'iconsmall')),
$OUTPUT->pix_icon('t/preview', get_string('view'), 'moodle', ['class' => 'iconsmall']),
[
'title' => get_string('view'),
'target' => '_blank',
@@ -88,7 +88,7 @@ class base_table extends flexible_table {
if ($editdelete) {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]),
$OUTPUT->pix_icon('t/edit', get_string('edit'), 'moodle', array('class' => 'iconsmall')),
$OUTPUT->pix_icon('t/edit', get_string('edit'), 'moodle', ['class' => 'iconsmall']),
['title' => get_string('edit')]
);
}
@@ -96,7 +96,7 @@ class base_table extends flexible_table {
// Clone button.
$buttons .= html_writer::link(
new moodle_url('/auth/outage/edit.php', ['clone' => $outage->id]),
$OUTPUT->pix_icon('t/copy', get_string('clone', 'auth_outage'), 'moodle', array('class' => 'iconsmall')),
$OUTPUT->pix_icon('t/copy', get_string('clone', 'auth_outage'), 'moodle', ['class' => 'iconsmall']),
['title' => get_string('clone', 'auth_outage')]
);
@@ -104,7 +104,7 @@ class base_table extends flexible_table {
if ($outage->is_ongoing()) {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/finish.php', ['id' => $outage->id]),
$OUTPUT->pix_icon('t/check', get_string('finish', 'auth_outage'), 'moodle', array('class' => 'iconsmall')),
$OUTPUT->pix_icon('t/check', get_string('finish', 'auth_outage'), 'moodle', ['class' => 'iconsmall']),
['title' => get_string('finish', 'auth_outage')]
);
}
@@ -113,7 +113,7 @@ class base_table extends flexible_table {
if ($editdelete) {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]),
$OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle', array('class' => 'iconsmall')),
$OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle', ['class' => 'iconsmall']),
['title' => get_string('delete')]
);
}

View File

@@ -19,7 +19,7 @@ namespace auth_outage\output\manage;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir . '/tablelib.php');
/**
* history_table class.
@@ -45,8 +45,7 @@ class history_table extends base_table {
get_string('tableheaderdurationactual', 'auth_outage'),
get_string('tableheadertitle', 'auth_outage'),
get_string('actions'),
]
);
]);
$this->setup();
}

View File

@@ -21,7 +21,7 @@ use html_writer;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir . '/tablelib.php');
/**
* planned_table class.

View File

@@ -45,7 +45,7 @@ class renderer extends plugin_renderer_base {
$viewbag['viewfile'] = $view;
unset($view);
require($CFG->dirroot.'/auth/outage/views/'.$viewbag['viewfile']);
require($CFG->dirroot . '/auth/outage/views/' . $viewbag['viewfile']);
}
/**
@@ -88,8 +88,8 @@ class renderer extends plugin_renderer_base {
* @return string HTML for the page.
*/
public function renderdeleteconfirmation(outage $outage) {
return $this->rendersubtitle('outagedelete').
html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage')).
return $this->rendersubtitle('outagedelete') .
html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage')) .
$this->renderoutage($outage, false);
}
@@ -99,8 +99,8 @@ class renderer extends plugin_renderer_base {
* @return string HTML for the page.
*/
public function renderfinishconfirmation(outage $outage) {
return $this->rendersubtitle('outagefinish').
html_writer::tag('p', get_string('outagefinishwarning', 'auth_outage')).
return $this->rendersubtitle('outagefinish') .
html_writer::tag('p', get_string('outagefinishwarning', 'auth_outage')) .
$this->renderoutage($outage, false);
}
@@ -147,7 +147,7 @@ class renderer extends plugin_renderer_base {
$created = core_user::get_user($outage->createdby, 'firstname,lastname', MUST_EXIST);
$created = html_writer::link(
new moodle_url('/user/profile.php', ['id' => $outage->createdby]),
trim($created->firstname.' '.$created->lastname)
trim($created->firstname . ' ' . $created->lastname)
);
}
@@ -157,7 +157,7 @@ class renderer extends plugin_renderer_base {
$modified = core_user::get_user($outage->modifiedby, 'firstname,lastname', MUST_EXIST);
$modified = html_writer::link(
new moodle_url('/user/profile.php', ['id' => $outage->modifiedby]),
trim($modified->firstname.' '.$modified->lastname)
trim($modified->firstname . ' ' . $modified->lastname)
);
}
@@ -185,33 +185,35 @@ class renderer extends plugin_renderer_base {
$start = outagelib::OUTAGE_START;
$end = outagelib::OUTAGE_END;
$outagehtml = html_writer::div(
html_writer::tag('blockquote',
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id])).
html_writer::div(html_writer::tag('i', $outage->get_description())).
html_writer::tag(
'blockquote',
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id])) .
html_writer::div(html_writer::tag('i', $outage->get_description())) .
html_writer::div(
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage').': ').
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage') . ': ') .
format_time($outage->get_warning_duration())
).
) .
html_writer::div(
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage').': ').
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage') . ': ') .
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
).
) .
html_writer::div(
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage').': ').
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage') . ': ') .
format_time($outage->get_duration_planned())
).
) .
html_writer::div(
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage').': ').
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage') . ': ') .
$finished
).
) .
html_writer::div(
html_writer::tag('small',
'Created by '.$created.
', modified by '.$modified.' on '.
html_writer::tag(
'small',
'Created by ' . $created .
', modified by ' . $modified . ' on ' .
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
)
).
($buttons ? html_writer::div($linkedit.$linkdelete) : '')
) .
($buttons ? html_writer::div($linkedit . $linkdelete) : '')
)
);
return $start . $outagehtml . $end;

View File

@@ -25,7 +25,6 @@ namespace auth_outage\privacy;
*/
class provider implements
\core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
@@ -38,5 +37,4 @@ class provider implements
public static function get_reason(): string {
return 'privacy:no_data_reason';
}
}