Skip to content

Commit

Permalink
Allow teachers to configure the navigation node placement
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Apr 30, 2023
1 parent e2faca3 commit 64ec49e
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
5 changes: 5 additions & 0 deletions lang/en/local_bulkenrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
24 changes: 21 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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);
}
}
}
}
17 changes: 17 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/behat/local_bulkenrol_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
57 changes: 57 additions & 0 deletions tests/behat/local_bulkenrol_navigation.feature
Original file line number Diff line number Diff line change
@@ -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 | <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 | <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 |
5 changes: 3 additions & 2 deletions tests/behat/local_bulkenrol_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 64ec49e

Please sign in to comment.