Skip to content

Commit 354e16c

Browse files
authored
Merge pull request #42 from learnweb/update/m404
Update for Moodle 4.4 and Code style
2 parents db54e5f + ac9cae4 commit 354e16c

File tree

16 files changed

+194
-229
lines changed

16 files changed

+194
-229
lines changed

.github/workflows/moodle-ci.yml

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jobs:
1212
strategy:
1313
matrix:
1414
php: ['8.2']
15-
moodle-branch: ['MOODLE_403_STABLE']
15+
moodle-branch: ['MOODLE_404_STABLE']
1616
database: ['pgsql']
1717

1818
steps:
1919
- name: Start PostgreSQL
2020
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14
2121

2222
- name: Check out repository code
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424
with:
2525
path: plugin
2626

@@ -36,29 +36,9 @@ jobs:
3636
ini-values: max_input_vars=5000
3737
coverage: none
3838

39-
- name: Get composer cache directory
40-
id: composer-cache
41-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
42-
43-
- name: Composer cache
44-
uses: actions/cache@v3
45-
with:
46-
path: ${{ steps.composer-cache.outputs.dir }}
47-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
48-
restore-keys: |
49-
${{ runner.os }}-composer-
50-
51-
- name: npm cache
52-
uses: actions/cache@v3
53-
with:
54-
path: ~/.npm
55-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
56-
restore-keys: |
57-
${{ runner.os }}-node-
58-
5939
- name: Initialise moodle-plugin-ci
6040
run: |
61-
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
41+
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
6242
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
6343
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
6444
sudo locale-gen en_AU.UTF-8
@@ -75,18 +55,13 @@ jobs:
7555
if: ${{ always() }}
7656
run: moodle-plugin-ci phplint
7757

78-
- name: PHP Copy/Paste Detector
79-
if: ${{ always() }}
80-
run: moodle-plugin-ci phpcpd
81-
8258
- name: PHP Mess Detector
8359
if: ${{ always() }}
8460
run: moodle-plugin-ci phpmd
8561

8662
- name: Moodle Code Checker
8763
if: ${{ always() }}
8864
run: moodle-plugin-ci codechecker
89-
continue-on-error: true
9065

9166
- name: Moodle PHPDoc Checker
9267
if: ${{ always() }}
@@ -117,30 +92,20 @@ jobs:
11792
fail-fast: false
11893
matrix:
11994
php: ['8.0', '8.1', '8.2']
120-
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE']
95+
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE']
12196
database: ['mariadb', 'pgsql']
12297
exclude:
98+
- php: '8.0'
99+
moodle-branch: 'MOODLE_404_STABLE'
123100
- php: '8.2'
124101
moodle-branch: 'MOODLE_401_STABLE'
125102
include:
126103
- php: '7.4'
127-
moodle-branch: 'MOODLE_39_STABLE'
128-
database: 'mariadb'
129-
- php: '7.4'
130-
moodle-branch: 'MOODLE_39_STABLE'
131-
database: 'pgsql'
132-
- php: '8.0'
133-
moodle-branch: 'MOODLE_311_STABLE'
134-
database: 'mariadb'
135-
- php: '8.0'
136-
moodle-branch: 'MOODLE_311_STABLE'
104+
moodle-branch: 'MOODLE_401_STABLE'
137105
database: 'pgsql'
138-
- php: '8.0'
139-
moodle-branch: 'MOODLE_400_STABLE'
106+
- php: '7.4'
107+
moodle-branch: 'MOODLE_401_STABLE'
140108
database: 'mariadb'
141-
- php: '8.0'
142-
moodle-branch: 'MOODLE_400_STABLE'
143-
database: 'pgsql'
144109

145110
steps:
146111
- name: Start MariaDB
@@ -152,7 +117,7 @@ jobs:
152117
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14
153118

154119
- name: Check out repository code
155-
uses: actions/checkout@v3
120+
uses: actions/checkout@v4
156121
with:
157122
path: plugin
158123

