MDL-46576 core_grades: Add weights to natural (MDL-47006)

This commit is contained in:
John Okely
2014-10-03 13:49:22 +08:00
committed by Adrian Greeve
parent b5e00814b3
commit 677bc07377
6 changed files with 45 additions and 5 deletions
+1 -1
View File
@@ -260,7 +260,7 @@ if ($data = data_submitted() and confirm_sesskey()) {
$recreatetree = true;
// Grade item text inputs
} elseif (preg_match('/^(grademax|aggregationcoef|multfactor|plusfactor)_([0-9]+)$/', $key, $matches)) {
} elseif (preg_match('/^(grademax|aggregationcoef|aggregationcoef2|multfactor|plusfactor)_([0-9]+)$/', $key, $matches)) {
$param = $matches[1];
$aid = $matches[2];
+14
View File
@@ -46,6 +46,8 @@ class grade_edit_tree {
public $uses_weight = false;
public $uses_weight2 = false;
public $table;
public $categories = array();
@@ -73,6 +75,10 @@ class grade_edit_tree {
$this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)),
grade_edit_tree_column::factory('aggregation', array('flag' => true)));
if ($this->uses_weight2) {
$this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef2'));
}
if ($this->uses_weight) {
$this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef'));
}
@@ -389,6 +395,11 @@ class grade_edit_tree {
<label class="accesshide" for="extracredit_'.$item->id.'">'.
get_string('extracreditvalue', 'grades', $item->itemname).'</label>
<input type="checkbox" id="extracredit_'.$item->id.'" name="extracredit_'.$item->id.'" value="1" '."$checked />\n";
} else if ($aggcoef == 'aggregationcoefextrasum' && $type == 'weight') {
return '<label class="accesshide" for="aggregationcoef_'.$item->id.'">'.
get_string('weight', 'grades', $item->itemname).'</label>'.
'<input type="text" size="6" id="aggregationcoef2_'.$item->id.'" name="aggregationcoef2_'.$item->id.'"
value="'.grade_edit_tree::format_number($item->aggregationcoef2).'" />';
} else {
return '';
}
@@ -491,6 +502,9 @@ class grade_edit_tree {
} elseif ($coefstring == 'aggregationcoefextraweight' || $coefstring == 'aggregationcoefextrasum') {
$this->uses_extra_credit = true;
}
if ($coefstring == 'aggregationcoefextrasum') { // TODO: coefstring2?
$this->uses_weight2 = true;
}
foreach($element['children'] as $child_el) {
if ($level > $deepest_level) {
+1
View File
@@ -716,6 +716,7 @@ $string['weighteddescending'] = 'Sort by weighted percent descending';
$string['weightedpct'] = 'weighted %';
$string['weightedpctcontribution'] = 'weighted % contribution';
$string['weightorextracredit'] = 'Weight or extra credit';
$string['weight'] = 'Weight';
$string['weights'] = 'Weights';
$string['weightsedit'] = 'Edit weights and extra credits';
$string['weightuc'] = 'Calculated weight';
+1
View File
@@ -1717,6 +1717,7 @@
<FIELD NAME="multfactor" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="1.0" SEQUENCE="false" DECIMALS="5" COMMENT="Multiply all grades by this"/>
<FIELD NAME="plusfactor" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="Add this to all grades"/>
<FIELD NAME="aggregationcoef" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="Aggregation coefficient used for category weights or other aggregation types"/>
<FIELD NAME="aggregationcoef2" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="Aggregation coefficient used for category weights or other aggregation types"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Sorting order of the columns"/>
<FIELD NAME="display" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display as real grades, percentages (in reference to the minimum and maximum grades) or letters (A, B, C etc..), or course default (0)"/>
<FIELD NAME="decimals" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Also known as precision, the number of digits after the decimal point symbol."/>
+16
View File
@@ -3859,5 +3859,21 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2014082700.00);
}
if ($oldversion < 2014082700.01) {
// Define field aggregationcoef2 to be added to grade_items.
$table = new xmldb_table('grade_items');
$field = new xmldb_field('aggregationcoef2', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'timemodified');
// Conditionally launch add field aggregationcoef2.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014082700.01);
}
return true;
}
+12 -4
View File
@@ -50,8 +50,8 @@ class grade_item extends grade_object {
public $required_fields = array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
'timemodified');
'aggregationcoef2', 'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime',
'needsupdate', 'timecreated', 'timemodified');
/**
* The course this grade_item belongs to.
@@ -199,11 +199,17 @@ class grade_item extends grade_object {
public $plusfactor = 0;
/**
* Aggregation coeficient used for weighted averages
* Aggregation coeficient used for weighted averages or extra credit
* @var float $aggregationcoef
*/
public $aggregationcoef = 0;
/**
* Aggregation coeficient used for weighted averages only
* @var float $aggregationcoef2
*/
public $aggregationcoef2 = 0;
/**
* Sorting order of the columns.
* @var int $sortorder
@@ -277,6 +283,7 @@ class grade_item extends grade_object {
$this->multfactor = grade_floatval($this->multfactor);
$this->plusfactor = grade_floatval($this->plusfactor);
$this->aggregationcoef = grade_floatval($this->aggregationcoef);
$this->aggregationcoef2 = grade_floatval($this->aggregationcoef2);
return parent::update($source);
}
@@ -306,13 +313,14 @@ class grade_item extends grade_object {
$multfactordiff = grade_floats_different($db_item->multfactor, $this->multfactor);
$plusfactordiff = grade_floats_different($db_item->plusfactor, $this->plusfactor);
$acoefdiff = grade_floats_different($db_item->aggregationcoef, $this->aggregationcoef);
$acoefdiff2 = grade_floats_different($db_item->aggregationcoef2, $this->aggregationcoef2);
$needsupdatediff = !$db_item->needsupdate && $this->needsupdate; // force regrading only if setting the flag first time
$lockeddiff = !empty($db_item->locked) && empty($this->locked); // force regrading only when unlocking
return ($calculationdiff || $categorydiff || $gradetypediff || $grademaxdiff || $grademindiff || $scaleiddiff
|| $outcomeiddiff || $multfactordiff || $plusfactordiff || $needsupdatediff
|| $lockeddiff || $acoefdiff || $locktimediff);
|| $lockeddiff || $acoefdiff || $acoefdiff2 || $locktimediff);
}
/**