Skip to content

Commit 5d11935

Browse files
author
Mahmoud Kassaei
committed
Ad-hoc database queries: publish report_customsql M4.5/M5.0 version #948807
1 parent 2dda6be commit 5d11935

32 files changed

+763
-334
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ jobs:
88
fail-fast: false
99
matrix:
1010
include:
11-
- php: '8.3'
11+
- php: '8.4'
1212
moodle-branch: 'main'
13+
database: 'mariadb'
14+
- php: '8.4'
15+
moodle-branch: 'MOODLE_501_STABLE'
1316
database: 'pgsql'
1417
- php: '8.3'
1518
moodle-branch: 'MOODLE_500_STABLE'
@@ -23,7 +26,7 @@ jobs:
2326

2427
services:
2528
postgres:
26-
image: postgres:14
29+
image: postgres:16
2730
env:
2831
POSTGRES_USER: 'postgres'
2932
POSTGRES_HOST_AUTH_METHOD: 'trust'
@@ -36,7 +39,7 @@ jobs:
3639
- 5432:5432
3740

3841
mariadb:
39-
image: mariadb:10
42+
image: mariadb:10.11
4043
env:
4144
MYSQL_USER: 'root'
4245
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
@@ -79,10 +82,6 @@ jobs:
7982
if: ${{ always() }}
8083
run: moodle-plugin-ci phplint
8184

82-
- name: PHP Copy/Paste Detector
83-
if: ${{ always() }}
84-
run: moodle-plugin-ci phpcpd
85-
8685
- name: PHP Mess Detector
8786
if: ${{ always() }}
8887
run: moodle-plugin-ci phpmd

