From eda9553cf8099227eede95131eb0f62b0a94f56f Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 10:24:51 +0200 Subject: [PATCH 01/17] Refactor create_allgroups_output --- classes/external/create_allgroups_output.php | 132 ++++++++++--------- 1 file changed, 73 insertions(+), 59 deletions(-) diff --git a/classes/external/create_allgroups_output.php b/classes/external/create_allgroups_output.php index ad66ca3..ab6cadc 100644 --- a/classes/external/create_allgroups_output.php +++ b/classes/external/create_allgroups_output.php @@ -78,29 +78,46 @@ public static function execute_returns() { public static function execute($groups) { global $PAGE, $CFG, $DB; $params = self::validate_parameters(self::execute_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', ['courseid' => $params['groups']['courseid']], 'id ASC'); - // The Course has no groups therefore changing all is not possible. + // 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', - ['id' => $params['groups']['courseid']] - ), 'modify groups'); - $content = html_writer::div(get_string('nogroups', 'block_groups')) . $link; - $output['newelement'] = html_writer::div($content, ['class' => 'content']); - $output['visibility'] = '0'; - $output['changedgroups'] = []; - return $output; + return self::createNoGroupsResponse($params['groups']['courseid']); } - $groupsvisible = []; - $renderer = $PAGE->get_renderer('block_groups'); + $groupsToChange = self::get_groups_to_change($params['groups']['action'], $groupsuitable); + $changedGroups = self::update_group_visibility($groupsToChange, $params['groups']['courseid']); + $html = self::genererate_groups_html($groupsuitable, $params['groups']['courseid'], $params['groups']['action']); + $statusCode = self::get_status_code($params['groups']['action'], $groupsToChange); + + return [ + 'courseid' => $params['groups']['courseid'], + 'newelement' => $html, + 'visibility' => $statusCode, + 'changedgroups' => $changedGroups + ]; + } + + private static function createNoGroupsResponse($courseid) { + $output['courseid'] = $courseid; + $link = html_writer::link(new moodle_url( + '/group/index.php', + ['id' => $courseid] + ), 'modify groups'); + $content = html_writer::div(get_string('nogroups', 'block_groups')) . $link; + $output['newelement'] = html_writer::div($content, ['class' => 'content']); + $output['visibility'] = '0'; + $output['changedgroups'] = []; + return $output; + } + + private static function get_groups_to_change($action, $groupsuitable) { + global $DB; + + $groupsvisible = []; foreach ($groupsuitable as $group) { $entry = $DB->get_records('block_groups_hide', ['id' => $group->id]); @@ -109,61 +126,58 @@ public static function execute($groups) { $groupsvisible[$group->id] = $group->id; } } - $groups = $groupsvisible; - $outputvisibility = '3'; - if ($params['groups']['action'] == "show") { - $outputvisibility = '4'; + + if ($action == "show") { $tempgroup = []; - if (!empty($groupsuitable)) { - foreach ($groupsuitable as $group) { - if (!empty($groupsvisible)) { - if (!(in_array($group->id, $groups))) { - $tempgroup[$group->id] = $group->id; - } - } else { - $tempgroup[$group->id] = $group->id; - } + foreach ($groupsuitable as $group) { + if (!in_array($group->id, $groupsvisible)) { + $tempgroup[$group->id] = $group->id; } } - $groups = $tempgroup; + return $tempgroup; } - $output['changedgroups'] = []; - if (!empty($groups)) { - foreach ($groups as $group) { - block_groups_db_transaction_change_visibility($group, $params['groups']['courseid']); - array_push($output['changedgroups'], ['groupid' => $group]); - } + + return $groupsvisible; + } + + private static function update_group_visibility($groups, $courseid) { + global $CFG; + require_once($CFG->dirroot . '/blocks/groups/locallib.php'); + + $changedgroups = []; + foreach ($groups as $groupid) { + block_groups_db_transaction_change_visibility($groupid, $courseid); + $changedgroups[] = ['groupid' => $groupid]; } + return $changedgroups; + } + + private static function genererate_groups_html($groupsuitable, $courseid, $action) { + global $PAGE; + + $renderer = $PAGE->get_renderer('block_groups'); + $groupsarray = []; + foreach ($groupsuitable as $group) { $fullgroup = groups_get_group($group->id); $href = new moodle_url( - '/blocks/groups/changevisibility.php', - ['courseid' => $params['groups']['courseid'], 'groupid' => $group->id] + '/blocks/groups/changevisibility.php', + ['courseid' => $courseid, 'groupid' => $group->id] ); $countmembers = count(groups_get_members($group->id)); - if ($params['groups']['action'] == 'hide') { - $visibility = true; - } - if ($params['groups']['action'] == 'show') { - $visibility = false; - } - $groupsarray[] = $renderer->get_string_group($fullgroup, $href, $countmembers, $visibility); + $visibility = ($action == "show") ? false : true; + $groupsarray[] = $renderer->get_string_group( + $fullgroup, $href, $countmembers, $visibility + ); } - $output['newelement'] = html_writer::alist($groupsarray, ['class' => 'wrapperlistgroup']); - $output['courseid'] = $params['groups']['courseid']; + return html_writer::alist($groupsarray, ['class' => 'wrapperlistgroup']); + } - if (empty($groups)) { - $output['visibility'] = $outputvisibility; - return $output; - } - // Parameter $outputvisibility 0->nogroups 1 -> hidden 2->visible 3-> all are hidden 4-> all are visible. - if ($params['groups']['action'] == 'hide') { - $outputvisibility = 1; - } - if ($params['groups']['action'] == 'show') { - $outputvisibility = 2; + private static function get_status_code($action, $groupsToChange) { + if (empty($groupsToChange)) { + return ($action == "show") ? 4 : 3; } - $output['visibility'] = $outputvisibility; - return $output; + + return ($action == "hide") ? 1 : 2; } } From 622a57372c0572a916efee4ecb8cf3a73a269fff Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 17:57:00 +0200 Subject: [PATCH 02/17] Adding a settings file --- block_groups.php | 8 ++++++++ settings.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 settings.php diff --git a/block_groups.php b/block_groups.php index b6a6851..e59289f 100644 --- a/block_groups.php +++ b/block_groups.php @@ -187,4 +187,12 @@ public function build_grouping_array($allgroupings, $courseid) { } return $groupingsarray; } + + /** + * Tells moodle, that the groups block has a settings file. + * @return bool true + */ + public function has_config() { + return true; + } } diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..daa500c --- /dev/null +++ b/settings.php @@ -0,0 +1,31 @@ +. + +/** + * Groups block settings + * + * @package block_groups + * @copyright 2026 Lena Herfeldt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + $settings->add(new admin_setting_configcheckbox('block_groups_showgroupsdefaultsetting', get_string('showgroupsdefaultsetting', 'block_groups'), + get_string('configshowgroupsandgroupings', 'block_groups'), 0)); +} + From be05b3b0c07eb25e01ce82daa164a7a6fd56212f Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 17:59:40 +0200 Subject: [PATCH 03/17] adding language files for the settings --- lang/en/block_groups.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/en/block_groups.php b/lang/en/block_groups.php index e436a3f..769969c 100644 --- a/lang/en/block_groups.php +++ b/lang/en/block_groups.php @@ -45,3 +45,5 @@ $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'; +$string['showgroupsdefaultsetting'] = 'Show groups and groupings by default'; +$string['configshowgroupsandgroupings'] = 'The groups block will not show groups and groupings by default. By enabling this, admins/teachers choose to show groups/groupings immediately after the creation.'; From 315434f83e9f45aa698356b04c8f153fea5553b0 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 18:00:53 +0200 Subject: [PATCH 04/17] refactoring settings file for phpcs --- settings.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/settings.php b/settings.php index daa500c..5b476ca 100644 --- a/settings.php +++ b/settings.php @@ -25,7 +25,12 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - $settings->add(new admin_setting_configcheckbox('block_groups_showgroupsdefaultsetting', get_string('showgroupsdefaultsetting', 'block_groups'), - get_string('configshowgroupsandgroupings', 'block_groups'), 0)); + $settings->add( + new admin_setting_configcheckbox( + 'block_groups/show_groups_default_setting', + get_string('showgroupsdefaultsetting', 'block_groups'), + get_string('configshowgroupsandgroupings', 'block_groups'), + 0 + ) + ); } - From 38459b4a0d3dd02c4c3c86b0258e212270c519c0 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 18:06:53 +0200 Subject: [PATCH 05/17] More fixes for phpcs --- classes/external/create_allgroups_output.php | 65 +++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/classes/external/create_allgroups_output.php b/classes/external/create_allgroups_output.php index ab6cadc..75d8ecc 100644 --- a/classes/external/create_allgroups_output.php +++ b/classes/external/create_allgroups_output.php @@ -85,27 +85,32 @@ public static function execute($groups) { // The Course has no groups therefore changing all is not possible. if (empty($groupsuitable)) { - return self::createNoGroupsResponse($params['groups']['courseid']); + return self::create_no_groups_response($params['groups']['courseid']); } - $groupsToChange = self::get_groups_to_change($params['groups']['action'], $groupsuitable); - $changedGroups = self::update_group_visibility($groupsToChange, $params['groups']['courseid']); - $html = self::genererate_groups_html($groupsuitable, $params['groups']['courseid'], $params['groups']['action']); - $statusCode = self::get_status_code($params['groups']['action'], $groupsToChange); + $groupstochange = self::get_groups_to_change($params['groups']['action'], $groupsuitable); + $changedgroups = self::update_group_visibility($groupstochange, $params['groups']['courseid']); + $html = self::generate_groups_html($groupsuitable, $params['groups']['courseid'], $params['groups']['action']); + $statuscode = self::get_status_code($params['groups']['action'], $groupstochange); return [ 'courseid' => $params['groups']['courseid'], 'newelement' => $html, - 'visibility' => $statusCode, - 'changedgroups' => $changedGroups + 'visibility' => $statuscode, + 'changedgroups' => $changedgroups, ]; } - private static function createNoGroupsResponse($courseid) { + /** + * Returns the response if the course has no groups. + * @param int $courseid + * @return array + */ + private static function create_no_groups_response($courseid) { $output['courseid'] = $courseid; $link = html_writer::link(new moodle_url( - '/group/index.php', - ['id' => $courseid] + '/group/index.php', + ['id' => $courseid] ), 'modify groups'); $content = html_writer::div(get_string('nogroups', 'block_groups')) . $link; $output['newelement'] = html_writer::div($content, ['class' => 'content']); @@ -114,6 +119,12 @@ private static function createNoGroupsResponse($courseid) { return $output; } + /** + * Returns the groups which should be changed depending on the action. + * @param string $action + * @param array $groupsuitable + * @return array + */ private static function get_groups_to_change($action, $groupsuitable) { global $DB; @@ -140,6 +151,12 @@ private static function get_groups_to_change($action, $groupsuitable) { return $groupsvisible; } + /** + * Changes the visibility of the groups in the database. + * @param array $groups + * @param int $courseid + * @return array + */ private static function update_group_visibility($groups, $courseid) { global $CFG; require_once($CFG->dirroot . '/blocks/groups/locallib.php'); @@ -152,7 +169,14 @@ private static function update_group_visibility($groups, $courseid) { return $changedgroups; } - private static function genererate_groups_html($groupsuitable, $courseid, $action) { + /** + * Generates the html for all groups of the course. + * @param array $groupsuitable + * @param int $courseid + * @param string $action + * @return string + */ + private static function generate_groups_html($groupsuitable, $courseid, $action) { global $PAGE; $renderer = $PAGE->get_renderer('block_groups'); @@ -161,20 +185,29 @@ private static function genererate_groups_html($groupsuitable, $courseid, $actio foreach ($groupsuitable as $group) { $fullgroup = groups_get_group($group->id); $href = new moodle_url( - '/blocks/groups/changevisibility.php', - ['courseid' => $courseid, 'groupid' => $group->id] + '/blocks/groups/changevisibility.php', + ['courseid' => $courseid, 'groupid' => $group->id] ); $countmembers = count(groups_get_members($group->id)); $visibility = ($action == "show") ? false : true; $groupsarray[] = $renderer->get_string_group( - $fullgroup, $href, $countmembers, $visibility + $fullgroup, + $href, + $countmembers, + $visibility ); } return html_writer::alist($groupsarray, ['class' => 'wrapperlistgroup']); } - private static function get_status_code($action, $groupsToChange) { - if (empty($groupsToChange)) { + /** + * Returns the status code for the response depending on the action and the groups which should be changed. + * @param string $action + * @param array $groupstochange + * @return int + */ + private static function get_status_code($action, $groupstochange) { + if (empty($groupstochange)) { return ($action == "show") ? 4 : 3; } From d05d2b7de84f8e487752806e377c0026e9b143df Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 18:08:38 +0200 Subject: [PATCH 06/17] event observing and handling whenever the settings are not in default for groups --- classes/observers/group_observer.php | 54 ++++++++++++++++++++++++++++ db/events.php | 32 +++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 classes/observers/group_observer.php create mode 100644 db/events.php diff --git a/classes/observers/group_observer.php b/classes/observers/group_observer.php new file mode 100644 index 0000000..b7c7b78 --- /dev/null +++ b/classes/observers/group_observer.php @@ -0,0 +1,54 @@ +. + +/** + * Event observers for the groups block. + * + * @package block_groups + * @copyright 2026 Lena Herfeldt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_groups\observers; + +/** + * Observer for group events + */ +class group_observer { + /** + * Handles the group_created event. + * Automatically adds new groups to block_groups_hide table if show_groups_default_setting is enabled. + * + * @param \core\event\group_created $event + */ + public static function group_created(\core\event\group_created $event) { + global $DB; + + // Checking if the setting is enabled. + $showalways = get_config('block_groups', 'show_groups_default_setting'); + + if (!$showalways) { + return; + } + + $groupid = $event->objectid; + + // Insert directly into the block_groups_hide table to make it visible from the start. + if (!$DB->record_exists('block_groups_hide', ['id' => $groupid])) { + $DB->insert_record_raw('block_groups_hide', ['id' => $groupid], true, false, true); + } + } +} diff --git a/db/events.php b/db/events.php new file mode 100644 index 0000000..7d90229 --- /dev/null +++ b/db/events.php @@ -0,0 +1,32 @@ +. + +/** + * Event observers for the groups block. + * + * @package block_groups + * @copyright 2026 Lena Herfeldt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$observers = [ + [ + 'eventname' => '\core\event\group_created', + 'callback' => '\block_groups\observers\group_observer::group_created', + ], +]; From 0f5a98beec569758060afd5cd15fd16d599f6752 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 18:13:50 +0200 Subject: [PATCH 07/17] bugfix but will have to merge other PR with just bugfix first --- classes/output/renderer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 67abb71..de2a007 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -17,6 +17,8 @@ namespace block_groups\output; use plugin_renderer_base; +use html_writer; +use moodle_url; /** * Class of the block_groups renderer. From 9dac3f5b18cf1d8dc54477b85518df57f16b9c28 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 20 May 2026 18:14:19 +0200 Subject: [PATCH 08/17] version --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index fb698e4..70d5e4a 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2026030400; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2026052001; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022112800; // Requires 4.1+ Moodle version. $plugin->component = 'block_groups'; // Full name of the plugin (used for diagnostics). $plugin->release = 'v5.0-r1'; From 54d2dd556c22be6fb9c0c3dc7593b4cd914714cf Mon Sep 17 00:00:00 2001 From: lenaherf Date: Mon, 25 May 2026 11:52:49 +0200 Subject: [PATCH 09/17] Refactoring spacing in cucumber tests and adding check that setting is default --- tests/behat/change_all.feature | 47 +++++++++++++++++----------------- tests/behat/hide_group.feature | 43 ++++++++++++++++--------------- tests/behat/show_group.feature | 47 +++++++++++++++++----------------- 3 files changed, 70 insertions(+), 67 deletions(-) diff --git a/tests/behat/change_all.feature b/tests/behat/change_all.feature index 13a585b..a947783 100644 --- a/tests/behat/change_all.feature +++ b/tests/behat/change_all.feature @@ -5,35 +5,36 @@ Feature: Change all groups in a group block In need to change all groups Background: - Given the following "courses" exist: + Given the "show groups default setting" is set to default + And the following "courses" exist: | fullname | shortname | category | - | Course 1 | C1 | 0 | + | Course 1 | C1 | 0 | And the following "users" exist: - | username | firstname | lastname | email | idnumber | - | teacher1 | Teacher | 1 | teacher1@example.com | T1 | - | student1 | Student | 1 | student1@example.com | S1 | - | student2 | Student | 2 | student2@example.com | S2 | - | student3 | Student | 3 | student3@example.com | S3 | + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + | student1 | Student | 1 | student1@example.com | S1 | + | student2 | Student | 2 | student2@example.com | S2 | + | student3 | Student | 3 | student3@example.com | S3 | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - | student2 | C1 | student | - | student3 | C1 | student | + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | And the following "groups" exist: - | name | course | idnumber | - | Group 1 | C1 | G1 | - | Group 2 | C1 | G2 | - | Group 3 | C1 | G3 | + | name | course | idnumber | + | Group 1 | C1 | G1 | + | Group 2 | C1 | G2 | + | Group 3 | C1 | G3 | And the following "groupings" exist: - | name | course | idnumber | - | Grouping 1 | C1 | GG1 | - | Grouping 2 | C1 | GG2 | + | name | course | idnumber | + | Grouping 1 | C1 | GG1 | + | Grouping 2 | C1 | GG2 | And the following "group members" exist: - | user | group | - | student1 | G1 | - | student2 | G1 | - | student2 | G2 | + | user | group | + | student1 | G1 | + | student2 | G1 | + | student2 | G2 | And the following "grouping groups" exist: | grouping | group | | GG1 | G1 | diff --git a/tests/behat/hide_group.feature b/tests/behat/hide_group.feature index f475e95..cdfc0c4 100644 --- a/tests/behat/hide_group.feature +++ b/tests/behat/hide_group.feature @@ -5,35 +5,36 @@ Feature: Hide a group in a group block In need to hide groups Background: - Given the following "courses" exist: + Given the "show groups default setting" is set to default + And the following "courses" exist: | fullname | shortname | category | - | Course 1 | C1 | 0 | + | Course 1 | C1 | 0 | And the following "users" exist: - | username | firstname | lastname | email | idnumber | - | teacher1 | Teacher | 1 | teacher1@example.com | T1 | - | student1 | Student | 1 | student1@example.com | S1 | - | student2 | Student | 2 | student2@example.com | S2 | - | student3 | Student | 3 | student3@example.com | S3 | + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + | student1 | Student | 1 | student1@example.com | S1 | + | student2 | Student | 2 | student2@example.com | S2 | + | student3 | Student | 3 | student3@example.com | S3 | And the following "course enrolments" exist: - | user | course | role | + | user | course | role | | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - | student2 | C1 | student | - | student3 | C1 | student | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | And the following "groups" exist: - | name | course | idnumber | - | Group 1 | C1 | G1 | - | Group 2 | C1 | G2 | - | Group 3 | C1 | G3 | + | name | course | idnumber | + | Group 1 | C1 | G1 | + | Group 2 | C1 | G2 | + | Group 3 | C1 | G3 | And the following "groupings" exist: - | name | course | idnumber | - | Grouping 1 | C1 | GG1 | - | Grouping 2 | C1 | GG2 | + | name | course | idnumber | + | Grouping 1 | C1 | GG1 | + | Grouping 2 | C1 | GG2 | And the following "group members" exist: | user | group | - | student1 | G1 | - | student2 | G1 | - | student2 | G2 | + | student1 | G1 | + | student2 | G1 | + | student2 | G2 | And the following "grouping groups" exist: | grouping | group | | GG1 | G1 | diff --git a/tests/behat/show_group.feature b/tests/behat/show_group.feature index ade5915..8206754 100644 --- a/tests/behat/show_group.feature +++ b/tests/behat/show_group.feature @@ -5,35 +5,36 @@ Feature: Make a group visible in a group block In need to make groups visible Background: - Given the following "courses" exist: + Given the "show groups default setting" is enabled + And the following "courses" exist: | fullname | shortname | category | - | Course 1 | C1 | 0 | + | Course 1 | C1 | 0 | And the following "users" exist: - | username | firstname | lastname | email | idnumber | - | teacher1 | Teacher | 1 | teacher1@example.com | T1 | - | student1 | Student | 1 | student1@example.com | S1 | - | student2 | Student | 2 | student2@example.com | S2 | - | student3 | Student | 3 | student3@example.com | S3 | + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + | student1 | Student | 1 | student1@example.com | S1 | + | student2 | Student | 2 | student2@example.com | S2 | + | student3 | Student | 3 | student3@example.com | S3 | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - | student2 | C1 | student | - | student3 | C1 | student | + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | And the following "groups" exist: - | name | course | idnumber | - | Group 1 | C1 | 1 | - | Group 2 | C1 | 2 | + | name | course | idnumber | + | Group 1 | C1 | 1 | + | Group 2 | C1 | 2 | And the following "groupings" exist: - | name | course | idnumber | - | Grouping 1 | C1 | GG1 | - | Grouping 2 | C1 | GG2 | + | name | course | idnumber | + | Grouping 1 | C1 | GG1 | + | Grouping 2 | C1 | GG2 | And the following "group members" exist: - | user | group | - | student1 | 1 | - | student2 | 1 | - | student3 | 2 | - | teacher1 | 1 | + | user | group | + | student1 | 1 | + | student2 | 1 | + | student3 | 2 | + | teacher1 | 1 | And the following "grouping groups" exist: | grouping | group | | GG1 | 1 | From 2da557430880d2e75c7f093f154287ec8b710192 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 12:07:50 +0200 Subject: [PATCH 10/17] remove the changes again it was not necessary --- tests/behat/change_all.feature | 3 +-- tests/behat/hide_group.feature | 13 ++++++------- tests/behat/show_group.feature | 13 ++++++------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/behat/change_all.feature b/tests/behat/change_all.feature index a947783..6e1366d 100644 --- a/tests/behat/change_all.feature +++ b/tests/behat/change_all.feature @@ -5,8 +5,7 @@ Feature: Change all groups in a group block In need to change all groups Background: - Given the "show groups default setting" is set to default - And the following "courses" exist: + Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "users" exist: diff --git a/tests/behat/hide_group.feature b/tests/behat/hide_group.feature index cdfc0c4..3b708a6 100644 --- a/tests/behat/hide_group.feature +++ b/tests/behat/hide_group.feature @@ -5,8 +5,7 @@ Feature: Hide a group in a group block In need to hide groups Background: - Given the "show groups default setting" is set to default - And the following "courses" exist: + Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "users" exist: @@ -16,11 +15,11 @@ Feature: Hide a group in a group block | student2 | Student | 2 | student2@example.com | S2 | | student3 | Student | 3 | student3@example.com | S3 | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - | student2 | C1 | student | - | student3 | C1 | student | + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | And the following "groups" exist: | name | course | idnumber | | Group 1 | C1 | G1 | diff --git a/tests/behat/show_group.feature b/tests/behat/show_group.feature index 8206754..661bdda 100644 --- a/tests/behat/show_group.feature +++ b/tests/behat/show_group.feature @@ -5,16 +5,15 @@ Feature: Make a group visible in a group block In need to make groups visible Background: - Given the "show groups default setting" is enabled - And the following "courses" exist: + Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "users" exist: - | username | firstname | lastname | email | idnumber | - | teacher1 | Teacher | 1 | teacher1@example.com | T1 | - | student1 | Student | 1 | student1@example.com | S1 | - | student2 | Student | 2 | student2@example.com | S2 | - | student3 | Student | 3 | student3@example.com | S3 | + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + | student1 | Student | 1 | student1@example.com | S1 | + | student2 | Student | 2 | student2@example.com | S2 | + | student3 | Student | 3 | student3@example.com | S3 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | From 21ccaeb671a96103ee2a59b39f5858e19f372de0 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 12:09:00 +0200 Subject: [PATCH 11/17] adding cucumber tests and defining steps for the default group settings --- tests/behat/behat_block_groups.php | 17 +++++++++++ tests/behat/default_settings.feature | 43 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/behat/default_settings.feature diff --git a/tests/behat/behat_block_groups.php b/tests/behat/behat_block_groups.php index ec42bce..754c19c 100644 --- a/tests/behat/behat_block_groups.php +++ b/tests/behat/behat_block_groups.php @@ -95,4 +95,21 @@ public function i_click_in_the_groups_block_on_all_groups($action) { } $eyeicon->click(); } + + /** + * Sets the group default visibility setting to a specific value (0 or 1). + * This step allows tests to configure whether groups are visible or hidden by default. + * + * @Given /^the group default visibility setting is "(?P(?:[^"]|\\")*)"$/ + * + * @param string $value The value to set (0 for hidden, 1 for visible) + * @throws \Exception + */ + public function the_group_default_visibility_setting_is($value) { + if ($value !== '0' && $value !== '1') { + throw new \Exception('Invalid value for group default visibility setting: ' . $value . '. Must be 0 or 1.'); + } + + set_config('show_groups_default_setting', $value, 'block_groups'); + } } diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature new file mode 100644 index 0000000..16c068e --- /dev/null +++ b/tests/behat/default_settings.feature @@ -0,0 +1,43 @@ +@javascript +Feature: Group block default visibility settings + In order to test that group visibility settings work properly + As a teacher + I need to verify that groups are shown to students according to the default visibility setting + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + + Scenario: Default setting is 0 - student should not see hidden group + Given the group default visibility setting is "0" + And the following "groups" exist: + | name | course | idnumber | + | Group 1 | C1 | group1 | + And the following "group members" exist: + | user | group | + | student1 | group1 | + When I log in as "student1" + And I am on "Course 1" course homepage + Then I should not see "Group 1" + + Scenario: Default setting is 1 - student should directly see group + Given the group default visibility setting is "1" + And the following "groups" exist: + | name | course | idnumber | + | Group 1 | C1 | group1 | + And the following "group members" exist: + | user | group | + | student1 | group1 | + When I log in as "student1" + And I am on "Course 1" course homepage + Then I should see "Group 1" + From aff5b7dafb4165140623a5de1bd4c46899dcec7d Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 12:22:44 +0200 Subject: [PATCH 12/17] fix spacing --- tests/behat/hide_group.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/behat/hide_group.feature b/tests/behat/hide_group.feature index 3b708a6..8197ab7 100644 --- a/tests/behat/hide_group.feature +++ b/tests/behat/hide_group.feature @@ -30,10 +30,10 @@ Feature: Hide a group in a group block | Grouping 1 | C1 | GG1 | | Grouping 2 | C1 | GG2 | And the following "group members" exist: - | user | group | - | student1 | G1 | - | student2 | G1 | - | student2 | G2 | + | user | group | + | student1 | G1 | + | student2 | G1 | + | student2 | G2 | And the following "grouping groups" exist: | grouping | group | | GG1 | G1 | From d889c5ae9bb047465216f4f86ae903c43092dc16 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 12:37:57 +0200 Subject: [PATCH 13/17] fixing empty lines for phpcs --- tests/behat/default_settings.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature index 16c068e..a774961 100644 --- a/tests/behat/default_settings.feature +++ b/tests/behat/default_settings.feature @@ -40,4 +40,3 @@ Feature: Group block default visibility settings When I log in as "student1" And I am on "Course 1" course homepage Then I should see "Group 1" - From f15e39820c5d1245aaeb71b532fb71b0dd030775 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 12:46:39 +0200 Subject: [PATCH 14/17] fix phpcs warning --- lang/en/block_groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/block_groups.php b/lang/en/block_groups.php index 769969c..3f50174 100644 --- a/lang/en/block_groups.php +++ b/lang/en/block_groups.php @@ -26,6 +26,7 @@ $string['allgroupsinstatevisible'] = 'All groups are already visible.'; $string['brackets'] = '({$a})'; $string['changeallgroups'] = 'Change all groups'; +$string['configshowgroupsandgroupings'] = 'The groups block will not show groups and groupings by default. By enabling this, admins/teachers choose to show groups/groupings immediately after the creation.'; $string['errorbutton'] = 'OK'; $string['errortitle'] = 'Synchronization error'; $string['group'] = 'Groups '; @@ -46,4 +47,3 @@ $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'; $string['showgroupsdefaultsetting'] = 'Show groups and groupings by default'; -$string['configshowgroupsandgroupings'] = 'The groups block will not show groups and groupings by default. By enabling this, admins/teachers choose to show groups/groupings immediately after the creation.'; From d57bcb2386ed80444105aad166d76a4dd2ac4c97 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 12:49:55 +0200 Subject: [PATCH 15/17] add missing tags for behat --- tests/behat/default_settings.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature index a774961..08f180d 100644 --- a/tests/behat/default_settings.feature +++ b/tests/behat/default_settings.feature @@ -1,4 +1,4 @@ -@javascript +@javascript @block @block_groups Feature: Group block default visibility settings In order to test that group visibility settings work properly As a teacher From fe1f8dd048da075e2691ab8542bf820cb256213b Mon Sep 17 00:00:00 2001 From: lenaherf Date: Tue, 2 Jun 2026 13:03:38 +0200 Subject: [PATCH 16/17] Accidentally restored my changes for the cucumber tests before commiting... --- tests/behat/default_settings.feature | 29 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature index 08f180d..7a73130 100644 --- a/tests/behat/default_settings.feature +++ b/tests/behat/default_settings.feature @@ -1,4 +1,4 @@ -@javascript @block @block_groups +@block @block_groups @groups_default_settings Feature: Group block default visibility settings In order to test that group visibility settings work properly As a teacher @@ -16,27 +16,34 @@ Feature: Group block default visibility settings | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I add the "Groups and Groupings" block + And I log out + @javascript Scenario: Default setting is 0 - student should not see hidden group Given the group default visibility setting is "0" And the following "groups" exist: - | name | course | idnumber | - | Group 1 | C1 | group1 | + | name | course | idnumber | + | Group 1 | C1 | G1 | And the following "group members" exist: - | user | group | - | student1 | group1 | + | user | group | + | student1 | G1 | When I log in as "student1" And I am on "Course 1" course homepage - Then I should not see "Group 1" + Then "Groups" "block" should not exist + @javascript Scenario: Default setting is 1 - student should directly see group Given the group default visibility setting is "1" And the following "groups" exist: - | name | course | idnumber | - | Group 1 | C1 | group1 | + | name | course | idnumber | + | Group 1 | C1 | G1 | And the following "group members" exist: - | user | group | - | student1 | group1 | + | user | group | + | student1 | G1 | When I log in as "student1" And I am on "Course 1" course homepage - Then I should see "Group 1" + Then "Groups" "block" should exist + And I should see "Group 1" in the "Groups" "block" From 4d453022fb4a2210102e43ab148af56eb5c308e2 Mon Sep 17 00:00:00 2001 From: lenaherf Date: Wed, 3 Jun 2026 11:08:35 +0200 Subject: [PATCH 17/17] removing unused global variable --- classes/external/create_allgroups_output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/external/create_allgroups_output.php b/classes/external/create_allgroups_output.php index 75d8ecc..a46a12c 100644 --- a/classes/external/create_allgroups_output.php +++ b/classes/external/create_allgroups_output.php @@ -76,7 +76,7 @@ public static function execute_returns() { * @return array */ public static function execute($groups) { - global $PAGE, $CFG, $DB; + global $PAGE, $DB; $params = self::validate_parameters(self::execute_parameters(), ['groups' => $groups]); $PAGE->set_context(context_course::instance($params['groups']['courseid'])); require_capability('moodle/course:managegroups', context_course::instance($params['groups']['courseid']));