Skip to content

Commit

Permalink
Update for Moodle 4.4 and Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Apr 30, 2024
1 parent db54e5f commit ac9cae4
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 229 deletions.
87 changes: 23 additions & 64 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
strategy:
matrix:
php: ['8.2']
moodle-branch: ['MOODLE_403_STABLE']
moodle-branch: ['MOODLE_404_STABLE']
database: ['pgsql']

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

- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -36,29 +36,9 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand All @@ -75,18 +55,13 @@ 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

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

- name: Moodle PHPDoc Checker
if: ${{ always() }}
Expand Down Expand Up @@ -117,30 +92,20 @@ jobs:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE']
database: ['mariadb', 'pgsql']
exclude:
- php: '8.0'
moodle-branch: 'MOODLE_404_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'

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

- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -163,24 +128,6 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
Expand All @@ -202,4 +149,16 @@ jobs:

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --auto-rerun 0
run: moodle-plugin-ci behat --profile chrome --auto-rerun 0

# This step allows to upload Behat faildump (screenshots) as workflow artifact,
# so it can be downloaded and inspected. You don't need this step if you
# are not running Behat test. Artifact will be retained for 7 days.
- name: Upload Behat Faildump
if: ${{ failure() && steps.behat.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: Behat Faildump (${{ join(matrix.*, ', ') }})
path: ${{ github.workspace }}/moodledata/behat_dump
retention-days: 7
if-no-files-found: ignore
41 changes: 20 additions & 21 deletions block_groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
* @copyright 2016/17 N Herrmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_groups extends block_base
{
class block_groups extends block_base {

/**
* Initializes the block.
*/
Expand Down Expand Up @@ -83,33 +83,33 @@ public function get_content() {
* @return array of applicable formats.
*/
public function applicable_formats() {
return array('course-view' => true, 'mod' => false, 'my' => false);
return ['course-view' => true, 'mod' => false, 'my' => false];
}
/**
* Returns a html representation of all existing groups and groupings
*
* @return string html-string
*/
private function get_content_teaching() {
global $COURSE, $PAGE, $DB, $CFG;
global $COURSE, $DB;
$courseid = $COURSE->id;
// Array to save all groups.
$allgroups = groups_get_all_groups($courseid);
// Array to save all groupings.
$allgroupings = groups_get_all_groupings($courseid);
$content = '';
/* @var $renderer block_groups_renderer */
$renderer = $PAGE->get_renderer('block_groups');
/** @var block_groups_renderer $renderer */
$renderer = $this->page->get_renderer('block_groups');
// Calls Javascript if available.
$PAGE->requires->js_call_amd('block_groups/blocks_groups_visibility', 'initialise', array($courseid));
$groupsarray = array();
$this->page->requires->js_call_amd('block_groups/blocks_groups_visibility', 'initialise', [$courseid]);
$groupsarray = [];
foreach ($allgroups as $value) {
// Checks availability of group and requests the content.
if (is_object($value) && property_exists($value, 'name')) {
$countmembers = count(groups_get_members($value->id));
$href = new moodle_url('/blocks/groups/changevisibility.php',
array('courseid' => $courseid, 'groupid' => $value->id));
if (empty($DB->get_records('block_groups_hide', array('id' => $value->id)))) {
['courseid' => $courseid, 'groupid' => $value->id]);
if (empty($DB->get_records('block_groups_hide', ['id' => $value->id]))) {
$groupsarray[] = $renderer->get_string_group($value, $href, $countmembers, true);
} else {
$groupsarray[] = $renderer->get_string_group($value, $href, $countmembers, false);
Expand All @@ -118,7 +118,7 @@ private function get_content_teaching() {
}

// Empty block or block with checkboxes.
$href = new moodle_url('/group/index.php', array('id' => $courseid));
$href = new moodle_url('/group/index.php', ['id' => $courseid]);
if (count($groupsarray) == 0) {
$content .= html_writer::div(get_string('nogroups', 'block_groups'));
$content .= $renderer->get_link_modify_groups($href);
Expand All @@ -140,16 +140,16 @@ private function get_content_teaching() {
* @return string html-string representing all member groups
*/
private function get_content_groupmembers() {
global $COURSE, $DB, $PAGE;
$enrolledgroups = array();
global $COURSE, $DB;
$enrolledgroups = [];
$allgroups = groups_get_my_groups();
// Necessary to show hidden groups to Course Managers.
$access = has_capability('moodle/course:managegroups', context_course::instance($COURSE->id));
/* @var $renderer block_groups_renderer */
$renderer = $PAGE->get_renderer('block_groups');
/** @var block_groups_renderer $renderer */
$renderer = $this->page->get_renderer('block_groups');
foreach ($allgroups as $group) {
if (($group->courseid == $COURSE->id)) {
$groupdbentry = $DB->get_records('block_groups_hide', array('id' => $group->id));
$groupdbentry = $DB->get_records('block_groups_hide', ['id' => $group->id]);
if (!empty($groupdbentry)) {
$enrolledgroups[] = $renderer->get_tag_group($group, true);
} else if ($access === true) {
Expand All @@ -173,10 +173,9 @@ private function get_content_groupmembers() {
* @return array every key is a group id and point to a grouping
*/
public function build_grouping_array($allgroupings, $courseid) {
global $PAGE;
/* @var $renderer block_groups_renderer */
$renderer = $PAGE->get_renderer('block_groups');
$groupingsarray = array();
/** @var block_groups_renderer $renderer */
$renderer = $this->page->get_renderer('block_groups');
$groupingsarray = [];
$arrayofmembers = count_grouping_members($courseid);
foreach ($allgroupings as $g => $value) {
if (is_object($value) && property_exists($value, 'name')) {
Expand All @@ -187,4 +186,4 @@ public function build_grouping_array($allgroupings, $courseid) {
}
return $groupingsarray;
}
}
}
15 changes: 8 additions & 7 deletions changeallgroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @copyright 2016 N Herrmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../../config.php');
require_login();

Expand All @@ -30,24 +31,24 @@

$PAGE->set_url('/blocks/groups/changeallgroups.php');
// In Case the given id of the course is not available in the database exit message is shown.
if (empty($DB->get_record('course', array('id' => $courseid)))) {
if (empty($DB->get_record('course', ['id' => $courseid]))) {
exit(get_string('nocourse', 'block_groups'));
}
$PAGE->set_context(context_course::instance($courseid));
// Check for capability beforehand not possible since a context is needed.
require_capability('moodle/course:managegroups', context_course::instance($courseid));
// Get all groups of the selected course.
$groupsuitable = $DB->get_records('groups', array('courseid' => $courseid));
$groupsuitable = $DB->get_records('groups', ['courseid' => $courseid]);
// The Course has no groups therefore changing all is not possible.
if (empty($groupsuitable)) {
notice(get_string('nogroups', 'block_groups'),
$CFG->wwwroot . '/course/view.php?id=' . $courseid);
exit();
}
$groups = array();
$groupsvisible = array();
$groups = [];
$groupsvisible = [];
foreach ($groupsuitable as $group) {
$entry = $DB->get_records('block_groups_hide', array('id' => $group->id));
$entry = $DB->get_records('block_groups_hide', ['id' => $group->id]);
// In the Case, that the group of the course has an entry in the 'block_groups_hide' table the group is visible.
if (!empty($entry)) {
$groupsvisible[$group->id] = $group->id;
Expand All @@ -58,7 +59,7 @@

if ($hide === 0) {
$messageaction = 'visible';
$tempgroup = array();
$tempgroup = [];
foreach ($groupsuitable as $group) {
if (!empty($groupsvisible)) {
if (!(in_array($group->id, $groups))) {
Expand All @@ -85,4 +86,4 @@
redirect($CFG->wwwroot . '/course/view.php?id=' . $courseid,
get_string('groupschanged' . $messageaction, 'block_groups'),
null, \core\output\notification::NOTIFY_SUCCESS);
exit();
exit();
5 changes: 3 additions & 2 deletions changevisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @copyright 2016/17 N Herrmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../../config.php');
require_login();

Expand All @@ -30,13 +31,13 @@

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

if (empty($groupsuitable)) {
notice(get_string('nochangeindatabasepossible', 'block_groups'),
Expand Down
7 changes: 2 additions & 5 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,21 @@

namespace block_groups\privacy;

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

/**
* Privacy Subsystem for block_groups implementing null_provider.
*
* @copyright 2018 Tamara Gunkel, Nina Herrmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
// This trait must be included.
use \core_privacy\local\legacy_polyfill;

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function _get_reason() {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
16 changes: 8 additions & 8 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

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

$capabilities = array(
'block/groups:addinstance' => array(
$capabilities = [
'block/groups:addinstance' => [
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/site:manageblocks',
],
];
Loading

0 comments on commit ac9cae4

Please sign in to comment.