diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index ebf9c26..618bd74 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: php: ['8.2'] - moodle-branch: ['MOODLE_403_STABLE'] + moodle-branch: ['MOODLE_404_STABLE'] database: ['pgsql'] steps: @@ -20,7 +20,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 @@ -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 @@ -75,10 +55,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 @@ -86,7 +62,6 @@ jobs: - name: Moodle Code Checker if: ${{ always() }} run: moodle-plugin-ci codechecker - continue-on-error: true - name: Moodle PHPDoc Checker if: ${{ always() }} @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/block_groups.php b/block_groups.php index 1b38fde..bff5b93 100644 --- a/block_groups.php +++ b/block_groups.php @@ -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. */ @@ -83,7 +83,7 @@ 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 @@ -91,25 +91,25 @@ public function applicable_formats() { * @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); @@ -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); @@ -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) { @@ -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')) { @@ -187,4 +186,4 @@ public function build_grouping_array($allgroupings, $courseid) { } return $groupingsarray; } -} \ No newline at end of file +} diff --git a/changeallgroups.php b/changeallgroups.php index f48a584..e93c997 100644 --- a/changeallgroups.php +++ b/changeallgroups.php @@ -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(); @@ -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; @@ -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))) { @@ -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(); \ No newline at end of file +exit(); diff --git a/changevisibility.php b/changevisibility.php index 4b60aef..65f9369 100644 --- a/changevisibility.php +++ b/changevisibility.php @@ -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(); @@ -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'), diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 5136d41..6cd600b 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -24,8 +24,6 @@ namespace block_groups\privacy; -defined('MOODLE_INTERNAL') || die(); - /** * Privacy Subsystem for block_groups implementing null_provider. * @@ -33,15 +31,14 @@ * @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'; } } diff --git a/db/access.php b/db/access.php index 46adbf5..4eef200 100644 --- a/db/access.php +++ b/db/access.php @@ -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' - ), -); \ No newline at end of file + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/site:manageblocks', + ], +]; diff --git a/db/services.php b/db/services.php index 0e7d949..e1ce0f7 100644 --- a/db/services.php +++ b/db/services.php @@ -22,8 +22,8 @@ */ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'block_groups_create_output' => array( +$functions = [ + 'block_groups_create_output' => [ 'classname' => 'block_groups_visibility_change', 'methodname' => 'create_output', 'classpath' => 'blocks/groups/externallib.php', @@ -31,8 +31,8 @@ 'type' => 'write', 'capabilities' => 'moodle/course:managegroups', 'ajax' => true, - ), - 'block_groups_create_allgroups_output' => array( + ], + 'block_groups_create_allgroups_output' => [ 'classname' => 'block_groups_visibilityall_change', 'methodname' => 'create_allgroups_output', 'classpath' => 'blocks/groups/externallib.php', @@ -40,5 +40,5 @@ 'type' => 'write', 'capabilities' => 'moodle/course:managegroups', 'ajax' => true, - ) -); \ No newline at end of file + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index d34aa4f..2baacf9 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -20,7 +20,7 @@ * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); + /** * Function to upgrade for the groups block. * @param integer $oldversion @@ -29,4 +29,4 @@ */ function xmldb_block_groups_upgrade($oldversion) { return true; -} \ No newline at end of file +} diff --git a/externallib.php b/externallib.php index 99dce5d..160672d 100644 --- a/externallib.php +++ b/externallib.php @@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/externallib.php"); +// This is stupid, but for some reason the code checker forbids $PAGE in this file. +// phpcs:disable moodle.PHP.ForbiddenGlobalUse.BadGlobal + /** * block_groups external functions * @@ -31,7 +34,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.9 */ -class block_groups_visibility_change extends external_api{ +class block_groups_visibility_change extends external_api { /** * Specifies the input parameters. @@ -39,14 +42,14 @@ class block_groups_visibility_change extends external_api{ */ public static function create_output_parameters() { return new external_function_parameters( - array( + [ 'groups' => new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'id of group'), 'courseid' => new external_value(PARAM_INT, 'id of course'), - ) - ) - ) + ] + ), + ] ); } @@ -56,12 +59,12 @@ public static function create_output_parameters() { */ public static function create_output_returns() { return new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'id of group'), 'courseid' => new external_value(PARAM_INT, 'id of course'), 'newelement' => new external_value(PARAM_RAW, 'replace html-element'), - 'visibility' => new external_value(PARAM_INT, 'returns the visibility value') - ) + 'visibility' => new external_value(PARAM_INT, 'returns the visibility value'), + ] ); } @@ -72,19 +75,19 @@ public static function create_output_returns() { */ public static function create_output($groups) { global $PAGE, $CFG, $DB; - $params = self::validate_parameters(self::create_output_parameters(), array('groups' => $groups)); + $params = self::validate_parameters(self::create_output_parameters(), ['groups' => $groups]); $PAGE->set_context(context_course::instance($params['groups']['courseid'])); require_capability('moodle/course:managegroups', context_course::instance($params['groups']['courseid'])); require_once($CFG->dirroot.'/blocks/groups/locallib.php'); block_groups_db_transaction_change_visibility($params['groups']['id'], $params['groups']['courseid']); $renderer = $PAGE->get_renderer('block_groups'); - $href = new moodle_url('/blocks/groups/changevisibility.php', array('courseid' => $params['groups']['courseid'], - 'groupid' => $params['groups']['id'])); + $href = new moodle_url('/blocks/groups/changevisibility.php', ['courseid' => $params['groups']['courseid'], + 'groupid' => $params['groups']['id']]); $countmembers = count(groups_get_members($params['groups']['id'])); $group = groups_get_group($params['groups']['id']); - $output = array('id' => $params['groups']['id'], 'courseid' => $params['groups']['courseid']); + $output = ['id' => $params['groups']['id'], 'courseid' => $params['groups']['courseid']]; // Generates the Output component. - $groupvisible = $DB->get_records('block_groups_hide', array('id' => $params['groups']['id'])); + $groupvisible = $DB->get_records('block_groups_hide', ['id' => $params['groups']['id']]); if (empty($groupvisible)) { $output['newelement'] = $renderer->get_string_group($group, $href, $countmembers, true); $output['visibility'] = 1; @@ -103,21 +106,21 @@ public static function create_output($groups) { * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class block_groups_visibilityall_change extends external_api{ +class block_groups_visibilityall_change extends external_api { /** * Specifies the input parameters. */ public static function create_allgroups_output_parameters() { return new external_function_parameters( - array( + [ 'groups' => new external_single_structure( - array( + [ // Insert 1 for hide groups 0 for show groups. 'action' => new external_value(PARAM_RAW, 'action'), 'courseid' => new external_value(PARAM_INT, 'id of course'), - ) - ) - ) + ] + ), + ] ); } @@ -126,18 +129,18 @@ public static function create_allgroups_output_parameters() { */ public static function create_allgroups_output_returns() { return new external_single_structure( - array( + [ 'courseid' => new external_value(PARAM_INT, 'id of course'), 'newelement' => new external_value(PARAM_RAW, 'replace html-element'), 'visibility' => new external_value(PARAM_INT, 'returns the visibility value'), 'changedgroups' => new external_multiple_structure( new external_single_structure( - array( - 'groupid' => new external_value(PARAM_INT, 'group-id', VALUE_OPTIONAL) - ) + [ + 'groupid' => new external_value(PARAM_INT, 'group-id', VALUE_OPTIONAL), + ] ) - ) - ) + ), + ] ); } /** @@ -148,30 +151,30 @@ public static function create_allgroups_output_returns() { */ public static function create_allgroups_output($groups) { global $PAGE, $CFG, $DB; - $params = self::validate_parameters(self::create_allgroups_output_parameters(), array('groups' => $groups)); + $params = self::validate_parameters(self::create_allgroups_output_parameters(), ['groups' => $groups]); require_once($CFG->dirroot.'/blocks/groups/locallib.php'); $PAGE->set_context(context_course::instance($params['groups']['courseid'])); require_capability('moodle/course:managegroups', context_course::instance($params['groups']['courseid'])); - $groupsuitable = $DB->get_records('groups', array('courseid' => $params['groups']['courseid']), 'id ASC'); + $groupsuitable = $DB->get_records('groups', ['courseid' => $params['groups']['courseid']], 'id ASC'); // The Course has no groups therefore changing all is not possible. if (empty($groupsuitable)) { $output['courseid'] = $params['groups']['courseid']; $link = html_writer::link(new moodle_url('/group/index.php', - array('id' => $params['groups']['courseid'])), 'modify groups'); + ['id' => $params['groups']['courseid']]), 'modify groups'); $content = html_writer::div(get_string('nogroups', 'block_groups')) . $link; - $output['newelement'] = html_writer::div($content, array('class' => 'content')); + $output['newelement'] = html_writer::div($content, ['class' => 'content']); $output['visibility'] = '0'; - $output['changedgroups'] = array(); + $output['changedgroups'] = []; return $output; } - $groupsvisible = array(); + $groupsvisible = []; $renderer = $PAGE->get_renderer('block_groups'); 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)) { @@ -182,7 +185,7 @@ public static function create_allgroups_output($groups) { $outputvisibility = '3'; if ($params['groups']['action'] == "show") { $outputvisibility = '4'; - $tempgroup = array(); + $tempgroup = []; if (!empty($groupsuitable)) { foreach ($groupsuitable as $group) { if (!empty($groupsvisible)) { @@ -196,17 +199,17 @@ public static function create_allgroups_output($groups) { } $groups = $tempgroup; } - $output['changedgroups'] = array(); + $output['changedgroups'] = []; if (!empty($groups)) { foreach ($groups as $group) { block_groups_db_transaction_change_visibility($group, $params['groups']['courseid']); - array_push($output['changedgroups'], array('groupid' => $group)); + array_push($output['changedgroups'], ['groupid' => $group]); } } foreach ($groupsuitable as $group) { $fullgroup = groups_get_group($group->id); $href = new moodle_url('/blocks/groups/changevisibility.php', - array('courseid' => $params['groups']['courseid'], 'groupid' => $group->id)); + ['courseid' => $params['groups']['courseid'], 'groupid' => $group->id]); $countmembers = count(groups_get_members($group->id)); if ($params['groups']['action'] == 'hide') { $visibility = true; @@ -217,7 +220,7 @@ public static function create_allgroups_output($groups) { } $groupsarray[] = $renderer->get_string_group($fullgroup, $href, $countmembers, $visibility); } - $output['newelement'] = html_writer::alist($groupsarray, array('class' => 'wrapperlistgroup')); + $output['newelement'] = html_writer::alist($groupsarray, ['class' => 'wrapperlistgroup']); $output['courseid'] = $params['groups']['courseid']; if (empty($groups)) { @@ -235,3 +238,4 @@ public static function create_allgroups_output($groups) { return $output; } } +// phpcs:enable diff --git a/lang/en/block_groups.php b/lang/en/block_groups.php index 5f3cf56..e67f4c9 100644 --- a/lang/en/block_groups.php +++ b/lang/en/block_groups.php @@ -21,26 +21,26 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['allgroupsinstatehidden'] = 'All groups are already hidden.'; +$string['allgroupsinstatevisible'] = 'All groups are already visible.'; +$string['brackets'] = '({$a})'; +$string['changeallgroups'] = 'Change all groups'; +$string['errorbutton'] = 'OK'; +$string['errortitle'] = 'Synchronization error'; +$string['group'] = 'Groups '; +$string['grouping'] = 'Groupings '; $string['groups:addinstance'] = 'Add a new Group block'; $string['groups:myaddinstance'] = 'Add a new Group block to Dashboard'; -$string['pluginname'] = 'Groups and Groupings'; -$string['pluginname2'] = 'Groups'; +$string['groupschangedhidden'] = 'All groups are hidden.'; +$string['groupschangedvisible'] = 'All groups are visible.'; +$string['hidegroup'] = 'hide group'; $string['introduction'] = 'You are enrolled in the following groups'; -$string['group'] = 'Groups '; -$string['grouping'] = 'Groupings '; -$string['brackets'] = '({$a})'; $string['modify'] = 'modify groups'; -$string['hidegroup'] = 'hide group'; -$string['showgroup'] = 'show group'; $string['nochangeindatabasepossible'] = 'The required change was not possible. Please reload the page.'; $string['nochangeindatabasepossiblereload'] = 'The required change was not possible. It is recommended to reload the page, do you want to reload the page?'; $string['nocourse'] = 'Problem to find course, please try again later.'; $string['nogroups'] = 'The requested course has no groups.'; -$string['allgroupsinstatehidden'] = 'All groups are already hidden.'; -$string['allgroupsinstatevisible'] = 'All groups are already visible.'; -$string['groupschangedhidden'] = 'All groups are hidden.'; -$string['groupschangedvisible'] = 'All groups are visible.'; -$string['errortitle'] = 'Synchronization error'; -$string['errorbutton'] = 'OK'; -$string['changeallgroups'] = 'Change all groups'; +$string['pluginname'] = 'Groups and Groupings'; +$string['pluginname2'] = 'Groups'; $string['privacy:metadata'] = 'The Group block only displays information about groups, but does not effect or store any personal data. The existing groups and groupings data are stored in other locations.'; +$string['showgroup'] = 'show group'; diff --git a/locallib.php b/locallib.php index 7c2e564..2a177af 100644 --- a/locallib.php +++ b/locallib.php @@ -20,7 +20,7 @@ * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); + /** * Executes a change in the block_groups_hide database * @param integer $groupid @@ -29,15 +29,15 @@ function block_groups_db_transaction_change_visibility($groupid, $courseid) { global $DB; $transaction = $DB->start_delegated_transaction(); - $groupsuitable = $DB->get_record('groups', array('id' => $groupid, 'courseid' => $courseid)); - $groupvisible = $DB->get_records('block_groups_hide', array('id' => $groupid)); + $groupsuitable = $DB->get_record('groups', ['id' => $groupid, 'courseid' => $courseid]); + $groupvisible = $DB->get_records('block_groups_hide', ['id' => $groupid]); if (!empty($groupsuitable)) { if (empty($groupvisible)) { // Methode neccessary since id is the only column. - $DB->insert_record_raw('block_groups_hide', array('id' => $groupid), true, false, true); + $DB->insert_record_raw('block_groups_hide', ['id' => $groupid], true, false, true); } if (!empty($groupvisible)) { - $DB->delete_records('block_groups_hide', array('id' => $groupid)); + $DB->delete_records('block_groups_hide', ['id' => $groupid]); } } $transaction->allow_commit(); @@ -48,7 +48,7 @@ function block_groups_db_transaction_change_visibility($groupid, $courseid) { * @return array of database records */ function count_grouping_members ($courseid) { - global $DB; + global $DB, $PAGE; return $DB->get_records_sql('SELECT g.id, Count(DISTINCT gm.userid) AS number FROM {groups_members} gm RIGHT JOIN {groupings_groups} gg diff --git a/renderer.php b/renderer.php index 8104827..46681a6 100644 --- a/renderer.php +++ b/renderer.php @@ -21,7 +21,6 @@ * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die; /** * Class of the block_groups renderer. @@ -44,11 +43,11 @@ public function teaching_groups_or_groupings_list($elementarray, $group) { } else { $type = 'grouping'; } - $contentgroups = html_writer::tag('input', '', array('type' => "checkbox", 'value' => "1", - 'class' => "blockgroupsandgroupingcheckbox", 'id' => 'checkbox' . $type)) . - html_writer::tag('label', get_string($type, 'block_groups'), array('for' => "checkbox" . $type)); - $contentgroups .= html_writer::alist($elementarray, array('class' => 'wrapperlist' . $type)); - return html_writer::tag('div', $contentgroups, array('class' => 'wrapperblockgroupsandgroupingcheckbox')); + $contentgroups = html_writer::tag('input', '', ['type' => "checkbox", 'value' => "1", + 'class' => "blockgroupsandgroupingcheckbox", 'id' => 'checkbox' . $type]) . + html_writer::tag('label', get_string($type, 'block_groups'), ['for' => "checkbox" . $type]); + $contentgroups .= html_writer::alist($elementarray, ['class' => 'wrapperlist' . $type]); + return html_writer::tag('div', $contentgroups, ['class' => 'wrapperblockgroupsandgroupingcheckbox']); } /** @@ -70,7 +69,6 @@ public function get_link_modify_groups($href) { * @return string html-string */ public function get_string_group($value, $href, $countmembers, $visibility) { - global $OUTPUT; if ($visibility === false) { $action = 'hide'; @@ -81,13 +79,13 @@ public function get_string_group($value, $href, $countmembers, $visibility) { $message = get_string('showgroup', 'block_groups'); $spanstring = 'hiddengroups'; } - $icon = $OUTPUT->pix_icon('t/' . $action, $message, 'moodle', - array('class' => "imggroup-". $value->id . ' imggroup')); + $icon = $this->output->pix_icon('t/' . $action, $message, 'moodle', + ['class' => "imggroup-". $value->id . ' imggroup']); $rightaligndiv = html_writer::div($icon, 'rightalign'); $line = html_writer::span($value->name . ' ' .get_string('brackets', 'block_groups', $countmembers), $spanstring) . - html_writer::link($href, $rightaligndiv, array('class' => 'block_groups_toggle', 'data-groupid' => $value->id, - 'data-action' => $action)); + html_writer::link($href, $rightaligndiv, ['class' => 'block_groups_toggle', 'data-groupid' => $value->id, + 'data-action' => $action]); return html_writer::span($line, 'group-'. $value->id); } /** @@ -144,7 +142,7 @@ public function get_tag_group($group, $visibility) { * @return string html_link */ private function create_all_groups_link($action, $reverseimage = true) { - global $OUTPUT, $CFG, $COURSE; + global $CFG, $COURSE; if ($action === 'hide') { $actionnumber = 0; $reverse = 'show'; @@ -153,11 +151,11 @@ private function create_all_groups_link($action, $reverseimage = true) { $reverse = 'hide'; } $urlhide = new moodle_url($CFG->wwwroot . '/blocks/groups/changeallgroups.php', - array('courseid' => $COURSE->id, 'hide' => $actionnumber)); + ['courseid' => $COURSE->id, 'hide' => $actionnumber]); - $icon = $OUTPUT->pix_icon('t/' . ($reverseimage ? $reverse : $action), get_string($reverse . 'group', 'block_groups'), - 'moodle', array('class' => "imggroup-all imggroup")); + $icon = $this->output->pix_icon('t/' . ($reverseimage ? $reverse : $action), get_string($reverse . 'group', 'block_groups'), + 'moodle', ['class' => "imggroup-all imggroup"]); $rightaligndiv = html_writer::div($icon, 'rightalign'); - return html_writer::link($urlhide, $rightaligndiv, array('data-action' => $reverse, 'class' => 'block_groups_all_toggle')); + return html_writer::link($urlhide, $rightaligndiv, ['data-action' => $reverse, 'class' => 'block_groups_all_toggle']); } -} \ No newline at end of file +} diff --git a/tests/behat/behat_block_groups.php b/tests/behat/behat_block_groups.php index ec9389d..a8f466f 100644 --- a/tests/behat/behat_block_groups.php +++ b/tests/behat/behat_block_groups.php @@ -92,4 +92,4 @@ public function i_click_in_the_groups_block_on_all_groups($action) { $eyeicon->click(); } -} \ No newline at end of file +} diff --git a/tests/block_groups_test.php b/tests/block_groups_test.php index df2d1e4..5a92d38 100644 --- a/tests/block_groups_test.php +++ b/tests/block_groups_test.php @@ -21,7 +21,8 @@ * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); + +namespace block_groups; /** * Class block_groups_testcase @@ -31,7 +32,7 @@ * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class block_groups_testcase extends advanced_testcase { +final class block_groups_test extends \advanced_testcase { /** * Set up environment for phpunit test. @@ -47,8 +48,9 @@ protected function set_up() { } /** * Function to test the locallib functions. + * @covers \count_grouping_members */ - public function test_locallib() { + public function test_locallib(): void { global $DB, $CFG; require_once($CFG->dirroot.'/blocks/groups/locallib.php'); $data = $this->set_up(); @@ -56,8 +58,8 @@ public function test_locallib() { block_groups_db_transaction_change_visibility($data['group1']->id, $data['course2']->id); block_groups_db_transaction_change_visibility($data['group2']->id, $data['course2']->id); block_groups_db_transaction_change_visibility($data['group2']->id, $data['course2']->id); - $functionresultshow = $DB->get_records('block_groups_hide', array('id' => $data['group1']->id)); - $functionresulthide = $DB->get_records('block_groups_hide', array('id' => $data['group2']->id)); + $functionresultshow = $DB->get_records('block_groups_hide', ['id' => $data['group1']->id]); + $functionresulthide = $DB->get_records('block_groups_hide', ['id' => $data['group2']->id]); $booleanvisible = empty($functionresultshow); $booleandeleted = empty($functionresulthide); @@ -75,8 +77,9 @@ public function test_locallib() { } /** * Methodes recommended by moodle to assure database and dataroot is reset. + * @coversNothing */ - public function test_deleting() { + public function test_deleting(): void { global $DB; $this->resetAfterTest(true); $DB->delete_records('user'); @@ -86,10 +89,11 @@ public function test_deleting() { } /** * Methodes recommended by moodle to assure database is reset. + * @coversNothing */ - public function test_user_table_was_reset() { + public function test_user_table_was_reset(): void { global $DB; - $this->assertEquals(2, $DB->count_records('user', array())); - $this->assertEquals(0, $DB->count_records('block_groups_hide', array())); + $this->assertEquals(2, $DB->count_records('user', [])); + $this->assertEquals(0, $DB->count_records('block_groups_hide', [])); } -} \ No newline at end of file +} diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 922c082..e8e6b20 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -22,8 +22,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Generator class for the block_groups testcase. @@ -37,29 +35,29 @@ class block_groups_generator extends testing_block_generator { /** * Creates Course, course members, groups and groupings to test the block. */ - public function test_create_preparation () { + public function test_create_preparation() { $generator = advanced_testcase::getDataGenerator(); - $data = array(); - $course2 = $generator->create_course(array('name' => 'Some course')); + $data = []; + $course2 = $generator->create_course(['name' => 'Some course']); $data['course2'] = $course2; // Creates groups. - $group1 = $generator->create_group(array('courseid' => $course2->id)); + $group1 = $generator->create_group(['courseid' => $course2->id]); $data['group1'] = $group1; - $group2 = $generator->create_group(array('courseid' => $course2->id)); + $group2 = $generator->create_group(['courseid' => $course2->id]); $data['group2'] = $group2; - $group21 = $generator->create_group(array('courseid' => $course2->id)); + $group21 = $generator->create_group(['courseid' => $course2->id]); $data['group21'] = $group21; // Create 3 groupings in course 2. - $grouping1 = $generator->create_grouping(array('courseid' => $course2->id)); + $grouping1 = $generator->create_grouping(['courseid' => $course2->id]); $data['grouping1'] = $grouping1; - $grouping2 = $generator->create_grouping(array('courseid' => $course2->id)); + $grouping2 = $generator->create_grouping(['courseid' => $course2->id]); $data['grouping2'] = $grouping2; - $grouping3 = $generator->create_grouping(array('courseid' => $course2->id)); + $grouping3 = $generator->create_grouping(['courseid' => $course2->id]); $data['grouping3'] = $grouping3; // Add Grouping to groups. - $generator->create_grouping_group(array('groupingid' => $grouping1->id, 'groupid' => $group1->id)); - $generator->create_grouping_group(array('groupingid' => $grouping2->id, 'groupid' => $group2->id)); - $generator->create_grouping_group(array('groupingid' => $grouping2->id, 'groupid' => $group21->id)); + $generator->create_grouping_group(['groupingid' => $grouping1->id, 'groupid' => $group1->id]); + $generator->create_grouping_group(['groupingid' => $grouping2->id, 'groupid' => $group2->id]); + $generator->create_grouping_group(['groupingid' => $grouping2->id, 'groupid' => $group21->id]); // Initiates the groupings and grouping members. // Creates 4 Users, enroles them in course2. @@ -68,13 +66,13 @@ public function test_create_preparation () { $generator->enrol_user($user->id, $course2->id); $data['user' . $i] = $user; } - $generator->create_group_member(array('groupid' => $group1->id, 'userid' => $data['user1']->id)); - $generator->create_group_member(array('groupid' => $group1->id, 'userid' => $data['user2']->id)); - $generator->create_group_member(array('groupid' => $group2->id, 'userid' => $data['user3']->id)); - $generator->create_group_member(array('groupid' => $group21->id, 'userid' => $data['user4']->id)); - $generator->create_group_member(array('groupid' => $group21->id, 'userid' => $data['user3']->id)); - $generator->create_group_member(array('groupid' => $group2->id, 'userid' => $data['user4']->id)); - $generator->create_group_member(array('groupid' => $group21->id, 'userid' => $data['user2']->id)); + $generator->create_group_member(['groupid' => $group1->id, 'userid' => $data['user1']->id]); + $generator->create_group_member(['groupid' => $group1->id, 'userid' => $data['user2']->id]); + $generator->create_group_member(['groupid' => $group2->id, 'userid' => $data['user3']->id]); + $generator->create_group_member(['groupid' => $group21->id, 'userid' => $data['user4']->id]); + $generator->create_group_member(['groupid' => $group21->id, 'userid' => $data['user3']->id]); + $generator->create_group_member(['groupid' => $group2->id, 'userid' => $data['user4']->id]); + $generator->create_group_member(['groupid' => $group21->id, 'userid' => $data['user2']->id]); return $data; // Return the user, course and group objects. } -} \ No newline at end of file +} diff --git a/tests/generator_test.php b/tests/generator_test.php index 6612cf4..67a048f 100644 --- a/tests/generator_test.php +++ b/tests/generator_test.php @@ -21,8 +21,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - +namespace block_groups; /** * PHPUnit data generator testcase @@ -32,14 +31,19 @@ * @copyright 2016/17 N Herrmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class block_groups_generator_testcase extends advanced_testcase { - public function test_generator() { +final class generator_test extends \advanced_testcase { + + /** + * Test generator. + * @covers \block_groups_generator + */ + public function test_generator(): void { global $DB; $this->resetAfterTest(true); $beforeblocks = $DB->count_records('block_instances'); - /** @var block_online_users_generator $generator */ + /** @var \block_groups_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('block_groups'); $this->assertInstanceOf('block_groups_generator', $generator); $this->assertEquals('groups', $generator->get_blockname()); @@ -47,4 +51,4 @@ public function test_generator() { $generator->create_instance(); $this->assertEquals($beforeblocks + 1, $DB->count_records('block_instances')); } -} \ No newline at end of file +}