MDL-12146 grade category defaults, forced settings and advanced options, merged from MOODLE_19_STABLE
This commit is contained in:
+19
-16
@@ -67,33 +67,36 @@ $temp->add(new admin_setting_configcheckbox('grade_hideforcedsettings', get_stri
|
||||
$strnoforce = get_string('noforce', 'grades');
|
||||
|
||||
// Aggregation type
|
||||
$options = array(-1 =>$strnoforce,
|
||||
GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'),
|
||||
$options = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'),
|
||||
GRADE_AGGREGATE_MEDIAN =>get_string('aggregatemedian', 'grades'),
|
||||
GRADE_AGGREGATE_MIN =>get_string('aggregatemin', 'grades'),
|
||||
GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'),
|
||||
GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'),
|
||||
GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'),
|
||||
GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades'));
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), -1, $options));
|
||||
GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades'),
|
||||
GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades'));
|
||||
$defaults = array('value'=>GRADE_AGGREGATE_MEAN, 'forced'=>false, 'adv'=>false);
|
||||
$temp->add(new admin_setting_gradecat_combo('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), $defaults, $options));
|
||||
|
||||
$options = array(-1 => $strnoforce, 0 => get_string('forceoff', 'grades'), 1 => get_string('forceon', 'grades'));
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'),
|
||||
get_string('aggregateonlygradedhelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'),
|
||||
get_string('aggregateoutcomeshelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'),
|
||||
get_string('aggregatesubcatshelp', 'grades'), -1, $options));
|
||||
$options = array(0 => get_string('no'), 1 => get_string('yes'));
|
||||
|
||||
$options = array(-1 => $strnoforce, 0 => get_string('none'));
|
||||
$defaults = array('value'=>0, 'forced'=>false, 'adv'=>true);
|
||||
$temp->add(new admin_setting_gradecat_combo('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'),
|
||||
get_string('aggregateonlygradedhelp', 'grades'), $defaults, $options));
|
||||
$temp->add(new admin_setting_gradecat_combo('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'),
|
||||
get_string('aggregateoutcomeshelp', 'grades'), $defaults, $options));
|
||||
$temp->add(new admin_setting_gradecat_combo('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'),
|
||||
get_string('aggregatesubcatshelp', 'grades'), $defaults, $options));
|
||||
|
||||
$options = array(0 => get_string('none'));
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
|
||||
$temp->add(new admin_category_regrade_select('grade_keephigh', get_string('keephigh', 'grades'),
|
||||
get_string('keephighhelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_category_regrade_select('grade_droplow', get_string('droplow', 'grades'),
|
||||
get_string('droplowhelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_setting_gradecat_combo('grade_keephigh', get_string('keephigh', 'grades'),
|
||||
get_string('keephighhelp', 'grades'), $defaults, $options));
|
||||
$temp->add(new admin_setting_gradecat_combo('grade_droplow', get_string('droplow', 'grades'),
|
||||
get_string('droplowhelp', 'grades'), $defaults, $options));
|
||||
|
||||
$ADMIN->add('grades', $temp);
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ if ($id) {
|
||||
} else {
|
||||
$grade_category = new grade_category();
|
||||
$grade_category->courseid = $course->id;
|
||||
$grade_category->apply_default_settings();
|
||||
$grade_category->apply_forced_settings();
|
||||
$category = $grade_category->get_record_data();
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ class edit_category_form extends moodleform {
|
||||
|
||||
$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
|
||||
$mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
|
||||
if ((int)$CFG->grade_aggregation_flag & 2) {
|
||||
$mform->setAdvanced('aggregation');
|
||||
}
|
||||
|
||||
//GVA Patch
|
||||
$mform->addElement('checkbox', 'weightcourse', 'Weight grades for course'); //To Do Localize
|
||||
@@ -60,6 +63,9 @@ class edit_category_form extends moodleform {
|
||||
$mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
|
||||
false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
|
||||
$mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
|
||||
if ((int)$CFG->grade_aggregateonlygraded_flag & 2) {
|
||||
$mform->setAdvanced('aggregateonlygraded');
|
||||
}
|
||||
|
||||
if (empty($CFG->enableoutcomes)) {
|
||||
$mform->addElement('hidden', 'aggregateoutcomes');
|
||||
@@ -69,11 +75,17 @@ class edit_category_form extends moodleform {
|
||||
$mform->setHelpButton('aggregateoutcomes', array(false, get_string('aggregateoutcomes', 'grades'),
|
||||
false, true, false, get_string('aggregateoutcomeshelp', 'grades')));
|
||||
$mform->disabledIf('aggregateoutcomes', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
|
||||
if ((int)$CFG->grade_aggregateoutcomes_flag & 2) {
|
||||
$mform->setAdvanced('aggregateoutcomes');
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
|
||||
$mform->setHelpButton('aggregatesubcats', array(false, get_string('aggregatesubcats', 'grades'),
|
||||
false, true, false, get_string('aggregatesubcatshelp', 'grades')));
|
||||
if ((int)$CFG->grade_aggregatesubcats_flag & 2) {
|
||||
$mform->setAdvanced('aggregatesubcats');
|
||||
}
|
||||
|
||||
$options = array(0 => get_string('none'));
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
@@ -83,11 +95,17 @@ class edit_category_form extends moodleform {
|
||||
$mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
|
||||
$mform->setHelpButton('keephigh', array(false, get_string('keephigh', 'grades'),
|
||||
false, true, false, get_string('keephighhelp', 'grades')));
|
||||
if ((int)$CFG->grade_keephigh_flag & 2) {
|
||||
$mform->setAdvanced('keephigh');
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
|
||||
$mform->setHelpButton('droplow', array(false, get_string('droplow', 'grades'),
|
||||
false, true, false, get_string('droplowhelp', 'grades')));
|
||||
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
|
||||
if ((int)$CFG->grade_droplow_flag & 2) {
|
||||
$mform->setAdvanced('droplow');
|
||||
}
|
||||
|
||||
$mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
|
||||
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
|
||||
@@ -104,6 +122,7 @@ class edit_category_form extends moodleform {
|
||||
$mform->setHelpButton('pref_aggregationview', array(false, get_string('aggregationview', 'grades'),
|
||||
false, true, false, get_string('configaggregationview', 'grades')));
|
||||
$mform->setDefault('pref_aggregationview', GRADE_REPORT_PREFERENCE_DEFAULT);
|
||||
$mform->setAdvanced('pref_aggregationview');
|
||||
|
||||
// hidden params
|
||||
$mform->addElement('hidden', 'id', 0);
|
||||
@@ -130,7 +149,7 @@ class edit_category_form extends moodleform {
|
||||
|
||||
$somecat = new grade_category();
|
||||
foreach ($somecat->forceable as $property) {
|
||||
if ($CFG->{"grade_$property"} != -1) {
|
||||
if ((int)$CFG->{"grade_{$property}_flag"} & 1) {
|
||||
if ($mform->elementExists($property)) {
|
||||
if (empty($CFG->grade_hideforcedsettings)) {
|
||||
$mform->hardFreeze($property);
|
||||
|
||||
+70
-17
@@ -2779,30 +2779,83 @@ class admin_setting_special_debugdisplay extends admin_setting_configcheckbox {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Select config class with regrading when setting changes.
|
||||
*/
|
||||
class admin_category_regrade_select extends admin_setting_configselect {
|
||||
|
||||
function admin_category_regrade_select($name, $visiblename, $description, $defaultsetting, $choices) {
|
||||
parent::admin_setting_configselect($name, $visiblename, $description, $defaultsetting, $choices);
|
||||
class admin_setting_gradecat_combo extends admin_setting {
|
||||
|
||||
var $choices;
|
||||
|
||||
function admin_setting_gradecat_combo($name, $visiblename, $description, $defaultsetting, $choices) {
|
||||
$this->choices = $choices;
|
||||
parent::admin_setting($name, $visiblename, $description, $defaultsetting);
|
||||
}
|
||||
|
||||
function get_setting() {
|
||||
global $CFG;
|
||||
|
||||
if (!isset($CFG->{$this->name}) or !isset($CFG->{$this->name.'_flag'})) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$flag = (int)$CFG->{$this->name.'_flag'};
|
||||
$forced = (boolean)(1 & $flag); // first bit
|
||||
$adv = (boolean)(2 & $flag); // second bit
|
||||
|
||||
return array('value' => $CFG->{$this->name}, 'forced' => $forced, 'adv' => $adv);
|
||||
}
|
||||
|
||||
function write_setting($data) {
|
||||
global $CFG;
|
||||
global $CFG;
|
||||
|
||||
if (!in_array($data, array_keys($this->choices))) {
|
||||
return 'Error setting ' . $this->visiblename . '<br />';
|
||||
}
|
||||
$value = $data['value'];
|
||||
$forced = empty($data['forced']) ? 0 : 1;
|
||||
$adv = empty($data['adv']) ? 0 : 2;
|
||||
$flag = ($forced | $adv); //bitwise or
|
||||
|
||||
if (!in_array($value, array_keys($this->choices))) {
|
||||
return 'Error setting ' . $this->visiblename . '<br />';
|
||||
}
|
||||
|
||||
$old = get_config(NULL, $this->name);
|
||||
set_config($this->name, $data);
|
||||
if ($old !== $data) {
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
grade_category::updated_forced_settings();
|
||||
}
|
||||
$oldvalue = get_config(NULL, $this->name);
|
||||
$oldflag = (int)get_config(NULL, $this->name.'_flag');
|
||||
$oldforced = (1 & $oldflag); // first bit
|
||||
|
||||
return '';
|
||||
$result = (boolean)set_config($this->name, $value);
|
||||
$result = $result && (boolean)set_config($this->name.'_flag', $flag);
|
||||
|
||||
if ($result) {
|
||||
// force regrade if needed
|
||||
if ($oldforced != $forced or ($forced and $value != $oldvalue)) {
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
grade_category::updated_forced_settings();
|
||||
}
|
||||
|
||||
return '';
|
||||
} else {
|
||||
return get_string('errorsetting', 'admin') . $this->visiblename . '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
function output_html() {
|
||||
|
||||
if ($this->get_setting() === NULL) {
|
||||
$current = $this->defaultsetting;
|
||||
} else {
|
||||
$current = $this->get_setting();
|
||||
}
|
||||
$value = $current['value'];
|
||||
$forced = !empty($current['forced']);
|
||||
$adv = !empty($current['adv']);
|
||||
|
||||
$return = '<select class="form-select" id="id_s_'.$this->name.'" name="s_' . $this->name .'[value]">';
|
||||
foreach ($this->choices as $key => $val) {
|
||||
// the string cast is needed because key may be integer - 0 is equal to most strings!
|
||||
$return .= '<option value="'.$key.'"'.((string)$key==$value ? ' selected="selected"' : '').'>'.$val.'</option>';
|
||||
}
|
||||
$return .= '</select>'; // TODO: localise
|
||||
$return .= '<label for="id_s_'.$this->name.'force">'.get_string('force').'</label><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'force" name="s_'.$this->name.'[forced]" value="1" ' . ($forced ? 'checked="checked"' : '') . ' />';
|
||||
$return .= '<label for="id_s_'.$this->name.'adv">'.get_string('advanced').'</label><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'adv" name="s_'.$this->name.'[adv]" value="1" ' . ($adv ? 'checked="checked"' : '') . ' />';
|
||||
|
||||
return format_admin_setting($this->name, $this->visiblename, $return, $this->description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ class grade_category extends grade_object {
|
||||
* Aggregate only graded items
|
||||
* @var int $aggregateonlygraded
|
||||
*/
|
||||
var $aggregateonlygraded = 1;
|
||||
var $aggregateonlygraded = 0;
|
||||
|
||||
/**
|
||||
* Aggregate outcomes together with normal items
|
||||
@@ -326,6 +326,7 @@ class grade_category extends grade_object {
|
||||
$this->parent = null;
|
||||
$this->aggregation = GRADE_AGGREGATE_MEAN;
|
||||
|
||||
$this->apply_default_settings();
|
||||
$this->apply_forced_settings();
|
||||
|
||||
$this->timecreated = $this->timemodified = time();
|
||||
@@ -1190,6 +1191,23 @@ class grade_category extends grade_object {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies default settings on this category
|
||||
* @return bool true if anything changed
|
||||
*/
|
||||
function apply_default_settings() {
|
||||
global $CFG;
|
||||
|
||||
foreach ($this->forceable as $property) {
|
||||
if (isset($CFG->{"grade_$property"})) {
|
||||
if ($CFG->{"grade_$property"} == -1) {
|
||||
continue; //temporary bc before version bump
|
||||
}
|
||||
$this->$property = $CFG->{"grade_$property"};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies forced settings on this category
|
||||
* @return bool true if anything changed
|
||||
@@ -1199,7 +1217,10 @@ class grade_category extends grade_object {
|
||||
|
||||
$updated = false;
|
||||
foreach ($this->forceable as $property) {
|
||||
if (isset($CFG->{"grade_$property"}) and $CFG->{"grade_$property"} != -1) {
|
||||
if (isset($CFG->{"grade_$property"}) and isset($CFG->{"grade_{$property}_flag"}) and ((int)$CFG->{"grade_{$property}_flag"} & 1)) {
|
||||
if ($CFG->{"grade_$property"} == -1) {
|
||||
continue; //temporary bc before version bump
|
||||
}
|
||||
$this->$property = $CFG->{"grade_$property"};
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user