diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37e6c41..6445d5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,11 @@ jobs: fail-fast: false matrix: include: - - php: '8.3' + - php: '8.4' moodle-branch: 'main' + database: 'mariadb' + - php: '8.4' + moodle-branch: 'MOODLE_501_STABLE' database: 'pgsql' - php: '8.3' moodle-branch: 'MOODLE_500_STABLE' @@ -23,7 +26,7 @@ jobs: services: postgres: - image: postgres:14 + image: postgres:16 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' @@ -36,7 +39,7 @@ jobs: - 5432:5432 mariadb: - image: mariadb:10 + image: mariadb:10.11 env: MYSQL_USER: 'root' MYSQL_ALLOW_EMPTY_PASSWORD: "true" @@ -79,10 +82,6 @@ jobs: if: ${{ always() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - - name: PHP Mess Detector if: ${{ always() }} run: moodle-plugin-ci phpmd diff --git a/addcategory.php b/addcategory.php index 6fcfa19..47bcb3f 100644 --- a/addcategory.php +++ b/addcategory.php @@ -47,8 +47,12 @@ $queryparams['categoryid'] = $id; $isadding = false; // Editing an existing category. - $category = $DB->get_record('report_customsql_categories', - ['id' => $id], '*', MUST_EXIST); + $category = $DB->get_record( + 'report_customsql_categories', + ['id' => $id], + '*', + MUST_EXIST, + ); } else { $queryparams['categoryid'] = null; $isadding = true; diff --git a/categoryadd_form.php b/categoryadd_form.php index 9f9e36e..cc9c4c6 100644 --- a/categoryadd_form.php +++ b/categoryadd_form.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class report_customsql_addcategory_form extends moodleform { - #[\Override] public function definition() { global $CFG, $DB; @@ -74,8 +73,13 @@ public function validation($data, $files) { if (!isset($data['id'])) { $data['id'] = 0;// Ensure id to check against. } - if ($DB->get_record_select('report_customsql_categories', - 'name = ? AND id != ?', [$data['name'], $data['id']])) { + if ( + $DB->get_record_select( + 'report_customsql_categories', + 'name = ? AND id != ?', + [$data['name'], $data['id']], + ) + ) { $errors['name'] = get_string('categoryexists', 'report_customsql'); } } diff --git a/categorydelete.php b/categorydelete.php index 74ba5e3..08fab32 100644 --- a/categorydelete.php +++ b/categorydelete.php @@ -31,8 +31,12 @@ $id = required_param('id', PARAM_INT); // Start the page. -admin_externalpage_setup('report_customsql', '', ['id' => $id], - '/report/customsql/categorydelete.php'); +admin_externalpage_setup( + 'report_customsql', + '', + ['id' => $id], + '/report/customsql/categorydelete.php', +); $context = context_system::instance(); require_capability('report/customsql:managecategories', $context); @@ -56,10 +60,25 @@ } echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('deletecategoryareyousure', 'report_customsql')); -echo html_writer::tag('p', get_string('categorynamex', 'report_customsql', $category->name )); -echo $OUTPUT->confirm(get_string('deletecategoryyesno', 'report_customsql'), - new single_button(report_customsql_url('categorydelete.php', - ['id' => $id, 'confirm' => 1, 'sesskey' => sesskey()]), get_string('yes')), - new single_button(report_customsql_url('index.php'), get_string('no'))); +echo $OUTPUT->heading( + get_string('deletecategoryareyousure', 'report_customsql') +); +echo html_writer::tag( + 'p', + get_string('categorynamex', 'report_customsql', $category->name), +); +echo $OUTPUT->confirm( + get_string('deletecategoryyesno', 'report_customsql'), + new single_button( + report_customsql_url( + 'categorydelete.php', + ['id' => $id, + 'confirm' => 1, + 'sesskey' => sesskey(), + ] + ), + get_string('yes') + ), + new single_button(report_customsql_url('index.php'), get_string('no')) +); echo $OUTPUT->footer(); diff --git a/classes/event/query_deleted.php b/classes/event/query_deleted.php index ba7012c..e8f816c 100644 --- a/classes/event/query_deleted.php +++ b/classes/event/query_deleted.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class query_deleted extends \core\event\base { - #[\Override] protected function init() { $this->data['crud'] = 'd'; diff --git a/classes/event/query_edited.php b/classes/event/query_edited.php index ad84c72..96a1478 100644 --- a/classes/event/query_edited.php +++ b/classes/event/query_edited.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class query_edited extends \core\event\base { - #[\Override] protected function init() { $this->data['crud'] = 'u'; diff --git a/classes/event/query_viewed.php b/classes/event/query_viewed.php index e3d79fa..2ddc6b6 100644 --- a/classes/event/query_viewed.php +++ b/classes/event/query_viewed.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class query_viewed extends \core\event\base { - #[\Override] protected function init() { $this->data['crud'] = 'r'; diff --git a/classes/external/get_users.php b/classes/external/get_users.php index bb2c6f4..c8d2569 100644 --- a/classes/external/get_users.php +++ b/classes/external/get_users.php @@ -54,8 +54,12 @@ public static function execute_parameters(): external_function_parameters { public static function execute(string $query, string $capability): array { global $CFG, $DB; - [$query, $capability] = array_values(self::validate_parameters(self::execute_parameters(), - ['query' => $query, 'capability' => $capability])); + [$query, $capability] = array_values( + self::validate_parameters( + self::execute_parameters(), + ['query' => $query, 'capability' => $capability], + ) + ); $context = \context_system::instance(); self::validate_context($context); @@ -63,8 +67,16 @@ public static function execute(string $query, string $capability): array { if (class_exists('\core_user\fields')) { $extrafields = \core_user\fields::for_identity($context, false)->get_required_fields(); - $fields = \core_user\fields::for_identity($context, - false)->with_userpic()->get_sql('u', false, '', '', false)->selects; + $fields = \core_user\fields::for_identity( + $context, + false + )->with_userpic()->get_sql( + 'u', + false, + '', + '', + false, + )->selects; } else { $extrafields = get_extra_user_fields($context); $fields = \user_picture::fields('u', $extrafields); @@ -148,6 +160,7 @@ public static function execute_returns(): external_description { 'identity' => new external_value(PARAM_RAW, 'Additional user identifying info.'), 'hasidentity' => new external_value(PARAM_BOOL, 'Whether identity is non-blank.'), 'profileimageurlsmall' => new external_value(PARAM_RAW, 'URL of the user profile image.'), - ])); + ]) + ); } } diff --git a/classes/local/category.php b/classes/local/category.php index bc011e7..d2ddfb2 100644 --- a/classes/local/category.php +++ b/classes/local/category.php @@ -79,7 +79,7 @@ public function load_queries_data(array $queries): void { * @return \stdClass[] All queries of type. */ public static function get_reports_of_a_particular_runtype(array $queries, string $type) { - return array_filter($queries, function($query) use ($type) { + return array_filter($queries, function ($query) use ($type) { return $query->runable == $type; }, ARRAY_FILTER_USE_BOTH); } @@ -91,7 +91,7 @@ public static function get_reports_of_a_particular_runtype(array $queries, strin * @return \stdClass[] queries the current user is allowed to see. */ public static function filter_reports_by_capability(array $queries) { - return array_filter($queries, function($query) { + return array_filter($queries, function ($query) { return has_capability($query->capability ?? 'moodle/site:config', \context_system::instance()); }, ARRAY_FILTER_USE_BOTH); } diff --git a/classes/output/category.php b/classes/output/category.php index 4a50638..6ac43d9 100644 --- a/classes/output/category.php +++ b/classes/output/category.php @@ -67,8 +67,16 @@ class category implements renderable, templatable { * @param bool $addnewquerybtn Show 'Add new query' button or not. * @param moodle_url|null $returnurl Return url. */ - public function __construct(report_category $category, context $context, bool $expandable = false, int $showcat = 0, - int $hidecat = 0, bool $showonlythislink = false, bool $addnewquerybtn = true, ?moodle_url $returnurl = null) { + public function __construct( + report_category $category, + context $context, + bool $expandable = false, + int $showcat = 0, + int $hidecat = 0, + bool $showonlythislink = false, + bool $addnewquerybtn = true, + ?moodle_url $returnurl = null + ) { $this->category = $category; $this->context = $context; $this->expandable = $expandable; @@ -108,8 +116,12 @@ public function export_for_template(renderer_base $output) { if ($this->addnewquerybtn && has_capability('report/customsql:definequeries', $this->context)) { $addnewqueryurl = report_customsql_url('edit.php', ['categoryid' => $this->category->get_id(), 'returnurl' => $this->returnurl->out_as_local_url(false)]); - $addquerybutton = $output->single_button($addnewqueryurl, get_string('addreport', 'report_customsql'), 'post', - ['class' => 'mb-1']); + $addquerybutton = $output->single_button( + $addnewqueryurl, + get_string('addreport', 'report_customsql'), + 'post', + ['class' => 'mb-1'], + ); } return [ diff --git a/classes/output/index_page.php b/classes/output/index_page.php index 98761f8..f5f2141 100644 --- a/classes/output/index_page.php +++ b/classes/output/index_page.php @@ -59,8 +59,14 @@ class index_page implements renderable, templatable { * @param int $showcat Showing Category Id. * @param int $hidecat Hiding Category Id. */ - public function __construct(array $categories, array $queries, context $context, moodle_url $returnurl, - int $showcat = 0, int $hidecat = 0) { + public function __construct( + array $categories, + array $queries, + context $context, + moodle_url $returnurl, + int $showcat = 0, + int $hidecat = 0 + ) { $this->categories = $categories; $this->queries = $queries; $this->context = $context; @@ -77,19 +83,33 @@ public function export_for_template(renderer_base $output) { $category = new report_category($record); $queries = $grouppedqueries[$record->id] ?? []; $category->load_queries_data($queries); - $categorywidget = new category($category, $this->context, true, $this->showcat, $this->hidecat, true, - false, $this->returnurl); + $categorywidget = new category( + $category, + $this->context, + true, + $this->showcat, + $this->hidecat, + true, + false, + $this->returnurl, + ); $categoriesdata[] = ['category' => $output->render($categorywidget)]; } $addquerybutton = $managecategorybutton = ''; if (has_capability('report/customsql:definequeries', $this->context)) { - $addquerybutton = $output->single_button(report_customsql_url('edit.php', ['returnurl' => $this->returnurl]), - get_string('addreport', 'report_customsql'), 'post', ['class' => 'mb-1']); + $addquerybutton = $output->single_button( + report_customsql_url('edit.php', ['returnurl' => $this->returnurl]), + get_string('addreport', 'report_customsql'), + 'post', + ['class' => 'mb-1'], + ); } if (has_capability('report/customsql:managecategories', $this->context)) { - $managecategorybutton = $output->single_button(report_customsql_url('manage.php'), - get_string('managecategories', 'report_customsql')); + $managecategorybutton = $output->single_button( + report_customsql_url('manage.php'), + get_string('managecategories', 'report_customsql') + ); } $data = [ diff --git a/classes/output/renderer.php b/classes/output/renderer.php index f60d53b..10f1d81 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -30,7 +30,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class renderer extends plugin_renderer_base { - /** * Output the standard action icons (edit, delete and back to list) for a report. * @@ -45,19 +44,22 @@ public function render_report_actions(stdClass $report, stdClass $category, cont if (has_capability('report/customsql:definequeries', $context)) { $reporturl = report_customsql_url('view.php', ['id' => $report->id]); $editaction = $this->action_link( - report_customsql_url('edit.php', ['id' => $report->id, 'returnurl' => $reporturl->out_as_local_url(false)]), - $this->pix_icon('t/edit', '') . ' ' . - get_string('editreportx', 'report_customsql', format_string($report->displayname))); + report_customsql_url('edit.php', ['id' => $report->id, 'returnurl' => $reporturl->out_as_local_url(false)]), + $this->pix_icon('t/edit', '') . ' ' . + get_string('editreportx', 'report_customsql', format_string($report->displayname)) + ); $deleteaction = $this->action_link( - report_customsql_url('delete.php', ['id' => $report->id, 'returnurl' => $reporturl->out_as_local_url(false)]), - $this->pix_icon('t/delete', '') . ' ' . - get_string('deletereportx', 'report_customsql', format_string($report->displayname))); + report_customsql_url('delete.php', ['id' => $report->id, 'returnurl' => $reporturl->out_as_local_url(false)]), + $this->pix_icon('t/delete', '') . ' ' . + get_string('deletereportx', 'report_customsql', format_string($report->displayname)) + ); } $backtocategoryaction = $this->action_link( - report_customsql_url('category.php', ['id' => $category->id]), - $this->pix_icon('t/left', '') . - get_string('backtocategory', 'report_customsql', $category->name)); + report_customsql_url('category.php', ['id' => $category->id]), + $this->pix_icon('t/left', '') . + get_string('backtocategory', 'report_customsql', $category->name) + ); $context = [ 'editaction' => $editaction, diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index ec0d4a7..b5f969e 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -35,12 +35,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements - // This plugin has data. \core_privacy\local\metadata\provider, - // This plugin currently implements the original plugin\provider interface. - \core_privacy\local\request\plugin\provider, - \core_privacy\local\request\core_userlist_provider { - + // This plugin currently implements the original plugin_provider interface. + \core_privacy\local\request\core_userlist_provider, + // This plugin has data. + \core_privacy\local\request\plugin\provider { /** * Returns meta data about this system. * @@ -194,8 +193,12 @@ public static function delete_data_for_user(request\approved_contextlist $contex $userid = $contextlist->get_user()->id; $adminuserid = get_admin()->id; - $DB->set_field('report_customsql_queries', 'usermodified', - $adminuserid, ['usermodified' => $userid]); + $DB->set_field( + 'report_customsql_queries', + 'usermodified', + $adminuserid, + ['usermodified' => $userid], + ); } } } @@ -213,10 +216,15 @@ public static function delete_data_for_users(request\approved_userlist $userlist $context = $userlist->get_context(); if ($context->contextlevel === CONTEXT_SYSTEM) { $userids = $userlist->get_userids(); - list($sqlcondition, $params) = $DB->get_in_or_equal($userids); + [$sqlcondition, $params] = $DB->get_in_or_equal($userids); $adminuserid = get_admin()->id; - $DB->set_field_select('report_customsql_queries', 'usermodified', $adminuserid, - 'usermodified ' . $sqlcondition, $params); + $DB->set_field_select( + 'report_customsql_queries', + 'usermodified', + $adminuserid, + 'usermodified ' . $sqlcondition, + $params, + ); } } diff --git a/classes/task/run_reports.php b/classes/task/run_reports.php index f211aa4..5eb1643 100644 --- a/classes/task/run_reports.php +++ b/classes/task/run_reports.php @@ -31,7 +31,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class run_reports extends \core\task\scheduled_task { - /** * Get a descriptive name for this task (shown to admins). * @@ -57,8 +56,8 @@ public function execute() { $timenow = time(); - list($startofthisweek, $startoflastweek) = report_customsql_get_week_starts($timenow); - list($startofthismonth) = report_customsql_get_month_starts($timenow); + [$startofthisweek, $startoflastweek] = report_customsql_get_week_starts($timenow); + [$startofthismonth] = report_customsql_get_month_starts($timenow); mtrace("... Looking for old temp CSV files to delete."); $numdeleted = report_customsql_delete_old_temp_files($startoflastweek); @@ -70,11 +69,16 @@ public function execute() { $dailyreportstorun = report_customsql_get_ready_to_run_daily_reports($timenow); // Get weekly and monthly scheduled reports. - $scheduledreportstorun = $DB->get_records_select('report_customsql_queries', - "(runable = 'weekly' AND lastrun < :startofthisweek) OR - (runable = 'monthly' AND lastrun < :startofthismonth)", - ['startofthisweek' => $startofthisweek, - 'startofthismonth' => $startofthismonth], 'lastrun'); + $scheduledreportstorun = $DB->get_records_select( + 'report_customsql_queries', + "(runable = 'weekly' AND lastrun < :startofthisweek) OR + (runable = 'monthly' AND lastrun < :startofthismonth)", + [ + 'startofthisweek' => $startofthisweek, + 'startofthismonth' => $startofthismonth, + ], + 'lastrun', + ); // All reports ready to run. $reportstorun = array_merge($dailyreportstorun, $scheduledreportstorun); diff --git a/classes/utils.php b/classes/utils.php index 1894431..498dbea 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -24,15 +24,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class utils { - /** * Return the current timestamp, or a fixed timestamp specified by an automated test. * * @return int The timestamp */ public static function time(): int { - if ((defined('BEHAT_SITE_RUNNING') || PHPUNIT_TEST) && - $time = get_config('report_customsql', 'behat_fixed_time')) { + if ( + (defined('BEHAT_SITE_RUNNING') || PHPUNIT_TEST) && + $time = get_config('report_customsql', 'behat_fixed_time') + ) { return $time; } else { return time(); @@ -64,6 +65,5 @@ public static function group_queries_by_category($queries) { * @param array $queries An array of query objects. */ public function get_queries_data($queries) { - } } diff --git a/db/upgrade.php b/db/upgrade.php index db09dd2..c8dadf5 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -34,7 +34,6 @@ function xmldb_report_customsql_upgrade($oldversion) { $dbman = $DB->get_manager(); if ($oldversion < 2012011900) { - // Add field to report_customsql_queries. $table = new xmldb_table('report_customsql_queries'); if ($dbman->table_exists($table)) { @@ -49,11 +48,9 @@ function xmldb_report_customsql_upgrade($oldversion) { } if ($oldversion < 2012092400) { - // Add fields to report_customsql_queries. $table = new xmldb_table('report_customsql_queries'); if ($dbman->table_exists($table)) { - // Define and add the field 'at'. $field = new xmldb_field('at', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'singlerow'); if (!$dbman->field_exists($table, $field)) { @@ -77,8 +74,16 @@ function xmldb_report_customsql_upgrade($oldversion) { if ($oldversion < 2013062300) { require_once($CFG->dirroot . '/report/customsql/locallib.php'); $table = new xmldb_table('report_customsql_queries'); - $field = new xmldb_field('querylimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, 5000, 'queryparams'); + $field = new xmldb_field( + 'querylimit', + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + null, + 5000, + 'queryparams' + ); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -88,7 +93,6 @@ function xmldb_report_customsql_upgrade($oldversion) { } if ($oldversion < 2013102400) { - // Define table report_customsql_categories to be created. $table = new xmldb_table('report_customsql_categories'); @@ -135,8 +139,16 @@ function xmldb_report_customsql_upgrade($oldversion) { if ($oldversion < 2014020300) { require_once($CFG->dirroot . '/report/customsql/locallib.php'); $table = new xmldb_table('report_customsql_queries'); - $field = new xmldb_field('querylimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, 5000, 'queryparams'); + $field = new xmldb_field( + 'querylimit', + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + null, + 5000, + 'queryparams' + ); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -146,7 +158,6 @@ function xmldb_report_customsql_upgrade($oldversion) { } if ($oldversion < 2015062900) { - // Define field descriptionformat to be added to report_customsql_queries. $table = new xmldb_table('report_customsql_queries'); $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1', 'description'); @@ -161,7 +172,6 @@ function xmldb_report_customsql_upgrade($oldversion) { } if ($oldversion < 2016011800) { - // Define field customdir to be added to report_customsql_queries. $table = new xmldb_table('report_customsql_queries'); $field = new xmldb_field('customdir', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'categoryid'); @@ -203,8 +213,11 @@ function xmldb_report_customsql_upgrade($oldversion) { $progressbar = new progress_bar('report_customsql_emailto_upgrade', 500, true); $done = 0; foreach ($queries as $query) { - $progressbar->update($done, $total, - "Updating ad-hoc DB query email recipients - {$done}/{$total} (id = {$query->id})."); + $progressbar->update( + $done, + $total, + "Updating ad-hoc DB query email recipients - {$done}/{$total} (id = {$query->id})." + ); $queryuserids = []; foreach (preg_split("/[\s,;]+/", $query->emailto) as $username) { @@ -235,8 +248,16 @@ function xmldb_report_customsql_upgrade($oldversion) { } // Define field timecreated to be added to report_customsql_queries. - $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, - XMLDB_NOTNULL, null, '0', 'usermodified'); + $field = new xmldb_field( + 'timecreated', + XMLDB_TYPE_INTEGER, + '10', + null, + XMLDB_NOTNULL, + null, + '0', + 'usermodified' + ); // Conditionally launch add field timecreated. if (!$dbman->field_exists($table, $field)) { @@ -244,8 +265,16 @@ function xmldb_report_customsql_upgrade($oldversion) { } // Define field timemodified to be added to report_customsql_queries. - $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, - XMLDB_NOTNULL, null, '0', 'timecreated'); + $field = new xmldb_field( + 'timemodified', + XMLDB_TYPE_INTEGER, + '10', + null, + XMLDB_NOTNULL, + null, + '0', + 'timecreated' + ); // Conditionally launch add field timemodified. if (!$dbman->field_exists($table, $field)) { diff --git a/delete.php b/delete.php index e9ed5a8..d17cf93 100644 --- a/delete.php +++ b/delete.php @@ -29,8 +29,12 @@ $id = required_param('id', PARAM_INT); $returnurl = optional_param('returnurl', '', PARAM_LOCALURL); -admin_externalpage_setup('report_customsql', '', ['id' => $id], - '/report/customsql/delete.php'); +admin_externalpage_setup( + 'report_customsql', + '', + ['id' => $id], + '/report/customsql/delete.php', +); $context = context_system::instance(); require_capability('report/customsql:definequeries', $context); @@ -63,20 +67,36 @@ $runnableoptions = report_customsql_runable_options(); // Start the page. -echo $OUTPUT->header(). - $OUTPUT->heading(get_string('deleteareyousure', 'report_customsql')). +echo $OUTPUT->header() . + $OUTPUT->heading(get_string('deleteareyousure', 'report_customsql')) . - html_writer::tag('p', get_string('displaynamex', 'report_customsql', - html_writer::tag('b', format_string($report->displayname)))). - html_writer::tag('p', get_string('querysql', 'report_customsql')). - html_writer::tag('pre', s($report->querysql)). - html_writer::tag('p', get_string('runablex', 'report_customsql', - $runnableoptions[$report->runable])). + html_writer::tag( + 'p', + get_string( + 'displaynamex', + 'report_customsql', + html_writer::tag('b', format_string($report->displayname)) + ) + ) . + html_writer::tag('p', get_string('querysql', 'report_customsql')) . + html_writer::tag('pre', s($report->querysql)) . + html_writer::tag( + 'p', + get_string( + 'runablex', + 'report_customsql', + $runnableoptions[$report->runable], + ) + ) . - $OUTPUT->confirm(get_string('deleteareyousure', 'report_customsql'), - new single_button(report_customsql_url('delete.php', - ['id' => $id, 'confirm' => 1, 'returnurl' => $returnurl->out_as_local_url(false)]), - get_string('yes')), - new single_button($returnurl, get_string('no'))). - - $OUTPUT->footer(); + $OUTPUT->confirm( + get_string('deleteareyousure', 'report_customsql'), + new single_button( + report_customsql_url( + 'delete.php', + ['id' => $id, 'confirm' => 1, 'returnurl' => $returnurl->out_as_local_url(false)], + ), + get_string('yes') + ), + new single_button($returnurl, get_string('no')) + ) . $OUTPUT->footer(); diff --git a/edit.php b/edit.php index e1d8917..1b4e81f 100644 --- a/edit.php +++ b/edit.php @@ -61,7 +61,7 @@ $reportquerysql = $report->querysql; $queryparams = !empty($report->queryparams) ? unserialize($report->queryparams) : []; foreach ($queryparams as $param => $value) { - $report->{'queryparam'.$param} = $value; + $report->{'queryparam' . $param} = $value; } $params['id'] = $id; $category = $DB->get_record('report_customsql_categories', ['id' => $report->categoryid], '*', MUST_EXIST); @@ -128,16 +128,21 @@ } $ok = $DB->update_record('report_customsql_queries', $newreport); if (!$ok) { - throw new moodle_exception('errorupdatingreport', 'report_customsql', - report_customsql_url('edit.php?id=' . $id)); + throw new moodle_exception( + 'errorupdatingreport', + 'report_customsql', + report_customsql_url('edit.php?id=' . $id), + ); } - } else { $newreport->timecreated = $newreport->timemodified; $id = $DB->insert_record('report_customsql_queries', $newreport); if (!$id) { - throw new moodle_exception('errorinsertingreport', 'report_customsql', - report_customsql_url('edit.php')); + throw new moodle_exception( + 'errorinsertingreport', + 'report_customsql', + report_customsql_url('edit.php'), + ); } } diff --git a/edit_form.php b/edit_form.php index cd0f7b5..8436984 100644 --- a/edit_form.php +++ b/edit_form.php @@ -34,7 +34,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class report_customsql_edit_form extends moodleform { - #[\Override] public function definition() { global $CFG; @@ -43,8 +42,12 @@ public function definition() { $customdata = $this->_customdata; $categoryoptions = report_customsql_category_options(); - $mform->addElement('select', 'categoryid', get_string('category', 'report_customsql'), - $categoryoptions); + $mform->addElement( + 'select', + 'categoryid', + get_string('category', 'report_customsql'), + $categoryoptions + ); if ($customdata['forcecategoryid'] && array_key_exists($customdata['forcecategoryid'], $categoryoptions)) { $catdefault = $customdata['forcecategoryid']; } else { @@ -52,20 +55,41 @@ public function definition() { } $mform->setDefault('categoryid', $catdefault); - $mform->addElement('text', 'displayname', - get_string('displayname', 'report_customsql'), ['size' => 80]); - $mform->addRule('displayname', get_string('displaynamerequired', 'report_customsql'), - 'required', null, 'client'); + $mform->addElement( + 'text', + 'displayname', + get_string('displayname', 'report_customsql'), + ['size' => 80] + ); + $mform->addRule( + 'displayname', + get_string('displaynamerequired', 'report_customsql'), + 'required', + null, + 'client' + ); $mform->setType('displayname', PARAM_TEXT); - $mform->addElement('editor', 'description', - get_string('description', 'report_customsql')); + $mform->addElement( + 'editor', + 'description', + get_string('description', 'report_customsql') + ); $mform->setType('description', PARAM_RAW); - $mform->addElement('textarea', 'querysql', get_string('querysql', 'report_customsql'), - ['rows' => '25', 'cols' => '80']); - $mform->addRule('querysql', get_string('querysqlrequried', 'report_customsql'), - 'required', null, 'client'); + $mform->addElement( + 'textarea', + 'querysql', + get_string('querysql', 'report_customsql'), + ['rows' => '25', 'cols' => '80'], + ); + $mform->addRule( + 'querysql', + get_string('querysqlrequried', 'report_customsql'), + 'required', + null, + 'client' + ); $mform->setType('querysql', PARAM_RAW); $mform->addElement('submit', 'verify', get_string('verifyqueryandupdate', 'report_customsql')); @@ -85,33 +109,55 @@ public function definition() { $mform->addElement('static', 'spacer', '', ''); } - $mform->addElement('static', 'note', get_string('note', 'report_customsql'), - get_string('querynote', 'report_customsql', $CFG->wwwroot)); + $mform->addElement( + 'static', + 'note', + get_string('note', 'report_customsql'), + get_string('querynote', 'report_customsql', $CFG->wwwroot) + ); $capabilityoptions = report_customsql_capability_options(); - $mform->addElement('select', 'capability', get_string('whocanaccess', 'report_customsql'), - $capabilityoptions); + $mform->addElement( + 'select', + 'capability', + get_string('whocanaccess', 'report_customsql'), + $capabilityoptions + ); end($capabilityoptions); $mform->setDefault('capability', key($capabilityoptions)); $mform->addElement('text', 'querylimit', get_string('querylimit', 'report_customsql')); $mform->setType('querylimit', PARAM_INT); $mform->setDefault('querylimit', get_config('report_customsql', 'querylimitdefault')); - $mform->addRule('querylimit', get_string('requireint', 'report_customsql'), - 'numeric', null, 'client'); + $mform->addRule( + 'querylimit', + get_string('requireint', 'report_customsql'), + 'numeric', + null, + 'client' + ); $runat = []; if ($hasparameters) { - $runat[] = $mform->createElement('select', 'runable', null, report_customsql_runable_options('manual')); + $runat[] = $mform->createElement('select', 'runable', null, report_customsql_runable_options('manual')); } else { - $runat[] = $mform->createElement('select', 'runable', null, report_customsql_runable_options()); + $runat[] = $mform->createElement('select', 'runable', null, report_customsql_runable_options()); } $runat[] = $mform->createElement('select', 'at', null, report_customsql_daily_at_options()); - $mform->addGroup($runat, 'runablegroup', get_string('runable', 'report_customsql'), - get_string('at', 'report_customsql'), false); + $mform->addGroup( + $runat, + 'runablegroup', + get_string('runable', 'report_customsql'), + get_string('at', 'report_customsql'), + false, + ); - $mform->addElement('checkbox', 'singlerow', get_string('typeofresult', 'report_customsql'), - get_string('onerow', 'report_customsql')); + $mform->addElement( + 'checkbox', + 'singlerow', + get_string('typeofresult', 'report_customsql'), + get_string('onerow', 'report_customsql') + ); $mform->addElement('text', 'customdir', get_string('customdir', 'report_customsql'), 'size = 70'); $mform->setType('customdir', PARAM_PATH); @@ -121,7 +167,7 @@ public function definition() { $options = [ 'ajax' => 'report_customsql/userselector', // Bit of a hack, but the service seems to do what we want. 'multiple' => true, - 'valuehtmlcallback' => function($userid) { + 'valuehtmlcallback' => function ($userid) { global $DB, $OUTPUT; $user = $DB->get_record('user', ['id' => (int) $userid], '*', IGNORE_MISSING); @@ -130,24 +176,32 @@ public function definition() { } if (class_exists('\core_user\fields')) { - $extrafields = \core_user\fields::for_identity(\context_system::instance(), - false)->get_required_fields(); + $extrafields = \core_user\fields::for_identity( + \context_system::instance(), + false + )->get_required_fields(); } else { $extrafields = get_extra_user_fields(context_system::instance()); } return $OUTPUT->render_from_template( - 'report_customsql/form-user-selector-suggestion', - \report_customsql\external\get_users::prepare_result_object( - $user, $extrafields) - ); + 'report_customsql/form-user-selector-suggestion', + \report_customsql\external\get_users::prepare_result_object( + $user, + $extrafields, + ) + ); }, ]; $mform->addElement('autocomplete', 'emailto', get_string('emailto', 'report_customsql'), [], $options); $mform->setType('emailto', PARAM_RAW); - $mform->addElement('select', 'emailwhat', get_string('emailwhat', 'report_customsql'), - report_customsql_email_options()); + $mform->addElement( + 'select', + 'emailwhat', + get_string('emailwhat', 'report_customsql'), + report_customsql_email_options() + ); $mform->disabledIf('singlerow', 'runable', 'eq', 'manual'); $mform->disabledIf('at', 'runable', 'ne', 'daily'); @@ -193,25 +247,24 @@ public function validation($data, $files) { $sql = $data['querysql']; if (report_customsql_contains_bad_word($sql)) { // Obviously evil stuff in the SQL. - $errors['querysql'] = get_string('notallowedwords', 'report_customsql', - implode(', ', report_customsql_bad_words_list())); - + $errors['querysql'] = get_string( + 'notallowedwords', + 'report_customsql', + implode(', ', report_customsql_bad_words_list()), + ); } else if (strpos($sql, ';') !== false) { // Do not allow any semicolons. $errors['querysql'] = get_string('nosemicolon', 'report_customsql'); - } else if ($CFG->prefix != '' && preg_match('/\b' . $CFG->prefix . '\w+/i', $sql)) { // Make sure prefix is prefix_, not explicit. $errors['querysql'] = get_string('noexplicitprefix', 'report_customsql', $CFG->prefix); - } else if (!array_key_exists('runable', $data)) { // This happens when the user enters a query including placehoders, and // selectes Run: Scheduled, and then tries to save the form. $errors['runablegroup'] = get_string('noscheduleifplaceholders', 'report_customsql'); - } else { // Now try running the SQL, and ensure it runs without errors. - $report = new stdClass; + $report = new stdClass(); $report->querysql = $sql; $report->runable = $data['runable']; if ($report->runable === 'daily') { @@ -243,8 +296,10 @@ public function validation($data, $files) { if (!$rows) { $errors['querysql'] = get_string('norowsreturned', 'report_customsql'); } else if ($rows >= 2) { - $errors['querysql'] = get_string('morethanonerowreturned', - 'report_customsql'); + $errors['querysql'] = get_string( + 'morethanonerowreturned', + 'report_customsql', + ); } } // Check the list of users in emailto field. @@ -255,11 +310,17 @@ public function validation($data, $files) { } $rs->close(); } catch (dml_exception $e) { - $errors['querysql'] = get_string('queryfailed', 'report_customsql', - s($e->getMessage() . ' ' . $e->debuginfo)); + $errors['querysql'] = get_string( + 'queryfailed', + 'report_customsql', + s($e->getMessage() . ' ' . $e->debuginfo), + ); } catch (Exception $e) { - $errors['querysql'] = get_string('queryfailed', 'report_customsql', - s($e->getMessage())); + $errors['querysql'] = get_string( + 'queryfailed', + 'report_customsql', + s($e->getMessage()), + ); } } } @@ -274,24 +335,20 @@ public function validation($data, $files) { $path = $data['customdir']; // The path either needs to be a writable directory ... - if (is_dir($path) ) { + if (is_dir($path)) { if (!is_writable($path)) { $errors['customdir'] = get_string('customdirnotwritable', 'report_customsql', s($path)); } - } else if (substr($path, -1) == DIRECTORY_SEPARATOR) { // ... and it must exist... $errors['customdir'] = get_string('customdirmustexist', 'report_customsql', s($path)); - } else { - // ... or be a path to a writable file, or a new file in a writable directory. $dir = dirname($path); if (!is_dir($dir)) { $errors['customdir'] = get_string('customdirnotadirectory', 'report_customsql', s($dir)); } else { - if (file_exists($path)) { if (!is_writable($path)) { $errors['customdir'] = get_string('filenotwritable', 'report_customsql', s($path)); diff --git a/lib.php b/lib.php index 6c3727c..0a26f82 100644 --- a/lib.php +++ b/lib.php @@ -61,8 +61,12 @@ function report_customsql_pluginfile($course, $cm, $context, $filearea, $args, $ $report = $DB->get_record('report_customsql_queries', ['id' => $id]); if (!$report) { - throw new moodle_exception('invalidreportid', 'report_customsql', - report_customsql_url('index.php'), $id); + throw new moodle_exception( + 'invalidreportid', + 'report_customsql', + report_customsql_url('index.php'), + $id, + ); } require_login(); @@ -91,12 +95,15 @@ function report_customsql_pluginfile($course, $cm, $context, $filearea, $args, $ } $csvtimestamp = report_customsql_generate_csv($report, $runtime, true); } - list($csvfilename) = report_customsql_csv_filename($report, $csvtimestamp); + [$csvfilename] = report_customsql_csv_filename($report, $csvtimestamp); $handle = fopen($csvfilename, 'r'); if ($handle === false) { - throw new moodle_exception('unknowndownloadfile', 'report_customsql', - report_customsql_url('view.php?id=' . $id)); + throw new moodle_exception( + 'unknowndownloadfile', + 'report_customsql', + report_customsql_url('view.php?id=' . $id), + ); } $fields = report_customsql_read_csv_row($handle); @@ -113,10 +120,10 @@ function report_customsql_pluginfile($course, $cm, $context, $filearea, $args, $ // can stop downloads from working in some browsers. $filename = str_replace(',', '', $filename); - \core\dataformat::download_data($filename, $dataformat, $fields, $rows->getIterator(), function(array $row) use ($dataformat) { + \core\dataformat::download_data($filename, $dataformat, $fields, $rows->getIterator(), function (array $row) use ($dataformat) { // HTML export content will need escaping. if (strcasecmp($dataformat, 'html') === 0) { - $row = array_map(function($cell) { + $row = array_map(function ($cell) { return s($cell); }, $row); } diff --git a/locallib.php b/locallib.php index 11bc396..de51485 100644 --- a/locallib.php +++ b/locallib.php @@ -68,7 +68,7 @@ function report_customsql_prepare_sql($report, $timenow) { global $USER; $sql = $report->querysql; if ($report->runable != 'manual') { - list($end, $start) = report_customsql_get_starts($report, $timenow); + [$end, $start] = report_customsql_get_starts($report, $timenow); $sql = report_customsql_substitute_time_tokens($sql, $start, $end); } $sql = report_customsql_substitute_user_token($sql, $USER->id); @@ -143,7 +143,7 @@ function report_customsql_generate_csv($report, $timenow, $returnheaderwhenempty $count = 0; foreach ($rs as $row) { if (!$csvtimestamp) { - list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $timenow); + [$csvfilename, $csvtimestamp] = report_customsql_csv_filename($report, $timenow); $csvfilenames[] = $csvfilename; if (!file_exists($csvfilename)) { @@ -161,8 +161,10 @@ function report_customsql_generate_csv($report, $timenow, $returnheaderwhenempty continue; } foreach ($data as $name => $value) { - if (report_customsql_get_element_type($name) == 'date_time_selector' && - report_customsql_is_integer($value) && $value > 0) { + if ( + report_customsql_get_element_type($name) == 'date_time_selector' && + report_customsql_is_integer($value) && $value > 0 + ) { $data[$name] = userdate($value, '%F %T'); } } @@ -232,12 +234,10 @@ function report_customsql_is_integer($value) { function report_customsql_csv_filename($report, $timenow) { if ($report->runable == 'manual') { return report_customsql_temp_cvs_name($report->id, $timenow); - } else if ($report->singlerow) { return report_customsql_accumulating_cvs_name($report->id); - } else { - list($timestart) = report_customsql_get_starts($report, $timenow); + [$timestart] = report_customsql_get_starts($report, $timenow); return report_customsql_scheduled_cvs_name($report->id, $timestart); } } @@ -251,10 +251,12 @@ function report_customsql_csv_filename($report, $timenow) { */ function report_customsql_temp_cvs_name($reportid, $timestamp) { global $CFG; - $path = 'admin_report_customsql/temp/'.$reportid; + $path = 'admin_report_customsql/temp/' . $reportid; make_upload_directory($path); - return [$CFG->dataroot.'/'.$path.'/'.\core_date::strftime('%Y%m%d-%H%M%S', $timestamp).'.csv', - $timestamp]; + return [ + $CFG->dataroot . '/' . $path . '/' . \core_date::strftime('%Y%m%d-%H%M%S', $timestamp) . '.csv', + $timestamp, + ]; } /** @@ -266,10 +268,12 @@ function report_customsql_temp_cvs_name($reportid, $timestamp) { */ function report_customsql_scheduled_cvs_name($reportid, $timestart) { global $CFG; - $path = 'admin_report_customsql/'.$reportid; + $path = 'admin_report_customsql/' . $reportid; make_upload_directory($path); - return [$CFG->dataroot.'/'.$path.'/'.\core_date::strftime('%Y%m%d-%H%M%S', $timestart).'.csv', - $timestart]; + return [ + $CFG->dataroot . '/' . $path . '/' . \core_date::strftime('%Y%m%d-%H%M%S', $timestart) . '.csv', + $timestart, + ]; } /** @@ -280,9 +284,9 @@ function report_customsql_scheduled_cvs_name($reportid, $timestart) { */ function report_customsql_accumulating_cvs_name($reportid) { global $CFG; - $path = 'admin_report_customsql/'.$reportid; + $path = 'admin_report_customsql/' . $reportid; make_upload_directory($path); - return [$CFG->dataroot.'/'.$path.'/accumulate.csv', 0]; + return [$CFG->dataroot . '/' . $path . '/accumulate.csv', 0]; } /** @@ -296,12 +300,18 @@ function report_customsql_get_archive_times($report) { if ($report->runable == 'manual' || $report->singlerow) { return []; } - $files = glob($CFG->dataroot.'/admin_report_customsql/'.$report->id.'/*.csv'); + $files = glob($CFG->dataroot . '/admin_report_customsql/' . $report->id . '/*.csv'); $archivetimes = []; foreach ($files as $file) { if (preg_match('|/(\d\d\d\d)(\d\d)(\d\d)-(\d\d)(\d\d)(\d\d)\.csv$|', $file, $matches)) { - $archivetimes[] = mktime($matches[4], $matches[5], $matches[6], $matches[2], - $matches[3], $matches[1]); + $archivetimes[] = mktime( + $matches[4], + $matches[5], + $matches[6], + $matches[2], + $matches[3], + $matches[1], + ); } } rsort($archivetimes); @@ -430,7 +440,7 @@ function report_customsql_bad_words_list() { * @param string $string The string to check. */ function report_customsql_contains_bad_word($string) { - return preg_match('/\b('.implode('|', report_customsql_bad_words_list()).')\b/i', $string); + return preg_match('/\b(' . implode('|', report_customsql_bad_words_list()) . ')\b/i', $string); } /** @@ -440,7 +450,8 @@ function report_customsql_contains_bad_word($string) { */ function report_customsql_log_delete($id) { $event = \report_customsql\event\query_deleted::create( - ['objectid' => $id, 'context' => context_system::instance()]); + ['objectid' => $id, 'context' => context_system::instance()] + ); $event->trigger(); } @@ -452,7 +463,8 @@ function report_customsql_log_delete($id) { */ function report_customsql_log_edit($id) { $event = \report_customsql\event\query_edited::create( - ['objectid' => $id, 'context' => context_system::instance()]); + ['objectid' => $id, 'context' => context_system::instance()] + ); $event->trigger(); } @@ -464,7 +476,8 @@ function report_customsql_log_edit($id) { */ function report_customsql_log_view($id) { $event = \report_customsql\event\query_viewed::create( - ['objectid' => $id, 'context' => context_system::instance()]); + ['objectid' => $id, 'context' => context_system::instance()] + ); $event->trigger(); } @@ -477,8 +490,10 @@ function report_customsql_log_view($id) { */ function report_customsql_get_reports_for($categoryid, $type) { global $DB; - $records = $DB->get_records('report_customsql_queries', - ['runable' => $type, 'categoryid' => $categoryid]); + $records = $DB->get_records( + 'report_customsql_queries', + ['runable' => $type, 'categoryid' => $categoryid], + ); return report_customsql_sort_reports_by_displayname($records); } @@ -510,21 +525,41 @@ function report_customsql_print_reports_for($reports, $type) { } echo html_writer::start_tag('p'); - echo html_writer::tag('a', format_string($report->displayname), - ['href' => report_customsql_url('view.php?id=' . $report->id)]). - ' ' . report_customsql_time_note($report, 'span'); + echo html_writer::tag( + 'a', + format_string($report->displayname), + ['href' => report_customsql_url('view.php?id=' . $report->id)], + ) . ' ' . report_customsql_time_note($report, 'span'); if ($canedit) { $imgedit = $OUTPUT->pix_icon('t/edit', get_string('edit')); $imgdelete = $OUTPUT->pix_icon('t/delete', get_string('delete')); - echo ' '.html_writer::tag('span', get_string('availableto', 'report_customsql', - $capabilities[$report->capability]), - ['class' => 'admin_note']) . ' ' . + echo ' ' . html_writer::tag( + 'span', + get_string( + 'availableto', + 'report_customsql', + $capabilities[$report->capability], + ), + ['class' => 'admin_note'] + ) . ' ' . html_writer::tag('a', $imgedit, [ - 'title' => get_string('editreportx', 'report_customsql', format_string($report->displayname)), - 'href' => report_customsql_url('edit.php?id='.$report->id)]) . ' ' . - html_writer::tag('a', $imgdelete, - ['title' => get_string('deletereportx', 'report_customsql', format_string($report->displayname)), - 'href' => report_customsql_url('delete.php?id=' . $report->id)]); + 'title' => get_string( + 'editreportx', + 'report_customsql', + format_string($report->displayname) + ), + 'href' => report_customsql_url('edit.php?id=' . $report->id)]) . ' ' . + html_writer::tag( + 'a', + $imgdelete, + ['title' => get_string( + 'deletereportx', + 'report_customsql', + format_string($report->displayname) + ), + 'href' => report_customsql_url('delete.php?id=' . $report->id), + ] + ); } echo html_writer::end_tag('p'); echo "\n"; @@ -548,7 +583,6 @@ function report_customsql_get_table_headers($row) { if (substr($colname, -9) === ' link url' && isset($colnames[substr($colname, 0, -9)])) { // This is a link_url column for another column. Skip. $linkcolumns[$key] = -1; - } else if (isset($colnames[$colname . ' link url'])) { $colheaders[] = $colname; $linkcolumns[$key] = array_search($colname . ' link url', $row); @@ -602,11 +636,10 @@ function report_customsql_display_row($row, $linkcolumns) { */ function report_customsql_time_note($report, $tag) { if ($report->lastrun) { - $a = new stdClass; + $a = new stdClass(); $a->lastrun = userdate($report->lastrun); $a->lastexecutiontime = $report->lastexecutiontime / 1000; $note = get_string('lastexecuted', 'report_customsql', $a); - } else { $note = get_string('notrunyet', 'report_customsql'); } @@ -630,8 +663,13 @@ function report_customsql_pretify_column_names($row, $querysql) { foreach (get_object_vars($row) as $colname => $ignored) { // Databases tend to return the columns lower-cased. // Try to get the original case from the query. - if (preg_match('~SELECT.*?\s(' . preg_quote($colname, '~') . ')\b~is', - $querysql, $matches)) { + if ( + preg_match( + '~SELECT.*?\s(' . preg_quote($colname, '~') . ')\b~is', + $querysql, + $matches + ) + ) { $colname = $matches[1]; } @@ -654,9 +692,9 @@ function report_customsql_write_csv_row($handle, $data) { $value = str_replace('%%Q%%', '?', $value); $value = str_replace('%%C%%', ':', $value); $value = str_replace('%%S%%', ';', $value); - $escapeddata[] = '"'.str_replace('"', '""', $value).'"'; + $escapeddata[] = '"' . str_replace('"', '""', $value) . '"'; } - fwrite($handle, implode(',', $escapeddata)."\r\n"); + fwrite($handle, implode(',', $escapeddata) . "\r\n"); } /** @@ -689,10 +727,20 @@ function report_customsql_read_csv_row($handle) { * @param stdClass $report The report record. * @return void */ -function report_customsql_start_csv($handle, $firstrow, $report) { - $colnames = report_customsql_pretify_column_names($firstrow, $report->querysql); +function report_customsql_start_csv( + $handle, + $firstrow, + $report +) { + $colnames = report_customsql_pretify_column_names( + $firstrow, + $report->querysql + ); if ($report->singlerow) { - array_unshift($colnames, get_string('queryrundate', 'report_customsql')); + array_unshift( + $colnames, + get_string('queryrundate', 'report_customsql') + ); } report_customsql_write_csv_row($handle, $colnames); } @@ -705,15 +753,30 @@ function report_customsql_start_csv($handle, $firstrow, $report) { * @return array with two elements: the timestamp for hour $at today (where today * is defined by $timenow) and the timestamp for hour $at yesterday. */ -function report_customsql_get_daily_time_starts($timenow, $at) { +function report_customsql_get_daily_time_starts( + $timenow, + $at +) { $hours = $at; $minutes = 0; $dateparts = getdate($timenow); return [ - mktime((int)$hours, (int)$minutes, 0, - $dateparts['mon'], $dateparts['mday'], $dateparts['year']), - mktime((int)$hours, (int)$minutes, 0, - $dateparts['mon'], $dateparts['mday'] - 1, $dateparts['year']), + mktime( + (int)$hours, + (int)$minutes, + 0, + $dateparts['mon'], + $dateparts['mday'], + $dateparts['year'] + ), + mktime( + (int)$hours, + (int)$minutes, + 0, + $dateparts['mon'], + $dateparts['mday'] - 1, + $dateparts['year'], + ), ]; } @@ -735,10 +798,22 @@ function report_customsql_get_week_starts($timenow) { $daysafterweekstart = ($dateparts['wday'] - $startofweek + 7) % 7; return [ - mktime(0, 0, 0, $dateparts['mon'], $dateparts['mday'] - $daysafterweekstart, - $dateparts['year']), - mktime(0, 0, 0, $dateparts['mon'], $dateparts['mday'] - $daysafterweekstart - 7, - $dateparts['year']), + mktime( + 0, + 0, + 0, + $dateparts['mon'], + $dateparts['mday'] - $daysafterweekstart, + $dateparts['year'] + ), + mktime( + 0, + 0, + 0, + $dateparts['mon'], + $dateparts['mday'] - $daysafterweekstart - 7, + $dateparts['year'] + ), ]; } @@ -789,9 +864,9 @@ function report_customsql_delete_old_temp_files($upto) { global $CFG; $count = 0; - $comparison = \core_date::strftime('%Y%m%d-%H%M%S', $upto).'csv'; + $comparison = \core_date::strftime('%Y%m%d-%H%M%S', $upto) . 'csv'; - $files = glob($CFG->dataroot.'/admin_report_customsql/temp/*/*.csv'); + $files = glob($CFG->dataroot . '/admin_report_customsql/temp/*/*.csv'); if (empty($files)) { return; } @@ -938,14 +1013,32 @@ function report_customsql_email_subject(int $countrows, stdClass $report): strin switch ($countrows) { case 0: - return get_string('emailsubjectnodata', 'report_customsql', - ['name' => report_customsql_plain_text_report_name($report), 'env' => $server]); + return get_string( + 'emailsubjectnodata', + 'report_customsql', + [ + 'name' => report_customsql_plain_text_report_name($report), + 'env' => $server, + ] + ); case 1: - return get_string('emailsubject1row', 'report_customsql', - ['name' => report_customsql_plain_text_report_name($report), 'env' => $server]); + return get_string( + 'emailsubject1row', + 'report_customsql', + [ + 'name' => report_customsql_plain_text_report_name($report), + 'env' => $server, + ] + ); default: - return get_string('emailsubjectxrows', 'report_customsql', - ['name' => report_customsql_plain_text_report_name($report), 'rows' => $countrows, 'env' => $server]); + return get_string( + 'emailsubjectxrows', + 'report_customsql', + [ + 'name' => report_customsql_plain_text_report_name($report), + 'rows' => $countrows, 'env' => $server, + ] + ); } } @@ -1036,11 +1129,11 @@ function report_customsql_send_email_notification($recipient, $message) { */ function report_customsql_is_daily_report_ready($report, $timenow) { // Time when the report should run today. - list($runtimetoday) = report_customsql_get_daily_time_starts($timenow, $report->at); + [$runtimetoday] = report_customsql_get_daily_time_starts($timenow, $report->at); // Values used to check whether the report has already run today. - list($today) = report_customsql_get_daily_time_starts($timenow, 0); - list($lastrunday) = report_customsql_get_daily_time_starts($report->lastrun, 0); + [$today] = report_customsql_get_daily_time_starts($timenow, 0); + [$lastrunday] = report_customsql_get_daily_time_starts($report->lastrun, 0); if (($runtimetoday <= $timenow) && ($today > $lastrunday)) { return true; @@ -1097,8 +1190,13 @@ function report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename * @return string the usable version of the name. */ function report_customsql_plain_text_report_name($report): string { - return format_string($report->displayname, true, - ['context' => context_system::instance()]); + return format_string( + $report->displayname, + true, + [ + 'context' => context_system::instance(), + ] + ); } /** diff --git a/manage.php b/manage.php index 8d3ca2e..a6eac28 100644 --- a/manage.php +++ b/manage.php @@ -47,23 +47,51 @@ foreach ($categories as $category) { echo html_writer::start_tag('div'); - echo ' ' . html_writer::link(report_customsql_url('category.php', ['id' => $category->id]), - format_string($category->name) . ' ', ['class' => 'report_customsql']) . - html_writer::tag('a', $OUTPUT->pix_icon('t/edit', get_string('edit')), - ['title' => get_string('editcategoryx', 'report_customsql', format_string($category->name)), - 'href' => report_customsql_url('addcategory.php?id=' . $category->id)]); + echo ' ' . html_writer::link( + report_customsql_url( + 'category.php', + ['id' => $category->id] + ), + format_string($category->name) . ' ', + ['class' => 'report_customsql'], + ) . html_writer::tag( + 'a', + $OUTPUT->pix_icon( + 't/edit', + get_string('edit'), + ), + [ + 'title' => get_string( + 'editcategoryx', + 'report_customsql', + format_string($category->name) + ), + 'href' => report_customsql_url('addcategory.php?id=' . $category->id), + ] + ); if ($category->id != 1 && !$DB->record_exists('report_customsql_queries', ['categoryid' => $category->id])) { - echo ' ' . html_writer::tag('a', $OUTPUT->pix_icon('t/delete', get_string('delete')), - ['title' => get_string('deletecategoryx', 'report_customsql', format_string($category->name)), - 'href' => report_customsql_url('categorydelete.php?id=' . $category->id)]); + echo ' ' . html_writer::tag( + 'a', + $OUTPUT->pix_icon('t/delete', get_string('delete')), + [ + 'title' => get_string( + 'deletecategoryx', + 'report_customsql', + format_string($category->name) + ), + 'href' => report_customsql_url('categorydelete.php?id=' . $category->id), + ] + ); } echo html_writer::end_tag('div'); } } -echo $OUTPUT->single_button(report_customsql_url('addcategory.php'), - get_string('addcategory', 'report_customsql')); +echo $OUTPUT->single_button( + report_customsql_url('addcategory.php'), + get_string('addcategory', 'report_customsql') +); echo $OUTPUT->footer(); diff --git a/readme.md b/readme.md index ada75a6..0c3888d 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,5 @@ +[![Moodle plugin CI](https://github.com/mkassaei/moodle-report_customsql/actions/workflows/ci.yml/badge.svg)](https://github.com/mkassaei/moodle-report_customsql/actions/workflows/ci.yml) + # Ad-hoc database queries This report plugin allows Administrators to set up arbitrary database queries diff --git a/settings.php b/settings.php index 06e4664..d24e185 100644 --- a/settings.php +++ b/settings.php @@ -27,7 +27,7 @@ if ($ADMIN->fulltree) { // Start of week, used for the day to run weekly reports. $days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']; - $days = array_map(function($day) { + $days = array_map(function ($day) { return get_string($day, 'calendar'); }, $days); @@ -35,20 +35,47 @@ // Setting this option to -1 will use the value from the site calendar. $options = [-1 => get_string('startofweek_default', 'report_customsql', $days[$default])] + $days; - $settings->add(new admin_setting_configselect('report_customsql/startwday', + $settings->add( + new admin_setting_configselect( + 'report_customsql/startwday', get_string('startofweek', 'report_customsql'), - get_string('startofweek_desc', 'report_customsql'), -1, $options)); + get_string('startofweek_desc', 'report_customsql'), + -1, + $options, + ) + ); - $settings->add(new admin_setting_configtext_with_maxlength('report_customsql/querylimitdefault', + $settings->add( + new admin_setting_configtext_with_maxlength( + 'report_customsql/querylimitdefault', get_string('querylimitdefault', 'report_customsql'), - get_string('querylimitdefault_desc', 'report_customsql'), 5000, PARAM_INT, null, 10)); + get_string('querylimitdefault_desc', 'report_customsql'), + 5000, + PARAM_INT, + null, + 10, + ) + ); - $settings->add(new admin_setting_configtext_with_maxlength('report_customsql/querylimitmaximum', + $settings->add( + new admin_setting_configtext_with_maxlength( + 'report_customsql/querylimitmaximum', get_string('querylimitmaximum', 'report_customsql'), - get_string('querylimitmaximum_desc', 'report_customsql'), 5000, PARAM_INT, null, 10)); + get_string('querylimitmaximum_desc', 'report_customsql'), + 5000, + PARAM_INT, + null, + 10, + ) + ); } -$ADMIN->add('reports', new admin_externalpage('report_customsql', +$ADMIN->add( + 'reports', + new admin_externalpage( + 'report_customsql', get_string('pluginname', 'report_customsql'), new moodle_url('/report/customsql/index.php'), - 'report/customsql:view')); + 'report/customsql:view', + ) +); diff --git a/tests/behat/behat_report_customsql.php b/tests/behat/behat_report_customsql.php index 49a1f06..e1897c0 100644 --- a/tests/behat/behat_report_customsql.php +++ b/tests/behat/behat_report_customsql.php @@ -25,6 +25,7 @@ */ // NOTE: no MOODLE_INTERNAL test because this file is required by Behat. +// phpcs:disable Universal.UseStatements.NoUselessAliases require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); @@ -38,7 +39,6 @@ * All these steps include the phrase 'custom SQL report'. */ class behat_report_customsql extends behat_base { - /** * Convert page names to URLs for steps like 'When I am on the "[page name]" page'. * @@ -109,7 +109,8 @@ public function the_following_custom_sql_report_exists(TableNode $data) { unset($report['category']); } else { $report['categoryid'] = $this->get_category_id_by_name( - get_string('defaultcategory', 'report_customsql')); + get_string('defaultcategory', 'report_customsql') + ); } // Capability. @@ -124,8 +125,9 @@ public function the_following_custom_sql_report_exists(TableNode $data) { } // Runnable. - if (isset($report['runable']) && - !in_array($report['runable'], report_customsql_runable_options())) { + if ( + isset($report['runable']) && !in_array($report['runable'], report_customsql_runable_options()) + ) { throw new Exception('Invalid runable value ' . $report['capability'] . '.'); } else { $report['runable'] = 'manual'; @@ -174,7 +176,8 @@ public function the_custom_sql_report_x_exists(string $reportname, PyStringNode 'descriptionformat' => FORMAT_HTML, 'querysql' => (string)$querysql, 'categoryid' => $this->get_category_id_by_name( - get_string('defaultcategory', 'report_customsql')), + get_string('defaultcategory', 'report_customsql') + ), 'capability' => 'moodle/site:config', 'runable' => 'manual', ]; @@ -290,7 +293,9 @@ public function downloading_custom_sql_report_x_returns_a_file_with_headers(stri $filecontent = core_text::trim_utf8_bom($filecontent); if ($filecontent != $headers) { throw new ExpectationException( - "File headers: $filecontent did not match expected: $headers", $this->getSession()); + "File headers: $filecontent did not match expected: $headers", + $this->getSession(), + ); } } diff --git a/tests/external/external_get_users_test.php b/tests/external/external_get_users_test.php index f892e2a..a4c21b5 100644 --- a/tests/external/external_get_users_test.php +++ b/tests/external/external_get_users_test.php @@ -36,7 +36,6 @@ * @runTestsInSeparateProcesses */ final class external_get_users_test extends \externallib_advanced_testcase { - /** * Sets up test users with specific roles and permissions. * @@ -63,9 +62,10 @@ protected function setup_users(): array { ['id' => $USER->id, 'firstname' => 'Admin', 'lastname' => 'User']); $admin = $DB->get_record('user', ['id' => $USER->id]); $manager = $generator->create_user( - ['firstname' => 'The', 'lastname' => 'Manager', 'email' => 'manager@example.com']); + ['firstname' => 'The', 'lastname' => 'Manager', 'email' => 'manager@example.com'] + ); $coursecreateor = $generator->create_user( - ['firstname' => 'Coarse', 'lastname' => 'Creator', 'email' => 'cc@example.com'] + ['firstname' => 'Coarse', 'lastname' => 'Creator', 'email' => 'cc@example.com'] ); $generator->role_assign($managerroleid, $manager->id); diff --git a/tests/local/query_test.php b/tests/local/query_test.php index 8c85864..b0290d8 100644 --- a/tests/local/query_test.php +++ b/tests/local/query_test.php @@ -52,8 +52,10 @@ public function test_create_query(): void { $this->assertStringContainsString('view.php?id=1', $query->get_url()); $this->assertStringContainsString('edit.php?id=1', $query->get_edit_url()); $this->assertStringContainsString('delete.php?id=1', $query->get_delete_url()); - $this->assertEquals('This query has not yet been run.', - $query->get_time_note()); + $this->assertEquals( + 'This query has not yet been run.', + $query->get_time_note(), + ); $this->assertEquals('Only administrators (moodle/site:config)', $query->get_capability_string()); // Admin user should have capability to edit and view queries. $this->assertEquals(true, $query->can_edit(\context_system::instance())); diff --git a/tests/privacy_test.php b/tests/privacy_test.php index 687a255..00bca5e 100644 --- a/tests/privacy_test.php +++ b/tests/privacy_test.php @@ -28,7 +28,6 @@ * @covers \report_customsql\privacy\provider */ final class privacy_test extends \core_privacy\tests\provider_testcase { - /** @var \stdClass test user. */ protected $user1; /** @var \stdClass test user. */ diff --git a/tests/report_test.php b/tests/report_test.php index f8ce545..491226c 100644 --- a/tests/report_test.php +++ b/tests/report_test.php @@ -29,7 +29,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class report_test extends \advanced_testcase { - /** * Data provider for test_get_week_starts * @@ -64,7 +63,11 @@ public static function get_week_starts_provider(): array { * @covers ::report_customsql_get_week_starts */ public function test_get_week_starts( - int $startwday, string $datestr, string $currentweek, string $lastweek): void { + int $startwday, + string $datestr, + string $currentweek, + string $lastweek + ): void { $this->resetAfterTest(); set_config('startwday', $startwday, 'report_customsql'); @@ -86,7 +89,11 @@ public function test_get_week_starts( * @covers ::report_customsql_get_week_starts */ public function test_get_week_starts_use_calendar_default( - int $startwday, string $datestr, string $currentweek, string $lastweek): void { + int $startwday, + string $datestr, + string $currentweek, + string $lastweek + ): void { $this->resetAfterTest(); // Setting this option to -1 will use the value from the site calendar. @@ -103,17 +110,26 @@ public function test_get_week_starts_use_calendar_default( * @covers ::report_customsql_get_month_starts */ public function test_get_month_starts_test(): void { - $this->assertEquals([ - strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009')], - report_customsql_get_month_starts(strtotime('12:36 10 November 2009'))); - - $this->assertEquals([ - strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009')], - report_customsql_get_month_starts(strtotime('00:00 1 November 2009'))); - - $this->assertEquals([ - strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009')], - report_customsql_get_month_starts(strtotime('23:59 29 November 2009'))); + $this->assertEquals( + [ + strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009'), + ], + report_customsql_get_month_starts(strtotime('12:36 10 November 2009')) + ); + + $this->assertEquals( + [ + strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009'), + ], + report_customsql_get_month_starts(strtotime('00:00 1 November 2009')) + ); + + $this->assertEquals( + [ + strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009'), + ], + report_customsql_get_month_starts(strtotime('23:59 29 November 2009')), + ); } /** @@ -138,9 +154,14 @@ public function test_report_customsql_get_element_type(): void { * @covers ::report_customsql_substitute_user_token */ public function test_report_customsql_substitute_user_token(): void { - $this->assertEquals('SELECT COUNT(*) FROM oh_quiz_attempts WHERE user = 123', - report_customsql_substitute_user_token('SELECT COUNT(*) FROM oh_quiz_attempts '. - 'WHERE user = %%USERID%%', 123)); + $this->assertEquals( + 'SELECT COUNT(*) FROM oh_quiz_attempts WHERE user = 123', + report_customsql_substitute_user_token( + 'SELECT COUNT(*) FROM oh_quiz_attempts ' . + 'WHERE user = %%USERID%%', + 123, + ), + ); } /** @@ -155,7 +176,6 @@ public function test_report_customsql_capability_options(): void { 'moodle/site:config' => get_string('userswhocanconfig', 'report_customsql'), ]; $this->assertEquals($capoptions, report_customsql_capability_options()); - } /** @@ -354,8 +374,10 @@ public function test_report_customsql_pretify_column_names(): void { $row->column_url = 2; $row->column_3 = 3; $query = "SELECT 1 AS First, 2 AS Column_URL, 3 AS column_3"; - $this->assertEquals(['column', 'Column URL', 'column 3'], - report_customsql_pretify_column_names($row, $query)); + $this->assertEquals( + ['column', 'Column URL', 'column 3'], + report_customsql_pretify_column_names($row, $query), + ); } /** @@ -373,8 +395,10 @@ public function test_report_customsql_pretify_column_names_multi_line(): void { 2 AS Column_URL, 3 AS column_3 FROM table"; - $this->assertEquals(['column', 'Column URL', 'column 3'], - report_customsql_pretify_column_names($row, $query)); + $this->assertEquals( + ['column', 'Column URL', 'column 3'], + report_customsql_pretify_column_names($row, $query) + ); } /** @@ -387,9 +411,10 @@ public function test_report_customsql_pretify_column_names_same_name_diff_capiti $row->course = 'B747-19B'; $query = "SELECT t.course AS Course FROM table"; - $this->assertEquals(['Course'], - report_customsql_pretify_column_names($row, $query)); - + $this->assertEquals( + ['Course'], + report_customsql_pretify_column_names($row, $query), + ); } /** @@ -422,9 +447,10 @@ public function test_report_customsql_pretify_column_names_issue(): void { ORDER BY website, frog"; - $this->assertEquals(['Website', 'Website link url', 'Frog', 'Frog link url'], - report_customsql_pretify_column_names($row, $query)); - + $this->assertEquals( + ['Website', 'Website link url', 'Frog', 'Frog link url'], + report_customsql_pretify_column_names($row, $query), + ); } /** diff --git a/version.php b/version.php index da2a530..257c026 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2025072400; +$plugin->version = 2026012200; $plugin->requires = 2024042200; $plugin->component = 'report_customsql'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '4.4 for Moodle 4.4+'; +$plugin->release = '4.4 for Moodle 4.5+ and compatible with Moodle 5.0+'; $plugin->outestssufficient = true; diff --git a/view.php b/view.php index 0048635..9a8c478 100644 --- a/view.php +++ b/view.php @@ -42,8 +42,13 @@ $urlparams['embed'] = $embed; // Setup the page. -admin_externalpage_setup('report_customsql', '', $urlparams, - '/report/customsql/view.php', ['pagelayout' => 'report']); +admin_externalpage_setup( + 'report_customsql', + '', + $urlparams, + '/report/customsql/view.php', + ['pagelayout' => 'report'], +); $PAGE->set_title(format_string($report->displayname)); $PAGE->navbar->add(format_string($category->name), report_customsql_url('category.php', ['id' => $report->categoryid])); $PAGE->navbar->add(format_string($report->displayname)); @@ -63,7 +68,6 @@ \core\session\manager::write_close(); if ($report->runable == 'manual') { - // Allow query parameters to be entered. if (!empty($report->queryparams)) { $queryparams = report_customsql_get_query_placeholders_and_field_names($report->querysql); @@ -95,7 +99,6 @@ } if (($newreport = $mform->get_data()) || count($paramvalues) == count($queryparams)) { - // Pick up named parameters into serialised array. if ($newreport) { foreach ($queryparams as $queryparam => $formparam) { @@ -103,11 +106,13 @@ } } $report->queryparams = serialize($paramvalues); - } else { - - admin_externalpage_setup('report_customsql', '', $urlparams, - '/report/customsql/view.php'); + admin_externalpage_setup( + 'report_customsql', + '', + $urlparams, + '/report/customsql/view.php', + ); $PAGE->set_title(format_string($report->displayname)); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($report->displayname)); @@ -128,8 +133,12 @@ // Get the updated execution times. $report = $DB->get_record('report_customsql_queries', ['id' => $id]); } catch (Exception $e) { - throw new moodle_exception('queryfailed', 'report_customsql', report_customsql_url('index.php'), - $e->getMessage()); + throw new moodle_exception( + 'queryfailed', + 'report_customsql', + report_customsql_url('index.php'), + $e->getMessage(), + ); } } else { // Runs on schedule. @@ -153,9 +162,15 @@ if (report_customsql_get_element_type($name) == 'date_time_selector') { $value = userdate($value, '%F %T'); } - echo html_writer::tag('p', get_string('parametervalue', 'report_customsql', + echo html_writer::tag( + 'p', + get_string( + 'parametervalue', + 'report_customsql', ['name' => html_writer::tag('b', str_replace('_', ' ', $name)), - 'value' => s($value)])); + 'value' => s($value)] + ) + ); } } @@ -163,7 +178,7 @@ if (is_null($csvtimestamp)) { echo html_writer::tag('p', get_string('nodatareturned', 'report_customsql')); } else { - list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $csvtimestamp); + [$csvfilename, $csvtimestamp] = report_customsql_csv_filename($report, $csvtimestamp); if (!is_readable($csvfilename)) { if (empty($report->lastrun) || $csvtimestamp > $report->lastrun) { echo html_writer::tag('p', get_string('notrunyet', 'report_customsql')); @@ -174,14 +189,17 @@ $handle = fopen($csvfilename, 'r'); if ($report->runable != 'manual' && !$report->singlerow) { - echo $OUTPUT->heading(get_string('reportfor', 'report_customsql', - userdate($csvtimestamp)), 3); + echo $OUTPUT->heading( + get_string('reportfor', 'report_customsql', userdate($csvtimestamp)), + 3, + ); } $table = new html_table(); $table->id = 'report_customsql_results'; - list($table->head, $linkcolumns) = report_customsql_get_table_headers( - report_customsql_read_csv_row($handle)); + [$table->head, $linkcolumns] = report_customsql_get_table_headers( + report_customsql_read_csv_row($handle) + ); $rowlimitexceeded = false; while ($row = report_customsql_read_csv_row($handle)) { @@ -204,12 +222,21 @@ echo html_writer::table($table); if ($rowlimitexceeded) { - echo html_writer::tag('p', get_string('recordlimitreached', 'report_customsql', - $report->querylimit ?? get_config('report_customsql', 'querylimitdefault')), - ['class' => 'admin_note']); + echo html_writer::tag( + 'p', + get_string( + 'recordlimitreached', + 'report_customsql', + $report->querylimit ?? get_config('report_customsql', 'querylimitdefault') + ), + ['class' => 'admin_note'], + ); } else { - echo html_writer::tag('p', get_string('recordcount', 'report_customsql', $count), - ['class' => 'admin_note']); + echo html_writer::tag( + 'p', + get_string('recordcount', 'report_customsql', $count), + ['class' => 'admin_note'], + ); } echo report_customsql_time_note($report, 'p'); @@ -220,17 +247,27 @@ } $urlparams['timestamp'] = $csvtimestamp; $downloadurl = report_customsql_downloadurl($id, $urlparams); - echo $OUTPUT->download_dataformat_selector(get_string('downloadthisreportas', 'report_customsql'), - $downloadurl, 'dataformat', $urlparams); + echo $OUTPUT->download_dataformat_selector( + get_string('downloadthisreportas', 'report_customsql'), + $downloadurl, + 'dataformat', + $urlparams, + ); } } if (!empty($queryparams)) { - echo html_writer::tag('p', - $OUTPUT->action_link( - report_customsql_url('view.php', ['id' => $id]), - $OUTPUT->pix_icon('t/editstring', '') . ' ' . - get_string('changetheparameters', 'report_customsql'))); + echo html_writer::tag( + 'p', + $OUTPUT->action_link( + report_customsql_url( + 'view.php', + ['id' => $id] + ), + $OUTPUT->pix_icon('t/editstring', '') . ' ' . + get_string('changetheparameters', 'report_customsql') + ) + ); } echo $output->render_report_actions($report, $category, $context); @@ -241,7 +278,6 @@ $archivetimes = report_customsql_get_archive_times($report); if (!$archivetimes) { echo html_writer::tag('p', get_string('notrunyet', 'report_customsql')); - } else { echo html_writer::start_tag('ul'); foreach ($archivetimes as $time) { @@ -250,9 +286,16 @@ if ($time == $csvtimestamp) { echo html_writer::tag('b', $formattedtime); } else { - echo html_writer::tag('a', $formattedtime, - ['href' => report_customsql_url('view.php', - ['id' => $id, 'timestamp' => $time])]); + echo html_writer::tag( + 'a', + $formattedtime, + [ + 'href' => report_customsql_url( + 'view.php', + ['id' => $id, 'timestamp' => $time], + ), + ], + ); } echo ''; } diff --git a/view_form.php b/view_form.php index e6ed1b8..fc86870 100644 --- a/view_form.php +++ b/view_form.php @@ -34,7 +34,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class report_customsql_view_form extends moodleform { - #[\Override] public function definition() { $mform = $this->_form;