From 64ec49eacb72a8c0589cfb15373554d874910c81 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Wed, 26 Apr 2023 21:10:20 +0200 Subject: [PATCH] Allow teachers to configure the navigation node placement --- CHANGES.md | 1 + README.md | 3 + lang/en/local_bulkenrol.php | 5 ++ lib.php | 24 +++++++- settings.php | 17 ++++++ tests/behat/local_bulkenrol_groups.feature | 5 +- .../behat/local_bulkenrol_navigation.feature | 57 +++++++++++++++++++ tests/behat/local_bulkenrol_users.feature | 5 +- version.php | 2 +- 9 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 tests/behat/local_bulkenrol_navigation.feature diff --git a/CHANGES.md b/CHANGES.md index 9a3c40a..dbe5f26 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2023-04-26 - Allow teachers to configure the navigation node placement. * 2023-04-26 - Add a missing setting to README.md * 2023-03-12 - Tests: Fix a Behat test which broke after Moodle core upstream changes * 2023-03-11 - Make codechecker happy again diff --git a/README.md b/README.md index f135269..574deb2 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ The enrolment method to be used to bulk enrol the users. If the configured enrol ### 2. Role The role to be used to bulk enrol the users. +### 3. Navigation node placement +The location where the navigation node for this functionality will be added within a course. + Capabilities ------------ diff --git a/lang/en/local_bulkenrol.php b/lang/en/local_bulkenrol.php index ed36989..c1ba815 100644 --- a/lang/en/local_bulkenrol.php +++ b/lang/en/local_bulkenrol.php @@ -68,3 +68,8 @@ $string['user_groups_already'] = 'User is already group member'; $string['parameter_empty'] = 'Parameter empty'; $string['type_enrol'] = 'Enrolment method'; +$string['navigation'] = 'Navigation node placement'; +$string['navigation_desc'] = 'The location where the navigation node for user bulk enrolment will be added within a course.'; +$string['nav_course'] = 'Navigation node in course navigation'; +$string['nav_participants'] = 'Navigation node in participants page jump menu'; +$string['nav_both'] = 'Navigation node both in participants page jump menu and in course navigation'; diff --git a/lib.php b/lib.php index de2bc8e..63c1c02 100644 --- a/lib.php +++ b/lib.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +define('LOCALBULKENROL_NAV_COURSE', 'navcourse'); +define('LOCALBULKENROL_NAV_PARTICIPANTS', 'navpart'); +define('LOCALBULKENROL_NAV_BOTH', 'navboth'); + /** * This function extends the course navigation with the bulkenrol item * @@ -31,13 +35,27 @@ */ function local_bulkenrol_extend_navigation_course($navigation, $course, $context) { if (has_capability('local/bulkenrol:enrolusers', $context)) { + // Create the navigation node. $url = new moodle_url('/local/bulkenrol/index.php', array('id' => $course->id)); $bulkenrolnode = navigation_node::create(get_string('pluginname', 'local_bulkenrol'), $url, navigation_node::TYPE_SETTING, null, 'local_bulkenrol', new pix_icon('i/users', '')); - $usersnode = $navigation->get('users'); - if (isset($bulkenrolnode) && !empty($usersnode)) { - $usersnode->add_node($bulkenrolnode); + // Get the navigation node placement setting. + $navigationplacement = get_config('local_bulkenrol', 'navigation'); + + // If the admin wanted to add the navigation node to the participants page jump menu. + if ($navigationplacement == LOCALBULKENROL_NAV_PARTICIPANTS || $navigationplacement == LOCALBULKENROL_NAV_BOTH) { + $usersnode = $navigation->get('users'); + if (isset($bulkenrolnode) && !empty($usersnode)) { + $usersnode->add_node($bulkenrolnode); + } + } + + // If the admin wanted to add the navigation node to the course navigation. + if ($navigationplacement == LOCALBULKENROL_NAV_COURSE || $navigationplacement == LOCALBULKENROL_NAV_BOTH) { + if (isset($bulkenrolnode)) { + $navigation->add_node($bulkenrolnode); + } } } } diff --git a/settings.php b/settings.php index 166df67..c79c7fe 100644 --- a/settings.php +++ b/settings.php @@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die; +// Require library. +require_once($CFG->dirroot.'/local/bulkenrol/lib.php'); + if ($hassiteconfig) { $settings = new admin_settingpage('local_bulkenrol', get_string('pluginname', 'local_bulkenrol', null, true)); @@ -74,6 +77,20 @@ $roleoptions) ); unset($roleoptions); + + // Create navigation node placement widget. + $navigationoptions = array(LOCALBULKENROL_NAV_COURSE => get_string('nav_course', 'local_bulkenrol'), + LOCALBULKENROL_NAV_PARTICIPANTS => get_string('nav_participants', 'local_bulkenrol'), + LOCALBULKENROL_NAV_BOTH => get_string('nav_both', 'local_bulkenrol')); + $settings->add( + new admin_setting_configselect( + 'local_bulkenrol/navigation', + get_string('navigation', 'local_bulkenrol'), + get_string('navigation_desc', 'local_bulkenrol'), + LOCALBULKENROL_NAV_PARTICIPANTS, + $navigationoptions) + ); + unset($navigationoptions); } $ADMIN->add('enrolments', $settings); diff --git a/tests/behat/local_bulkenrol_groups.feature b/tests/behat/local_bulkenrol_groups.feature index 0fea443..ae0ad74 100644 --- a/tests/behat/local_bulkenrol_groups.feature +++ b/tests/behat/local_bulkenrol_groups.feature @@ -18,8 +18,9 @@ Feature: Using the local_bulkenrol plugin for group management | user | course | role | | teacher1 | C1 | editingteacher | And the following config values are set as admin: - | config | value | plugin | - | enrolplugin | manual | local_bulkenrol | + | config | value | plugin | + | enrolplugin | manual | local_bulkenrol | + | navigation | navpart | local_bulkenrol | Given I log in as "admin" And I navigate to "Plugins > Enrolments > User bulk enrolment" in site administration And I set the following fields to these values: diff --git a/tests/behat/local_bulkenrol_navigation.feature b/tests/behat/local_bulkenrol_navigation.feature new file mode 100644 index 0000000..bb0a38c --- /dev/null +++ b/tests/behat/local_bulkenrol_navigation.feature @@ -0,0 +1,57 @@ +@local @local_bulkenrol @local_bulkenrol_navigation @javascript +Feature: Using the local_bulkenrol plugin + In order to bulk enrol users into the course + As user with the appropriate rights + I need to have a proper navigation + + Background: + Given the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following config values are set as admin: + | config | value | plugin | + | enrolplugin | manual | local_bulkenrol | + Given I log in as "admin" + And I navigate to "Plugins > Enrolments > User bulk enrolment" in site administration + And I set the following fields to these values: + | Role | Student | + And I press "Save changes" + And I set the following system permissions of "Teacher" role: + | capability | permission | + | local/bulkenrol:enrolusers | Allow | + And I log out + + Scenario Outline: Access the bulk enrolment page via the participants page jump menu + Given the following config values are set as admin: + | config | value | plugin | + | navigation | | local_bulkenrol | + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I select "Participants" from secondary navigation + And I select "User bulk enrolment" from the "jump" singleselect + Then I should see "User bulk enrolment" in the "#region-main h2" "css_element" + + Examples: + | navigation | + | navpart | + | navboth | + + Scenario Outline: Access the bulk enrolment page via the participants page jump menu + Given the following config values are set as admin: + | config | value | plugin | + | navigation | | local_bulkenrol | + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "User bulk enrolment" in current page administration + Then I should see "User bulk enrolment" in the "#region-main h2" "css_element" + + Examples: + | navigation | + | navcourse | + | navboth | diff --git a/tests/behat/local_bulkenrol_users.feature b/tests/behat/local_bulkenrol_users.feature index 69fb7a6..5f46330 100644 --- a/tests/behat/local_bulkenrol_users.feature +++ b/tests/behat/local_bulkenrol_users.feature @@ -18,8 +18,9 @@ Feature: Using the local_bulkenrol plugin for user enrolments | user | course | role | | teacher1 | C1 | editingteacher | And the following config values are set as admin: - | config | value | plugin | - | enrolplugin | manual | local_bulkenrol | + | config | value | plugin | + | enrolplugin | manual | local_bulkenrol | + | navigation | navpart | local_bulkenrol | Given I log in as "admin" And I navigate to "Plugins > Enrolments > User bulk enrolment" in site administration And I set the following fields to these values: diff --git a/version.php b/version.php index 555d5d7..b3eae07 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'local_bulkenrol'; -$plugin->version = 2022071201; +$plugin->version = 2022071202; $plugin->release = 'v4.0-r2'; $plugin->requires = 2022041900; $plugin->supported = [400, 400];