addcategory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@
4747
$queryparams['categoryid'] = $id;
4848
$isadding = false;
4949
// Editing an existing category.
50-
$category = $DB->get_record('report_customsql_categories',
51-
['id' => $id], '*', MUST_EXIST);
50+
$category = $DB->get_record(
51+
'report_customsql_categories',
52+
['id' => $id],
53+
'*',
54+
MUST_EXIST,
55+
);
5256
} else {
5357
$queryparams['categoryid'] = null;
5458
$isadding = true;

categoryadd_form.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3939
*/
4040
class report_customsql_addcategory_form extends moodleform {
41-
4241
#[\Override]
4342
public function definition() {
4443
global $CFG, $DB;
@@ -74,8 +73,13 @@ public function validation($data, $files) {
7473
if (!isset($data['id'])) {
7574
$data['id'] = 0;// Ensure id to check against.
7675
}
77-
if ($DB->get_record_select('report_customsql_categories',
78-
'name = ? AND id != ?', [$data['name'], $data['id']])) {
76+
if (
77+
$DB->get_record_select(
78+
'report_customsql_categories',
79+
'name = ? AND id != ?',
80+
[$data['name'], $data['id']],
81+
)
82+
) {
7983
$errors['name'] = get_string('categoryexists', 'report_customsql');
8084
}
8185
}

categorydelete.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
$id = required_param('id', PARAM_INT);
3232

3333
// Start the page.
34-
admin_externalpage_setup('report_customsql', '', ['id' => $id],
35-
'/report/customsql/categorydelete.php');
34+
admin_externalpage_setup(
35+
'report_customsql',
36+
'',
37+
['id' => $id],
38+
'/report/customsql/categorydelete.php',
39+
);
3640
$context = context_system::instance();
3741
require_capability('report/customsql:managecategories', $context);
3842

@@ -56,10 +60,25 @@
5660
}
5761

5862
echo $OUTPUT->header();
59-
echo $OUTPUT->heading(get_string('deletecategoryareyousure', 'report_customsql'));
60-
echo html_writer::tag('p', get_string('categorynamex', 'report_customsql', $category->name ));
61-
echo $OUTPUT->confirm(get_string('deletecategoryyesno', 'report_customsql'),
62-
new single_button(report_customsql_url('categorydelete.php',
63-
['id' => $id, 'confirm' => 1, 'sesskey' => sesskey()]), get_string('yes')),
64-
new single_button(report_customsql_url('index.php'), get_string('no')));
63+
echo $OUTPUT->heading(
64+
get_string('deletecategoryareyousure', 'report_customsql')
65+
);
66+
echo html_writer::tag(
67+
'p',
68+
get_string('categorynamex', 'report_customsql', $category->name),
69+
);
70+
echo $OUTPUT->confirm(
71+
get_string('deletecategoryyesno', 'report_customsql'),
72+
new single_button(
73+
report_customsql_url(
74+
'categorydelete.php',
75+
['id' => $id,
76+
'confirm' => 1,
77+
'sesskey' => sesskey(),
78+
]
79+
),
80+
get_string('yes')
81+
),
82+
new single_button(report_customsql_url('index.php'), get_string('no'))
83+
);
6584
echo $OUTPUT->footer();

classes/event/query_deleted.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3333
*/
3434
class query_deleted extends \core\event\base {
35-
3635
#[\Override]
3736
protected function init() {
3837
$this->data['crud'] = 'd';

classes/event/query_edited.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3333
*/
3434
class query_edited extends \core\event\base {
35-
3635
#[\Override]
3736
protected function init() {
3837
$this->data['crud'] = 'u';

classes/event/query_viewed.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3333
*/
3434
class query_viewed extends \core\event\base {
35-
3635
#[\Override]
3736
protected function init() {
3837
$this->data['crud'] = 'r';

classes/external/get_users.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,29 @@ public static function execute_parameters(): external_function_parameters {
5454
public static function execute(string $query, string $capability): array {
5555
global $CFG, $DB;
5656

57-
[$query, $capability] = array_values(self::validate_parameters(self::execute_parameters(),
58-
['query' => $query, 'capability' => $capability]));
57+
[$query, $capability] = array_values(
58+
self::validate_parameters(
59+
self::execute_parameters(),
60+
['query' => $query, 'capability' => $capability],
61+
)
62+
);
5963

6064
$context = \context_system::instance();
6165
self::validate_context($context);
6266
require_capability('report/customsql:definequeries', $context);
6367

6468
if (class_exists('\core_user\fields')) {
6569
$extrafields = \core_user\fields::for_identity($context, false)->get_required_fields();
66-
$fields = \core_user\fields::for_identity($context,
67-
false)->with_userpic()->get_sql('u', false, '', '', false)->selects;
70+
$fields = \core_user\fields::for_identity(
71+
$context,
72+
false
73+
)->with_userpic()->get_sql(
74+
'u',
75+
false,
76+
'',
77+
'',
78+
false,
79+
)->selects;
6880
} else {
6981
$extrafields = get_extra_user_fields($context);
7082
$fields = \user_picture::fields('u', $extrafields);
@@ -148,6 +160,7 @@ public static function execute_returns(): external_description {
148160
'identity' => new external_value(PARAM_RAW, 'Additional user identifying info.'),
149161
'hasidentity' => new external_value(PARAM_BOOL, 'Whether identity is non-blank.'),
150162
'profileimageurlsmall' => new external_value(PARAM_RAW, 'URL of the user profile image.'),
151-
]));
163+
])
164+
);
152165
}
153166
}

classes/local/category.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function load_queries_data(array $queries): void {
7979
* @return \stdClass[] All queries of type.
8080
*/
8181
public static function get_reports_of_a_particular_runtype(array $queries, string $type) {
82-
return array_filter($queries, function($query) use ($type) {
82+
return array_filter($queries, function ($query) use ($type) {
8383
return $query->runable == $type;
8484
}, ARRAY_FILTER_USE_BOTH);
8585
}
@@ -91,7 +91,7 @@ public static function get_reports_of_a_particular_runtype(array $queries, strin
9191
* @return \stdClass[] queries the current user is allowed to see.
9292
*/
9393
public static function filter_reports_by_capability(array $queries) {
94-
return array_filter($queries, function($query) {
94+
return array_filter($queries, function ($query) {
9595
return has_capability($query->capability ?? 'moodle/site:config', \context_system::instance());
9696
}, ARRAY_FILTER_USE_BOTH);
9797
}

classes/output/category.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ class category implements renderable, templatable {
6767
* @param bool $addnewquerybtn Show 'Add new query' button or not.
6868
* @param moodle_url|null $returnurl Return url.
6969
*/
70-
public function __construct(report_category $category, context $context, bool $expandable = false, int $showcat = 0,
71-
int $hidecat = 0, bool $showonlythislink = false, bool $addnewquerybtn = true, ?moodle_url $returnurl = null) {
70+
public function __construct(
71+
report_category $category,
72+
context $context,
73+
bool $expandable = false,
74+
int $showcat = 0,
75+
int $hidecat = 0,
76+
bool $showonlythislink = false,
77+
bool $addnewquerybtn = true,
78+
?moodle_url $returnurl = null
79+
) {
7280
$this->category = $category;
7381
$this->context = $context;
7482
$this->expandable = $expandable;
@@ -108,8 +116,12 @@ public function export_for_template(renderer_base $output) {
108116
if ($this->addnewquerybtn && has_capability('report/customsql:definequeries', $this->context)) {
109117
$addnewqueryurl = report_customsql_url('edit.php', ['categoryid' => $this->category->get_id(),
110118
'returnurl' => $this->returnurl->out_as_local_url(false)]);
111-
$addquerybutton = $output->single_button($addnewqueryurl, get_string('addreport', 'report_customsql'), 'post',
112-
['class' => 'mb-1']);
119+
$addquerybutton = $output->single_button(
120+
$addnewqueryurl,
121+
get_string('addreport', 'report_customsql'),
122+
'post',
123+
['class' => 'mb-1'],
124+
);
113125
}
114126

115127
return [

0 commit comments

Comments
 (0)