MDL-54105 mod_assign: Added default gradetype and gradescale
Added 2 new settings to mod_assign and made moodle core look for them to set the default grade values.
This commit is contained in:
+25
-13
@@ -60,8 +60,8 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
|
||||
/** @var int $currentscaleid The current scale id */
|
||||
public $currentscaleid = null;
|
||||
|
||||
/** @var string $currentgradetype The current gradetype - can either be 'none', 'scale', or 'point' */
|
||||
public $currentgradetype = 'none';
|
||||
/** @var ?string $currentgradetype The current gradetype - can either be 'none', 'scale', or 'point' */
|
||||
public $currentgradetype = null;
|
||||
|
||||
/** @var boolean $useratings Set to true if the activity is using ratings, false otherwise */
|
||||
public $useratings = false;
|
||||
@@ -514,18 +514,30 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
|
||||
// This means that the subelements data (inc const and default values) can be overridden by form code.
|
||||
// So - when we call this code really we can't be sure that will be the end value for the element.
|
||||
if (!empty($this->_elements)) {
|
||||
if (!empty($value)) {
|
||||
if ($value < 0) {
|
||||
$this->gradetypeformelement->setValue('scale');
|
||||
$this->scaleformelement->setValue(($value * -1));
|
||||
} else if ($value > 0) {
|
||||
$this->gradetypeformelement->setValue('point');
|
||||
$maxvalue = !empty($this->currentgrade) ? (string)unformat_float($this->currentgrade) : $value;
|
||||
$this->maxgradeformelement->setValue($maxvalue);
|
||||
if (!$this->currentgradetype) {
|
||||
if (!empty($value)) {
|
||||
$this->currentgradetype = $value < 0 ? 'scale' : 'point';
|
||||
} else {
|
||||
$this->currentgradetype = 'none';
|
||||
}
|
||||
} else {
|
||||
$this->gradetypeformelement->setValue('none');
|
||||
$this->maxgradeformelement->setValue(100);
|
||||
}
|
||||
|
||||
$this->gradetypeformelement->setValue($this->currentgradetype);
|
||||
|
||||
switch ($this->currentgradetype) {
|
||||
case 'scale':
|
||||
if (!empty($value)) {
|
||||
$this->currentscaleid = $value * -1;
|
||||
}
|
||||
$this->scaleformelement->setValue($this->currentscaleid);
|
||||
break;
|
||||
case 'point':
|
||||
case 'none':
|
||||
if (!empty($value)) {
|
||||
$maxvalue = !empty($this->currentgrade) ? (string)unformat_float($this->currentgrade) : $value;
|
||||
}
|
||||
$this->maxgradeformelement->setValue($maxvalue ?? 100);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user