mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 23:42:11 +02:00
Merge branch 'MDL-54891-master' of git://github.com/ryanwyllie/moodle
This commit is contained in:
commit
120f4ed7ee
@ -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
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
@ -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.';
|
||||
|
86
blocks/activity_results/settings.php
Normal file
86
blocks/activity_results/settings.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
66
blocks/activity_results/tests/behat/defaultsettings.feature
Normal file
66
blocks/activity_results/tests/behat/defaultsettings.feature
Normal file
@ -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"
|
@ -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).
|
Loading…
x
Reference in New Issue
Block a user