diff --git a/blocks/activity_results/block_activity_results.php b/blocks/activity_results/block_activity_results.php index 796304e86ad..a38f289da79 100644 --- a/blocks/activity_results/block_activity_results.php +++ b/blocks/activity_results/block_activity_results.php @@ -55,6 +55,15 @@ class block_activity_results extends block_base { $this->title = get_string('pluginname', 'block_activity_results'); } + /** + * Allow the block to have a configuration page + * + * @return boolean + */ + public function has_config() { + return true; + } + /** * Core function, specifies where the block can be used. * @return array diff --git a/blocks/activity_results/edit_form.php b/blocks/activity_results/edit_form.php index 0a07151a859..aa3f0b0e10c 100644 --- a/blocks/activity_results/edit_form.php +++ b/blocks/activity_results/edit_form.php @@ -42,6 +42,9 @@ class block_activity_results_edit_form extends block_edit_form { protected function specific_definition($mform) { global $DB; + // Load defaults. + $blockconfig = get_config('block_activity_results'); + // Fields for editing activity_results block title and contents. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); @@ -64,15 +67,25 @@ class block_activity_results_edit_form extends block_edit_form { $mform->addElement('text', 'config_showbest', get_string('config_show_best', 'block_activity_results'), array('size' => 3)); - $mform->setDefault('config_showbest', 3); + $mform->setDefault('config_showbest', $blockconfig->config_showbest); $mform->setType('config_showbest', PARAM_INT); + if ($blockconfig->config_showbest_locked) { + $mform->freeze('config_showbest'); + } $mform->addElement('text', 'config_showworst', get_string('config_show_worst', 'block_activity_results'), array('size' => 3)); - $mform->setDefault('config_showworst', 0); + $mform->setDefault('config_showworst', $blockconfig->config_showworst); $mform->setType('config_showworst', PARAM_INT); + if ($blockconfig->config_showworst_locked) { + $mform->freeze('config_showworst'); + } $mform->addElement('selectyesno', 'config_usegroups', get_string('config_use_groups', 'block_activity_results')); + $mform->setDefault('config_usegroups', $blockconfig->config_usegroups); + if ($blockconfig->config_usegroups_locked) { + $mform->freeze('config_usegroups'); + } $nameoptions = array( B_ACTIVITYRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_activity_results'), @@ -81,7 +94,10 @@ class block_activity_results_edit_form extends block_edit_form { ); $mform->addElement('select', 'config_nameformat', get_string('config_name_format', 'block_activity_results'), $nameoptions); - $mform->setDefault('config_nameformat', B_ACTIVITYRESULTS_NAME_FORMAT_FULL); + $mform->setDefault('config_nameformat', $blockconfig->config_nameformat); + if ($blockconfig->config_nameformat_locked) { + $mform->freeze('config_nameformat'); + } $gradeeoptions = array( B_ACTIVITYRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_activity_results'), @@ -90,7 +106,10 @@ class block_activity_results_edit_form extends block_edit_form { ); $mform->addElement('select', 'config_gradeformat', get_string('config_grade_format', 'block_activity_results'), $gradeeoptions); - $mform->setDefault('config_gradeformat', B_ACTIVITYRESULTS_GRADE_FORMAT_PCT); + $mform->setDefault('config_gradeformat', $blockconfig->config_gradeformat); + if ($blockconfig->config_gradeformat_locked) { + $mform->freeze('config_gradeformat'); + } $options = array(); for ($i = 0; $i <= 5; $i++) { @@ -98,7 +117,10 @@ class block_activity_results_edit_form extends block_edit_form { } $mform->addElement('select', 'config_decimalpoints', get_string('config_decimalplaces', 'block_activity_results'), $options); - $mform->setDefault('config_decimalpoints', 2); + $mform->setDefault('config_decimalpoints', $blockconfig->config_decimalpoints); $mform->setType('config_decimalpoints', PARAM_INT); + if ($blockconfig->config_decimalpoints_locked) { + $mform->freeze('config_decimalpoints'); + } } } \ No newline at end of file diff --git a/blocks/activity_results/lang/en/block_activity_results.php b/blocks/activity_results/lang/en/block_activity_results.php index 97ed95e4a98..8a9b6314653 100644 --- a/blocks/activity_results/lang/en/block_activity_results.php +++ b/blocks/activity_results/lang/en/block_activity_results.php @@ -42,6 +42,18 @@ $string['config_show_best'] = 'How many of the highest grades should be shown (0 $string['config_show_worst'] = 'How many of the lowest grades should be shown (0 to disable)?'; $string['configuredtoshownothing'] = 'This block\'s configuration currently does not allow it to show any results.'; $string['config_use_groups'] = 'Show groups instead of students (only if the activity supports groups)?'; +$string['defaulthighestgrades'] = 'Default highest grades shown'; +$string['defaulthighestgrades_desc'] = 'How many of the highest grades should be shown by default?'; +$string['defaultlowestgrades'] = 'Default lowest grades shown'; +$string['defaultlowestgrades_desc'] = 'How many of the lowest grades should be shown by default?'; +$string['defaultshowgroups'] = 'Default show groups'; +$string['defaultnameoptions'] = 'Privacy of results'; +$string['defaultnameoptions_desc'] = 'How should the students be identified by default?'; +$string['defaultshowgroups_desc'] = 'Show groups instead of students by default (only if the activity supports groups)'; +$string['defaultgradedisplay'] = 'Display grades as'; +$string['defaultgradedisplay_desc'] = 'How should the grades be displayed by default?'; +$string['defaultdecimalplaces'] = 'Decimal places'; +$string['defaultdecimalplaces_desc'] = 'Number of decimal places to display by default'; $string['error_emptyactivityid'] = 'Please configure this block and select which activity it should display results from.'; $string['error_emptyactivityrecord'] = 'Error: the selected activity does not exist in the database.'; $string['error_nogroupsexist'] = 'Error: the block is set to display grades in group mode, but there are no groups defined.'; diff --git a/blocks/activity_results/settings.php b/blocks/activity_results/settings.php new file mode 100644 index 00000000000..da080883420 --- /dev/null +++ b/blocks/activity_results/settings.php @@ -0,0 +1,86 @@ +. + +/** + * Defines the form for editing activity results block instances. + * + * @package block_activity_results + * @copyright 2016 Stephen Bourget + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + + // Default high scores. + $setting = new admin_setting_configtext('block_activity_results/config_showbest', + new lang_string('defaulthighestgrades', 'block_activity_results'), + new lang_string('defaulthighestgrades_desc', 'block_activity_results'), 3, PARAM_INT); + $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); + $settings->add($setting); + + // Default low scores. + $setting = new admin_setting_configtext('block_activity_results/config_showworst', + new lang_string('defaultlowestgrades', 'block_activity_results'), + new lang_string('defaultlowestgrades_desc', 'block_activity_results'), 0, PARAM_INT); + $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); + $settings->add($setting); + + // Default group display. + $yesno = array(0 => get_string('no'), 1 => get_string('yes')); + $setting = new admin_setting_configselect('block_activity_results/config_usegroups', + new lang_string('defaultshowgroups', 'block_activity_results'), + new lang_string('defaultshowgroups_desc', 'block_activity_results'), 0, $yesno); + $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); + $settings->add($setting); + + // Default privacy settings. + $nameoptions = array( + B_ACTIVITYRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_activity_results'), + B_ACTIVITYRESULTS_NAME_FORMAT_ID => get_string('config_names_id', 'block_activity_results'), + B_ACTIVITYRESULTS_NAME_FORMAT_ANON => get_string('config_names_anon', 'block_activity_results') + ); + $setting = new admin_setting_configselect('block_activity_results/config_nameformat', + new lang_string('defaultnameoptions', 'block_activity_results'), + new lang_string('defaultnameoptions_desc', 'block_activity_results'), B_ACTIVITYRESULTS_NAME_FORMAT_FULL, $nameoptions); + $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); + $settings->add($setting); + + // Default grade display settings. + $gradeoptions = array( + B_ACTIVITYRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_activity_results'), + B_ACTIVITYRESULTS_GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_activity_results'), + B_ACTIVITYRESULTS_GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_activity_results') + ); + $setting = new admin_setting_configselect('block_activity_results/config_gradeformat', + new lang_string('defaultgradedisplay', 'block_activity_results'), + new lang_string('defaultgradedisplay_desc', 'block_activity_results'), B_ACTIVITYRESULTS_GRADE_FORMAT_PCT, $gradeoptions); + $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); + $settings->add($setting); + + // Default decimal places. + $places = array(); + for ($i = 0; $i <= 5; $i++) { + $places[$i] = $i; + } + $setting = new admin_setting_configselect('block_activity_results/config_decimalpoints', + new lang_string('defaultdecimalplaces', 'block_activity_results'), + new lang_string('defaultdecimalplaces_desc', 'block_activity_results'), 2, $places); + $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); + $settings->add($setting); + +} diff --git a/blocks/activity_results/tests/behat/defaultsettings.feature b/blocks/activity_results/tests/behat/defaultsettings.feature new file mode 100644 index 00000000000..ca45c84449a --- /dev/null +++ b/blocks/activity_results/tests/behat/defaultsettings.feature @@ -0,0 +1,66 @@ +@block @block_activity_results +Feature: The activity results block can have administrator set defaults + In order to be customize the activity results block + As an admin + I need can assign some site wide defaults + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + | student1 | Student | 1 | student1@example.com | S1 | + 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: Assign some site-wide defaults to the block. + Given the following config values are set as admin: + | config_showbest | 0 | block_activity_results | + | config_showworst | 0 | block_activity_results | + | config_gradeformat | 2 | block_activity_results | + | config_nameformat | 2 | block_activity_results | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment | + | Description | Offline text | + | assignsubmission_file_enabled | 0 | + And I follow "Course 1" + And I add the "Activity results" block + When I configure the "Activity results" block + And the following fields match these values: + | id_config_showbest | 0 | + | id_config_showworst | 0 | + | id_config_gradeformat | Fractions | + | id_config_nameformat | Display only ID numbers | + And I press "Save changes" + Then I should see "This block's configuration currently does not allow it to show any results." in the "Activity results" "block" + + Scenario: Assign some site-wide defaults to the block and lock them. + Given the following config values are set as admin: + | config_showbest | 0 | block_activity_results | + | config_showbest_locked | 1 | block_activity_results | + | config_showworst | 0 | block_activity_results | + | config_showworst_locked | 1 | block_activity_results | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment | + | Description | Offline text | + | assignsubmission_file_enabled | 0 | + And I follow "Course 1" + And I add the "Activity results" block + When I configure the "Activity results" block + And the following fields match these values: + | id_config_showbest | 0 | + | id_config_showworst | 0 | + And the "id_config_showbest" "field" should be readonly + And the "id_config_showworst" "field" should be readonly + And I press "Save changes" + Then I should see "This block's configuration currently does not allow it to show any results." in the "Activity results" "block" diff --git a/blocks/activity_results/version.php b/blocks/activity_results/version.php index f8930265f9f..cd1ded7b103 100644 --- a/blocks/activity_results/version.php +++ b/blocks/activity_results/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016052300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2016070400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2016051900; // Requires this Moodle version. $plugin->component = 'block_activity_results'; // Full name of the plugin (used for diagnostics). \ No newline at end of file