@@ -163,24 +128,6 @@ jobs:
163128
ini-values: max_input_vars=5000
164129
coverage: none
165130

166-
- name: Get composer cache directory
167-
id: composer-cache
168-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
169-
- name: Composer cache
170-
uses: actions/cache@v3
171-
with:
172-
path: ${{ steps.composer-cache.outputs.dir }}
173-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
174-
restore-keys: |
175-
${{ runner.os }}-composer-
176-
- name: npm cache
177-
uses: actions/cache@v3
178-
with:
179-
path: ~/.npm
180-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
181-
restore-keys: |
182-
${{ runner.os }}-node-
183-
184131
- name: Initialise moodle-plugin-ci
185132
run: |
186133
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
@@ -202,4 +149,16 @@ jobs:
202149

203150
- name: Behat features
204151
if: ${{ always() }}
205-
run: moodle-plugin-ci behat --auto-rerun 0
152+
run: moodle-plugin-ci behat --profile chrome --auto-rerun 0
153+
154+
# This step allows to upload Behat faildump (screenshots) as workflow artifact,
155+
# so it can be downloaded and inspected. You don't need this step if you
156+
# are not running Behat test. Artifact will be retained for 7 days.
157+
- name: Upload Behat Faildump
158+
if: ${{ failure() && steps.behat.outcome == 'failure' }}
159+
uses: actions/upload-artifact@v4
160+
with:
161+
name: Behat Faildump (${{ join(matrix.*, ', ') }})
162+
path: ${{ github.workspace }}/moodledata/behat_dump
163+
retention-days: 7
164+
if-no-files-found: ignore

