From 7c4ca5f26935c4bca5243814c73e3fe75ca21c8a Mon Sep 17 00:00:00 2001 From: Gregor Eichelberger Date: Thu, 24 Aug 2023 09:28:32 +0200 Subject: [PATCH] MDL-79044 gradebook: Add default export method setting Introduces a new admin setting to configure the default export method used for redirecting the user via /grade/export/index.php Signed-off-by: Gregor Eichelberger --- admin/settings/grades.php | 2 + grade/export/index.php | 3 +- .../behat/grade_export_default_method.feature | 27 +++++++++++ lang/en/admin.php | 2 + lib/adminlib.php | 48 +++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 grade/tests/behat/grade_export_default_method.feature diff --git a/admin/settings/grades.php b/admin/settings/grades.php index a832c9db217..153a7226f47 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -74,6 +74,8 @@ if (has_capability('moodle/grade:manage', $systemcontext) $temp->add(new admin_setting_special_gradeexport()); + $temp->add(new admin_setting_special_gradeexportdefault()); + $temp->add(new admin_setting_special_gradelimiting()); $temp->add(new admin_setting_configcheckbox('grade_report_showmin', diff --git a/grade/export/index.php b/grade/export/index.php index 7e2957b8ee0..d1645d244ac 100644 --- a/grade/export/index.php +++ b/grade/export/index.php @@ -46,7 +46,8 @@ $exportplugins = array_filter(core_component::get_plugin_list('gradeexport'), ); if (!empty($exportplugins)) { - $exportplugin = array_key_first($exportplugins); + $exportplugin = isset($CFG->gradeexport_default, $exportplugins[$CFG->gradeexport_default]) + ? $CFG->gradeexport_default : array_key_first($exportplugins); $url = new moodle_url("/grade/export/{$exportplugin}/index.php", ['id' => $courseid]); redirect($url); } diff --git a/grade/tests/behat/grade_export_default_method.feature b/grade/tests/behat/grade_export_default_method.feature new file mode 100644 index 00000000000..9b280350350 --- /dev/null +++ b/grade/tests/behat/grade_export_default_method.feature @@ -0,0 +1,27 @@ +@core @core_grades @javascript +Feature: Configurable default grade export method + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + + Scenario: View default grade export method in gradebook + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "More > Export" in the course gradebook + Then I should see "Export to OpenDocument spreadsheet" + + Scenario: Changing the default grade export method in gradebook + Given the following config values are set as admin: + | gradeexport_default | txt | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "More > Export" in the course gradebook + Then I should see "Export to Plain text file" diff --git a/lang/en/admin.php b/lang/en/admin.php index db09c430b54..50660edaa58 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -287,6 +287,7 @@ $string['configgeoipfile'] = 'Location of GeoLite2 City binary data file. This f $string['configgetremoteaddrconf'] = 'If your server is behind a reverse proxy, you can use this setting to specify which HTTP headers can be trusted to contain the remote IP address. The headers are read in order, using the first one that is available.'; $string['configgradebookroles'] = 'This setting allows you to control who appears on the gradebook. Users need to have at least one of these roles in a course to be shown in the gradebook for that course.'; $string['configgradeexport'] = 'Choose which gradebook export formats are your primary methods for exporting grades. Chosen plugins will then set and use a "last exported" field for every grade. For example, this might result in exported records being identified as being "new" or "updated". If you are not sure about this then leave everything unchecked.'; +$string['configgradeexportdefault'] = 'Choose which gradebook export format is your default method for exporting grades.'; $string['confighiddenuserfields'] = 'Select which user information fields you wish to hide from other users other than course teachers/admins. This will increase student privacy. Hold CTRL key to select multiple fields.'; $string['configidnumber'] = 'This option specifies whether (a) Users are not be asked for an ID number at all, (b) Users are asked for an ID number but can leave it blank or (c) Users are asked for an ID Number and cannot leave it blank. If given the User\'s ID number is displayed in their Profile.'; $string['configintro'] = 'On this page you can specify a number of configuration variables that help make Moodle work properly on your server. Don\'t worry too much about it - the defaults will usually work fine and you can always come back to this page later and change these settings.'; @@ -701,6 +702,7 @@ $string['gradebookroles'] = 'Graded roles'; $string['gravatardefaulturl'] = 'Gravatar default image URL'; $string['gravatardefaulturl_help'] = 'Gravatar needs a default image to display if it is unable to find a picture for a given user. Provide a full URL for an image. If you leave this setting empty, Moodle will attempt to use the most appropriate default image for the page you are viewing. Note also that Gravatar has a number of codes which can be used to generate default images.'; $string['gradeexport'] = 'Primary grade export methods'; +$string['gradeexportdefault'] = 'Default grade export method'; $string['guestroleid'] = 'Role for guest'; $string['guestroleid_help'] = 'This role is automatically assigned to the guest user. It is also temporarily assigned to not enrolled users that enter the course via guest enrolment plugin.'; $string['helpadminseesall'] = 'In the site calendar, do admins see and filter events from all course calendars or just those from courses they are enrolled in? Regardless of the chosen option, admins will always be able to manage events for each course calendar by navigating to the course first, and then accessing the course calendar directly.'; diff --git a/lib/adminlib.php b/lib/adminlib.php index a370b5d86ac..1352816734d 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -6165,6 +6165,54 @@ class admin_setting_special_gradeexport extends admin_setting_configmulticheckbo } } +/** + * A setting for the default grade export plugin. + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_setting_special_gradeexportdefault extends admin_setting_configselect { + /** + * Calls parent::__construct with specific arguments + */ + public function __construct() { + parent::__construct('gradeexport_default', get_string('gradeexportdefault', 'admin'), + get_string('configgradeexportdefault', 'admin'), null, null); + } + + /** + * Returns the default option + * + * @return string default option + */ + public function get_defaultsetting() { + $this->load_choices(); + $defaultsetting = parent::get_defaultsetting(); + if (array_key_exists($defaultsetting, $this->choices)) { + return $defaultsetting; + } else { + return array_key_first($this->choices); + } + } + + /** + * Load the available choices for the configselect + * + * @return bool always returns true + */ + public function load_choices() { + if (is_array($this->choices)) { + return true; + } + $this->choices = []; + + if ($plugins = core_component::get_plugin_list('gradeexport')) { + foreach ($plugins as $plugin => $unused) { + $this->choices[$plugin] = get_string('pluginname', 'gradeexport_'.$plugin); + } + } + return true; + } +} /** * A setting for setting the default grade point value. Must be an integer between 1 and $CFG->gradepointmax.