Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -23,7 +26,7 @@ jobs:

services:
postgres:
image: postgres:14
image: postgres:16
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -36,7 +39,7 @@ jobs:
- 5432:5432

mariadb:
image: mariadb:10
image: mariadb:10.11
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions addcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions categoryadd_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}
Expand Down
35 changes: 27 additions & 8 deletions categorydelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
1 change: 0 additions & 1 deletion classes/event/query_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion classes/event/query_edited.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion classes/event/query_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
23 changes: 18 additions & 5 deletions classes/external/get_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,29 @@ 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);
require_capability('report/customsql:definequeries', $context);

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);
Expand Down Expand Up @@ -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.'),
]));
])
);
}
}
4 changes: 2 additions & 2 deletions classes/local/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
20 changes: 16 additions & 4 deletions classes/output/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 [
Expand Down
36 changes: 28 additions & 8 deletions classes/output/index_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [
Expand Down
22 changes: 12 additions & 10 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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,
Expand Down
28 changes: 18 additions & 10 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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],
);
}
}
}
Expand All @@ -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,
);
}
}

Expand Down
Loading