block_groups.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
* @copyright 2016/17 N Herrmann
3737
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3838
*/
39-
class block_groups extends block_base
40-
{
39+
class block_groups extends block_base {
40+
4141
/**
4242
* Initializes the block.
4343
*/
@@ -83,33 +83,33 @@ public function get_content() {
8383
* @return array of applicable formats.
8484
*/
8585
public function applicable_formats() {
86-
return array('course-view' => true, 'mod' => false, 'my' => false);
86+
return ['course-view' => true, 'mod' => false, 'my' => false];
8787
}
8888
/**
8989
* Returns a html representation of all existing groups and groupings
9090
*
9191
* @return string html-string
9292
*/
9393
private function get_content_teaching() {
94-
global $COURSE, $PAGE, $DB, $CFG;
94+
global $COURSE, $DB;
9595
$courseid = $COURSE->id;
9696
// Array to save all groups.
9797
$allgroups = groups_get_all_groups($courseid);
9898
// Array to save all groupings.
9999
$allgroupings = groups_get_all_groupings($courseid);
100100
$content = '';
101-
/* @var $renderer block_groups_renderer */
102-
$renderer = $PAGE->get_renderer('block_groups');
101+
/** @var block_groups_renderer $renderer */
102+
$renderer = $this->page->get_renderer('block_groups');
103103
// Calls Javascript if available.
104-
$PAGE->requires->js_call_amd('block_groups/blocks_groups_visibility', 'initialise', array($courseid));
105-
$groupsarray = array();
104+
$this->page->requires->js_call_amd('block_groups/blocks_groups_visibility', 'initialise', [$courseid]);
105+
$groupsarray = [];
106106
foreach ($allgroups as $value) {
107107
// Checks availability of group and requests the content.
108108
if (is_object($value) && property_exists($value, 'name')) {
109109
$countmembers = count(groups_get_members($value->id));
110110
$href = new moodle_url('/blocks/groups/changevisibility.php',
111-
array('courseid' => $courseid, 'groupid' => $value->id));
112-
if (empty($DB->get_records('block_groups_hide', array('id' => $value->id)))) {
111+
['courseid' => $courseid, 'groupid' => $value->id]);
112+
if (empty($DB->get_records('block_groups_hide', ['id' => $value->id]))) {
113113
$groupsarray[] = $renderer->get_string_group($value, $href, $countmembers, true);
114114
} else {
115115
$groupsarray[] = $renderer->get_string_group($value, $href, $countmembers, false);
@@ -118,7 +118,7 @@ private function get_content_teaching() {
118118
}
119119

120120
// Empty block or block with checkboxes.
121-
$href = new moodle_url('/group/index.php', array('id' => $courseid));
121+
$href = new moodle_url('/group/index.php', ['id' => $courseid]);
122122
if (count($groupsarray) == 0) {
123123
$content .= html_writer::div(get_string('nogroups', 'block_groups'));
124124
$content .= $renderer->get_link_modify_groups($href);
@@ -140,16 +140,16 @@ private function get_content_teaching() {
140140
* @return string html-string representing all member groups
141141
*/
142142
private function get_content_groupmembers() {
143-
global $COURSE, $DB, $PAGE;
144-
$enrolledgroups = array();
143+
global $COURSE, $DB;
144+
$enrolledgroups = [];
145145
$allgroups = groups_get_my_groups();
146146
// Necessary to show hidden groups to Course Managers.
147147
$access = has_capability('moodle/course:managegroups', context_course::instance($COURSE->id));
148-
/* @var $renderer block_groups_renderer */
149-
$renderer = $PAGE->get_renderer('block_groups');
148+
/** @var block_groups_renderer $renderer */
149+
$renderer = $this->page->get_renderer('block_groups');
150150
foreach ($allgroups as $group) {
151151
if (($group->courseid == $COURSE->id)) {
152-
$groupdbentry = $DB->get_records('block_groups_hide', array('id' => $group->id));
152+
$groupdbentry = $DB->get_records('block_groups_hide', ['id' => $group->id]);
153153
if (!empty($groupdbentry)) {
154154
$enrolledgroups[] = $renderer->get_tag_group($group, true);
155155
} else if ($access === true) {
@@ -173,10 +173,9 @@ private function get_content_groupmembers() {
173173
* @return array every key is a group id and point to a grouping
174174
*/
175175
public function build_grouping_array($allgroupings, $courseid) {
176-
global $PAGE;
177-
/* @var $renderer block_groups_renderer */
178-
$renderer = $PAGE->get_renderer('block_groups');
179-
$groupingsarray = array();
176+
/** @var block_groups_renderer $renderer */
177+
$renderer = $this->page->get_renderer('block_groups');
178+
$groupingsarray = [];
180179
$arrayofmembers = count_grouping_members($courseid);
181180
foreach ($allgroupings as $g => $value) {
182181
if (is_object($value) && property_exists($value, 'name')) {
@@ -187,4 +186,4 @@ public function build_grouping_array($allgroupings, $courseid) {
187186
}
188187
return $groupingsarray;
189188
}
190-
}
189+
}

changeallgroups.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @copyright 2016 N Herrmann
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
25+
2526
require_once('../../config.php');
2627
require_login();
2728

@@ -30,24 +31,24 @@
3031

3132
$PAGE->set_url('/blocks/groups/changeallgroups.php');
3233
// In Case the given id of the course is not available in the database exit message is shown.
33-
if (empty($DB->get_record('course', array('id' => $courseid)))) {
34+
if (empty($DB->get_record('course', ['id' => $courseid]))) {
3435
exit(get_string('nocourse', 'block_groups'));
3536
}
3637
$PAGE->set_context(context_course::instance($courseid));
3738
// Check for capability beforehand not possible since a context is needed.
3839
require_capability('moodle/course:managegroups', context_course::instance($courseid));
3940
// Get all groups of the selected course.
40-
$groupsuitable = $DB->get_records('groups', array('courseid' => $courseid));
41+
$groupsuitable = $DB->get_records('groups', ['courseid' => $courseid]);
4142
// The Course has no groups therefore changing all is not possible.
4243
if (empty($groupsuitable)) {
4344
notice(get_string('nogroups', 'block_groups'),
4445
$CFG->wwwroot . '/course/view.php?id=' . $courseid);
4546
exit();
4647
}
47-
$groups = array();
48-
$groupsvisible = array();
48+
$groups = [];
49+
$groupsvisible = [];
4950
foreach ($groupsuitable as $group) {
50-
$entry = $DB->get_records('block_groups_hide', array('id' => $group->id));
51+
$entry = $DB->get_records('block_groups_hide', ['id' => $group->id]);
5152
// In the Case, that the group of the course has an entry in the 'block_groups_hide' table the group is visible.
5253
if (!empty($entry)) {
5354
$groupsvisible[$group->id] = $group->id;
@@ -58,7 +59,7 @@
5859

5960
if ($hide === 0) {
6061
$messageaction = 'visible';
61-
$tempgroup = array();
62+
$tempgroup = [];
6263
foreach ($groupsuitable as $group) {
6364
if (!empty($groupsvisible)) {
6465
if (!(in_array($group->id, $groups))) {
@@ -85,4 +86,4 @@
8586
redirect($CFG->wwwroot . '/course/view.php?id=' . $courseid,
8687
get_string('groupschanged' . $messageaction, 'block_groups'),
8788
null, \core\output\notification::NOTIFY_SUCCESS);
88-
exit();
89+
exit();

changevisibility.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @copyright 2016/17 N Herrmann
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
25+
2526
require_once('../../config.php');
2627
require_login();
2728

@@ -30,13 +31,13 @@
3031

3132
$PAGE->set_url('/blocks/groups/changevisibility.php');
3233
// In Case the given id of the course is not available in the database exit message is shown.
33-
if (empty($DB->get_record('course', array('id' => $courseid)))) {
34+
if (empty($DB->get_record('course', ['id' => $courseid]))) {
3435
exit(get_string('nocourse', 'block_groups'));
3536
}
3637
$PAGE->set_context(context_course::instance($courseid));
3738
// Check for capability beforehand not possible since a context is needed.
3839
require_capability('moodle/course:managegroups', context_course::instance($courseid));
39-
$groupsuitable = $DB->get_record('groups', array('id' => $groupid, 'courseid' => $courseid));
40+
$groupsuitable = $DB->get_record('groups', ['id' => $groupid, 'courseid' => $courseid]);
4041

4142
if (empty($groupsuitable)) {
4243
notice(get_string('nochangeindatabasepossible', 'block_groups'),

classes/privacy/provider.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,21 @@
2424

2525
namespace block_groups\privacy;
2626

27-
defined('MOODLE_INTERNAL') || die();
28-
2927
/**
3028
* Privacy Subsystem for block_groups implementing null_provider.
3129
*
3230
* @copyright 2018 Tamara Gunkel, Nina Herrmann
3331
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3432
*/
3533
class provider implements \core_privacy\local\metadata\null_provider {
36-
// This trait must be included.
37-
use \core_privacy\local\legacy_polyfill;
34+
3835
/**
3936
* Get the language string identifier with the component's language
4037
* file to explain why this plugin stores no data.
4138
*
4239
* @return string
4340
*/
44-
public static function _get_reason() {
41+
public static function get_reason(): string {
4542
return 'privacy:metadata';
4643
}
4744
}

db/access.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

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

27-
$capabilities = array(
28-
'block/groups:addinstance' => array(
27+
$capabilities = [
28+
'block/groups:addinstance' => [
2929
'captype' => 'write',
3030
'contextlevel' => CONTEXT_BLOCK,
31-
'archetypes' => array(
31+
'archetypes' => [
3232
'editingteacher' => CAP_ALLOW,
33-
'manager' => CAP_ALLOW
34-
),
35-
'clonepermissionsfrom' => 'moodle/site:manageblocks'
36-
),
37-
);
33+
'manager' => CAP_ALLOW,
34+
],
35+
'clonepermissionsfrom' => 'moodle/site:manageblocks',
36+
],
37+
];

0 commit comments

Comments
 (0)