mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-11278 improved forced category settings - refactoring + regrading forced + new setting to hide forced settings in UI
This commit is contained in:
parent
a8d0a37a27
commit
89a5f82768
@ -57,10 +57,12 @@ $ADMIN->add('grades', $temp);
|
||||
/// Grade category settings
|
||||
$temp = new admin_settingpage('gradecategorysettings', get_string('gradecategorysettings', 'grades'));
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox('grade_hideforcedsettings', get_string('hideforcedsettings', 'grades'), get_string('confighideforcedsettings', 'grades'), 0, PARAM_INT));
|
||||
|
||||
$strnoforce = get_string('noforce', 'grades');
|
||||
|
||||
// Aggregation type
|
||||
$options = array(-1 => $strnoforce,
|
||||
// Aggregation type
|
||||
$options = array(-1 =>$strnoforce,
|
||||
GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'),
|
||||
GRADE_AGGREGATE_MEDIAN =>get_string('aggregatemedian', 'grades'),
|
||||
GRADE_AGGREGATE_MIN =>get_string('aggregatemin', 'grades'),
|
||||
@ -68,14 +70,14 @@ $options = array(-1 => $strnoforce,
|
||||
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_setting_configselect('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), -1, $options));
|
||||
|
||||
$options = array(-1 => $strnoforce, 0 => get_string('forceoff', 'grades'), 1 => get_string('forceon', 'grades'));
|
||||
$temp->add(new admin_setting_configselect('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'),
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'),
|
||||
get_string('aggregateonlygradedhelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_setting_configselect('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'),
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'),
|
||||
get_string('aggregateoutcomeshelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_setting_configselect('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'),
|
||||
$temp->add(new admin_category_regrade_select('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'),
|
||||
get_string('aggregatesubcatshelp', 'grades'), -1, $options));
|
||||
|
||||
$options = array(-1 => $strnoforce, 0 => get_string('none'));
|
||||
@ -83,9 +85,9 @@ for ($i=1; $i<=20; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_configselect('grade_keephigh', get_string('keephigh', 'grades'),
|
||||
$temp->add(new admin_category_regrade_select('grade_keephigh', get_string('keephigh', 'grades'),
|
||||
get_string('keephighhelp', 'grades'), -1, $options));
|
||||
$temp->add(new admin_setting_configselect('grade_droplow', get_string('droplow', 'grades'),
|
||||
$temp->add(new admin_category_regrade_select('grade_droplow', get_string('droplow', 'grades'),
|
||||
get_string('droplowhelp', 'grades'), -1, $options));
|
||||
|
||||
$ADMIN->add('grades', $temp);
|
||||
|
@ -45,20 +45,29 @@ $returnurl = $gpr->get_return_url('index.php?id='.$course->id);
|
||||
|
||||
|
||||
$mform = new edit_category_form(null, array('gpr'=>$gpr));
|
||||
if ($category = get_record('grade_categories', 'id', $id, 'courseid', $course->id)) {
|
||||
|
||||
if ($id) {
|
||||
if (!$grade_category = grade_category::fetch(array('id'=>$id, 'courseid'=>$course->id))) {
|
||||
error('Incorrect category id!');
|
||||
}
|
||||
$grade_category->apply_forced_settings();
|
||||
$category = $grade_category->get_record_data();
|
||||
// Get Category preferences
|
||||
$category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
|
||||
|
||||
$mform->set_data($category);
|
||||
} else {
|
||||
$mform->set_data(array('courseid'=>$course->id));
|
||||
$grade_category = new grade_category();
|
||||
$grade_category->courseid = $course->id;
|
||||
$grade_category->apply_forced_settings();
|
||||
$category = $grade_category->get_record_data();
|
||||
}
|
||||
|
||||
$mform->set_data($category);
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($data = $mform->get_data(false)) {
|
||||
$grade_category = new grade_category(array('id'=>$id, 'courseid'=>$course->id));
|
||||
grade_category::set_properties($grade_category, $data);
|
||||
|
||||
if (empty($grade_category->id)) {
|
||||
|
@ -26,91 +26,56 @@
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class edit_category_form extends moodleform {
|
||||
var $aggregation_types = array();
|
||||
var $keepdrop_options = array();
|
||||
|
||||
function definition() {
|
||||
global $CFG;
|
||||
$mform =& $this->_form;
|
||||
|
||||
$this->aggregation_types = 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'));
|
||||
$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'));
|
||||
|
||||
// visible elements
|
||||
$mform->addElement('header', 'gradecat', get_string('gradecategory', 'grades'));
|
||||
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
|
||||
|
||||
if ($CFG->grade_aggregation == -1) {
|
||||
$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
|
||||
$mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
|
||||
|
||||
$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_types);
|
||||
$mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
|
||||
$mform->setDefault('aggregation', GRADE_AGGREGATE_MEAN);
|
||||
} else {
|
||||
$mform->addElement('static', 'aggregation', get_string('aggregation', 'grades'));
|
||||
}
|
||||
|
||||
if ($CFG->grade_aggregateonlygraded == -1) {
|
||||
$mform->addElement('advcheckbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
|
||||
$mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
|
||||
false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
|
||||
} else {
|
||||
$mform->addElement('static', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
|
||||
}
|
||||
$mform->addElement('advcheckbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
|
||||
$mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
|
||||
false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
|
||||
|
||||
if (!empty($CFG->enableoutcomes)) {
|
||||
if($CFG->grade_aggregateoutcomes == -1) {
|
||||
$mform->addElement('advcheckbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
|
||||
$mform->setHelpButton('aggregateoutcomes', array(false, get_string('aggregateoutcomes', 'grades'),
|
||||
false, true, false, get_string('aggregateoutcomeshelp', 'grades')));
|
||||
} else {
|
||||
$mform->addElement('static', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
|
||||
}
|
||||
$mform->addElement('advcheckbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
|
||||
$mform->setHelpButton('aggregateoutcomes', array(false, get_string('aggregateoutcomes', 'grades'),
|
||||
false, true, false, get_string('aggregateoutcomeshelp', 'grades')));
|
||||
}
|
||||
|
||||
if ($CFG->grade_aggregatesubcats == -1) {
|
||||
$mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
|
||||
$mform->setHelpButton('aggregatesubcats', array(false, get_string('aggregatesubcats', 'grades'),
|
||||
false, true, false, get_string('aggregatesubcatshelp', 'grades')));
|
||||
} else {
|
||||
$mform->addElement('static', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
|
||||
}
|
||||
$mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
|
||||
$mform->setHelpButton('aggregatesubcats', array(false, get_string('aggregatesubcats', 'grades'),
|
||||
false, true, false, get_string('aggregatesubcatshelp', 'grades')));
|
||||
|
||||
$this->keepdrop_options = array();
|
||||
$this->keepdrop_options[0] = get_string('none');
|
||||
$options = array(0 => get_string('none'));
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
$this->keepdrop_options[$i] = $i;
|
||||
$options[$i] = $i;
|
||||
}
|
||||
|
||||
$keepdrop_present = 0;
|
||||
$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 ($CFG->grade_keephigh == -1) {
|
||||
$mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $this->keepdrop_options);
|
||||
$mform->setHelpButton('keephigh', array(false, get_string('keephigh', 'grades'),
|
||||
false, true, false, get_string('keephighhelp', 'grades')));
|
||||
$keepdrop_present++;
|
||||
} else {
|
||||
$mform->addElement('static', 'keephigh', get_string('keephigh', 'grades'));
|
||||
}
|
||||
$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 ($CFG->grade_droplow == -1) {
|
||||
$mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $this->keepdrop_options);
|
||||
$mform->setHelpButton('droplow', array(false, get_string('droplow', 'grades'),
|
||||
false, true, false, get_string('droplowhelp', 'grades')));
|
||||
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
|
||||
$keepdrop_present++;
|
||||
} else {
|
||||
$mform->addElement('static', 'droplow', get_string('droplow', 'grades'));
|
||||
}
|
||||
|
||||
if ($keepdrop_present == 2) {
|
||||
$mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
|
||||
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
|
||||
}
|
||||
$mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
|
||||
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
|
||||
|
||||
// user preferences
|
||||
$mform->addElement('header', 'userpref', get_string('myreportpreferences', 'grades'));
|
||||
@ -148,38 +113,29 @@ class edit_category_form extends moodleform {
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$checkbox_values = array(get_string('no'), get_string('yes'));
|
||||
|
||||
if ($CFG->grade_aggregation != -1) {
|
||||
$agg_el =& $mform->getElement('aggregation');
|
||||
$agg_el->setValue($this->aggregation_types[$CFG->grade_aggregation]);
|
||||
}
|
||||
|
||||
if ($CFG->grade_aggregateonlygraded != -1) {
|
||||
$agg_el =& $mform->getElement('aggregateonlygraded');
|
||||
$agg_el->setValue($checkbox_values[$CFG->grade_aggregateonlygraded]);
|
||||
}
|
||||
|
||||
if (!empty($CFG->enableoutcomes)) {
|
||||
if ($CFG->grade_aggregateoutcomes != -1) {
|
||||
$agg_el =& $mform->getElement('aggregateoutcomes');
|
||||
$agg_el->setValue($checkbox_values[$CFG->grade_aggregateoutcomes]);
|
||||
$somecat = new grade_category();
|
||||
foreach ($somecat->forceable as $property) {
|
||||
if ($CFG->{"grade_$property"} != -1) {
|
||||
if ($mform->elementExists($property)) {
|
||||
if (empty($CFG->grade_hideforcedsettings)) {
|
||||
$mform->hardFreeze($property);
|
||||
} else {
|
||||
if ($mform->elementExists($property)) {
|
||||
$mform->removeElement($property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($CFG->grade_aggregatesubcats != -1) {
|
||||
$agg_el =& $mform->getElement('aggregatesubcats');
|
||||
$agg_el->setValue($checkbox_values[$CFG->grade_aggregatesubcats]);
|
||||
}
|
||||
|
||||
if ($CFG->grade_keephigh != -1) {
|
||||
$agg_el =& $mform->getElement('keephigh');
|
||||
$agg_el->setValue($this->keepdrop_options[$CFG->grade_keephigh]);
|
||||
}
|
||||
|
||||
if ($CFG->grade_droplow != -1) {
|
||||
$agg_el =& $mform->getElement('droplow');
|
||||
$agg_el->setValue($this->keepdrop_options[$CFG->grade_droplow]);
|
||||
if ($CFG->grade_droplow > 0) {
|
||||
if ($mform->elementExists('keephigh')) {
|
||||
$mform->removeElement('keephigh');
|
||||
}
|
||||
} else if ($CFG->grade_keephigh > 0) {
|
||||
if ($mform->elementExists('droplow')) {
|
||||
$mform->removeElement('droplow');
|
||||
}
|
||||
}
|
||||
|
||||
if ($id = $mform->getElementValue('id')) {
|
||||
|
@ -38,7 +38,7 @@ $string['availableidnumbers'] = 'Available id numbers';
|
||||
$string['average'] = 'Average';
|
||||
$string['averagesdecimalpoints'] = 'Decimals in column averages';
|
||||
$string['averagesdisplaytype'] = 'Column averages display type';
|
||||
$string['backupwithoutgradebook'] = "Backup does not contain Gradebook configuration";
|
||||
$string['backupwithoutgradebook'] = 'Backup does not contain Gradebook configuration';
|
||||
$string['badgrade'] = 'Supplied grade is invalid';
|
||||
$string['baduser'] = 'Supplied user is invalid';
|
||||
$string['bonuspoints'] = 'Bonus Points';
|
||||
@ -80,6 +80,7 @@ $string['configquickfeedback'] = 'Quick Feedback adds a text input element in ea
|
||||
$string['configquickgrading'] = 'Quick Grading adds a text input element in each grade cell on the grader report, allowing you to edit the feedback for many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.';
|
||||
$string['configrangesdecimalpoints'] = 'The number of decimal points to display for each range, above a column of grades. This can be overriden per grading item.';
|
||||
$string['configrangesdisplaytype'] = 'Specifies how to display the range for each column in the grader report. Default means to use the display type of each column.';
|
||||
$string['confighideforcedsettings'] = 'Do not show forced settings in grading UI.';
|
||||
$string['configshowcalculations'] = 'Whether to show calculator icons near each grade item and category, tooltips over calculated items and a visual indicator that a column is calculated.';
|
||||
$string['configshoweyecons'] = 'Whether to show a show/hide icon near each grade (controlling its visibility to the user).';
|
||||
$string['configshowactivityicons'] = 'Show an activity icon next to each grade item linked to an activity, in the grader report.';
|
||||
@ -353,6 +354,7 @@ $string['rangesdisplaytype'] = 'Range display type';
|
||||
$string['rank'] = 'Rank';
|
||||
$string['rawpct'] = 'Raw %%';
|
||||
$string['real'] = 'Real';
|
||||
$string['hideforcedsettings'] = 'Hide forced settings';
|
||||
$string['report'] = 'Report';
|
||||
$string['reportdefault'] = 'Report default ($a)';
|
||||
$string['reportplugins'] = 'Report plugins';
|
||||
|
@ -2765,6 +2765,33 @@ 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);
|
||||
}
|
||||
|
||||
function write_setting($data) {
|
||||
global $CFG;
|
||||
|
||||
if (!in_array($data, 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();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Code for a function that helps externalpages print proper headers and footers
|
||||
// N.B.: THIS FUNCTION HANDLES AUTHENTICATION
|
||||
|
@ -138,6 +138,11 @@ class grade_category extends grade_object {
|
||||
*/
|
||||
var $sortorder;
|
||||
|
||||
/**
|
||||
* List of options which can be "forced" from site settings.
|
||||
*/
|
||||
var $forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes', 'aggregatesubcats');
|
||||
|
||||
/**
|
||||
* Builds this category's path string based on its parents (if any) and its own id number.
|
||||
* This is typically done just before inserting this object in the DB for the first time,
|
||||
@ -194,6 +199,14 @@ class grade_category extends grade_object {
|
||||
$this->depth = substr_count($this->path, '/') - 1;
|
||||
}
|
||||
|
||||
$this->apply_forced_settings();
|
||||
|
||||
// these are exclusive
|
||||
if ($this->droplow > 0) {
|
||||
$this->keephigh = 0;
|
||||
} else if ($this->keephigh > 0) {
|
||||
$this->droplow = 0;
|
||||
}
|
||||
|
||||
// Recalculate grades if needed
|
||||
if ($this->qualifies_for_regrading()) {
|
||||
@ -303,6 +316,8 @@ class grade_category extends grade_object {
|
||||
$this->parent = null;
|
||||
$this->aggregate = GRADE_AGGREGATE_MEAN;
|
||||
|
||||
$this->apply_forced_settings();
|
||||
|
||||
if (!parent::insert('system')) {
|
||||
debugging("Could not insert this category: " . print_r($this, true));
|
||||
return false;
|
||||
@ -371,9 +386,7 @@ class grade_category extends grade_object {
|
||||
return true; // no need to recalculate locked items
|
||||
}
|
||||
|
||||
$this->grade_item->load_scale();
|
||||
|
||||
// find grade items of immediate children (category or grade items)
|
||||
// find grade items of immediate children (category or grade items) and force site settings
|
||||
$depends_on = $this->grade_item->depends_on();
|
||||
|
||||
if (empty($depends_on)) {
|
||||
@ -492,11 +505,6 @@ class grade_category extends grade_object {
|
||||
$grade_values[$itemid] = grade_grade::standardise_score($v, $items[$itemid]->grademin, $items[$itemid]->grademax, 0, 1);
|
||||
}
|
||||
|
||||
// If global aggregateonlygraded is set, override category value
|
||||
if ($CFG->grade_aggregateonlygraded != -1) {
|
||||
$this->aggregateonlygraded = $CFG->grade_aggregateonlygraded;
|
||||
}
|
||||
|
||||
// use min grade if grade missing for these types
|
||||
if (!$this->aggregateonlygraded) {
|
||||
foreach($items as $itemid=>$value) {
|
||||
@ -552,6 +560,9 @@ class grade_category extends grade_object {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function - aggregation maths.
|
||||
*/
|
||||
function aggregate_values($grade_values, $items) {
|
||||
switch ($this->aggregation) {
|
||||
case GRADE_AGGREGATE_MEDIAN: // Middle point value in the set: ignores frequencies
|
||||
@ -633,17 +644,6 @@ class grade_category extends grade_object {
|
||||
* @return array Limited grades.
|
||||
*/
|
||||
function apply_limit_rules(&$grade_values) {
|
||||
global $CFG;
|
||||
|
||||
// If global keephigh and/or droplow are set, override category variable
|
||||
if ($CFG->grade_keephigh != -1) {
|
||||
$this->keephigh = $CFG->grade_keephigh;
|
||||
}
|
||||
|
||||
if ($CFG->grade_droplow != -1) {
|
||||
$this->droplow = $CFG->grade_droplow;
|
||||
}
|
||||
|
||||
arsort($grade_values, SORT_NUMERIC);
|
||||
if (!empty($this->droplow)) {
|
||||
for ($i = 0; $i < $this->droplow; $i++) {
|
||||
@ -1108,5 +1108,33 @@ class grade_category extends grade_object {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies forced settings on this category
|
||||
* @return bool true if anything changed
|
||||
*/
|
||||
function apply_forced_settings() {
|
||||
global $CFG;
|
||||
|
||||
$updated = false;
|
||||
foreach ($this->forceable as $property) {
|
||||
if (isset($CFG->{"grade_$property"}) and $CFG->{"grade_$property"} != -1) {
|
||||
$this->$property = $CFG->{"grade_$property"};
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification of change in forced category settings.
|
||||
* @static
|
||||
*/
|
||||
function updated_forced_settings() {
|
||||
global $CFG;
|
||||
$sql = "UPDATE {$CFG->prefix}grade_items SET needsupdate=1 WHERE itemtype='course' or itemtype='category'";
|
||||
execute_sql($sql, false);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -542,8 +542,10 @@ class grade_grade extends grade_object {
|
||||
unset($todo[$key]);
|
||||
$found = true;
|
||||
continue;
|
||||
|
||||
} else {
|
||||
$grade_category = $grade_items[$do]->load_item_category();
|
||||
|
||||
$values = array();
|
||||
foreach ($dependson[$do] as $itemid) {
|
||||
if (array_key_exists($itemid, $altered)) {
|
||||
@ -552,9 +554,6 @@ class grade_grade extends grade_object {
|
||||
$values[$itemid] = $grade_grades[$itemid]->finalgrade;
|
||||
}
|
||||
}
|
||||
if ($CFG->grade_aggregateonlygraded != -1) {
|
||||
$grade_category->aggregateonlygraded = $CFG->grade_aggregateonlygraded;
|
||||
}
|
||||
|
||||
if ($grade_category->aggregateonlygraded) {
|
||||
foreach ($values as $itemid=>$value) {
|
||||
|
@ -1191,15 +1191,7 @@ class grade_item extends grade_object {
|
||||
return $this->dependson_cache;
|
||||
}
|
||||
|
||||
// If global aggregateoutcomes is set, override category value
|
||||
if ($CFG->grade_aggregateoutcomes != -1) {
|
||||
$grade_category->aggregateoutcomes = $CFG->grade_aggregateoutcomes;
|
||||
}
|
||||
|
||||
// If global aggregatesubcats is set, override category value
|
||||
if ($CFG->grade_aggregatesubcats != -1) {
|
||||
$grade_category->aggregatesubcats = $CFG->grade_aggregatesubcats;
|
||||
}
|
||||
$grade_category->apply_forced_settings();
|
||||
|
||||
if (empty($CFG->enableoutcomes) or $grade_category->aggregateoutcomes) {
|
||||
$outcomes_sql = "";
|
||||
|
@ -201,17 +201,7 @@ class grade_object {
|
||||
|
||||
$this->timemodified = time();
|
||||
|
||||
// we need to do this to prevent infinite loops in addslashes_recursive - grade_item -> category ->grade_item
|
||||
$data = new object();
|
||||
foreach ($this as $var=>$value) {
|
||||
if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
|
||||
if (is_object($value) or is_array($value)) {
|
||||
debugging("Incorrect property '$var' found when updating grade object");
|
||||
} else {
|
||||
$data->$var = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = $this->get_record_data();
|
||||
|
||||
if (!update_record($this->table, addslashes_recursive($data))) {
|
||||
return false;
|
||||
@ -260,6 +250,24 @@ class grade_object {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns object with fields and values that are defined in database
|
||||
*/
|
||||
function get_record_data() {
|
||||
$data = new object();
|
||||
// we need to do this to prevent infinite loops in addslashes_recursive - grade_item -> category ->grade_item
|
||||
foreach ($this as $var=>$value) {
|
||||
if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
|
||||
if (is_object($value) or is_array($value)) {
|
||||
debugging("Incorrect property '$var' found when inserting grade object");
|
||||
} else {
|
||||
$data->$var = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records this object in the Database, sets its id to the returned value, and returns that value.
|
||||
* If successful this function also fetches the new object data from database and stores it
|
||||
@ -277,17 +285,7 @@ class grade_object {
|
||||
|
||||
$this->timecreated = $this->timemodified = time();
|
||||
|
||||
// we need to do this to prevent infinite loops in addslashes_recursive - grade_item -> category ->grade_item
|
||||
$data = new object();
|
||||
foreach ($this as $var=>$value) {
|
||||
if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
|
||||
if (is_object($value) or is_array($value)) {
|
||||
debugging("Incorrect property '$var' found when inserting grade object");
|
||||
} else {
|
||||
$data->$var = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = $this->get_record_data();
|
||||
|
||||
if (!$this->id = insert_record($this->table, addslashes_recursive($data))) {
|
||||
debugging("Could not insert object into db");
|
||||
|
Loading…
x
Reference in New Issue
Block a user