Skip to content

Commit

Permalink
Merge branch 'wip-MDL-33563-m25' of git://github.com/marinaglancy/moo…
Browse files Browse the repository at this point in the history
…dle into MOODLE_25_STABLE
  • Loading branch information
stronk7 committed Jul 22, 2013
2 parents 55be97f + 16307c1 commit ed3a28d
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
11 changes: 7 additions & 4 deletions grade/grading/form/guide/lib.php
Expand Up @@ -820,10 +820,9 @@ public function update($data) {
/**
* Calculates the grade to be pushed to the gradebook
*
* @return int the valid grade from $this->get_controller()->get_grade_range()
* @return float|int the valid grade from $this->get_controller()->get_grade_range()
*/
public function get_grade() {
global $DB, $USER;
$grade = $this->get_guide_filling();

if (!($scores = $this->get_controller()->get_min_max_score()) || $scores['maxscore'] <= $scores['minscore']) {
Expand All @@ -842,8 +841,12 @@ public function get_grade() {
foreach ($grade['criteria'] as $record) {
$curscore += $record['score'];
}
return round(($curscore-$scores['minscore'])/($scores['maxscore']-$scores['minscore'])*
($maxgrade-$mingrade), 0) + $mingrade;
$gradeoffset = ($curscore-$scores['minscore'])/($scores['maxscore']-$scores['minscore'])*
($maxgrade-$mingrade);
if ($this->get_controller()->get_allow_grade_decimals()) {
return $gradeoffset + $mingrade;
}
return round($gradeoffset, 0) + $mingrade;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions grade/grading/form/guide/version.php
Expand Up @@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'gradingform_guide';
$plugin->version = 2013050100;
$plugin->requires = 2013050100;
$plugin->version = 2013051401.05;
$plugin->requires = 2013051401.05;
$plugin->maturity = MATURITY_STABLE;
36 changes: 31 additions & 5 deletions grade/grading/form/lib.php
Expand Up @@ -73,6 +73,9 @@ abstract class gradingform_controller {
/** @var array graderange array of valid grades for this area. Use set_grade_range and get_grade_range to access this */
private $graderange = null;

/** @var bool if decimal values are allowed as grades. */
private $allowgradedecimals = false;

/** @var boolean|null cached result of function has_active_instances() */
protected $hasactiveinstances = null;

Expand Down Expand Up @@ -622,13 +625,23 @@ public function render_grade($page, $itemid, $gradinginfo, $defaultcontent, $can

/**
* Sets the range of grades used in this area. This is usually either range like 0-100
* or the scale where keys start from 1. Typical use:
* $controller->set_grade_range(make_grades_menu($gradingtype));
* or the scale where keys start from 1.
*
* Typically modules will call it:
* $controller->set_grade_range(make_grades_menu($gradingtype), $gradingtype > 0);
* Negative $gradingtype means that scale is used and the grade must be rounded
* to the nearest int. Positive $gradingtype means that range 0..$gradingtype
* is used for the grades and in this case grade does not have to be rounded.
*
* Sometimes modules always expect grade to be rounded (like mod_assignment does).
*
* @param array $graderange
* @param array $graderange array where first _key_ is the minimum grade and the
* last key is the maximum grade.
* @param bool $allowgradedecimals if decimal values are allowed as grades.
*/
public final function set_grade_range(array $graderange) {
public final function set_grade_range(array $graderange, $allowgradedecimals = false) {
$this->graderange = $graderange;
$this->allowgradedecimals = $allowgradedecimals;
}

/**
Expand All @@ -643,6 +656,15 @@ public final function get_grade_range() {
return $this->graderange;
}

/**
* Returns if decimal values are allowed as grades
*
* @return bool
*/
public final function get_allow_grade_decimals() {
return $this->allowgradedecimals;
}

/**
* Overridden by sub classes that wish to make definition details available to web services.
* When not overridden, only definition data common to all grading methods is made available.
Expand Down Expand Up @@ -866,7 +888,11 @@ public function update($elementvalue) {
/**
* Calculates the grade to be pushed to the gradebook
*
* @return int the valid grade from $this->get_controller()->get_grade_range()
* Returned grade must be in range $this->get_controller()->get_grade_range()
* Plugins must returned grade converted to int unless
* $this->get_controller()->get_allow_grade_decimals() is true.
*
* @return float|int
*/
abstract public function get_grade();

Expand Down
9 changes: 6 additions & 3 deletions grade/grading/form/rubric/lib.php
Expand Up @@ -814,10 +814,9 @@ public function update($data) {
/**
* Calculates the grade to be pushed to the gradebook
*
* @return int the valid grade from $this->get_controller()->get_grade_range()
* @return float|int the valid grade from $this->get_controller()->get_grade_range()
*/
public function get_grade() {
global $DB, $USER;
$grade = $this->get_rubric_filling();

if (!($scores = $this->get_controller()->get_min_max_score()) || $scores['maxscore'] <= $scores['minscore']) {
Expand All @@ -836,7 +835,11 @@ public function get_grade() {
foreach ($grade['criteria'] as $id => $record) {
$curscore += $this->get_controller()->get_definition()->rubric_criteria[$id]['levels'][$record['levelid']]['score'];
}
return round(($curscore-$scores['minscore'])/($scores['maxscore']-$scores['minscore'])*($maxgrade-$mingrade), 0) + $mingrade;
$gradeoffset = ($curscore-$scores['minscore'])/($scores['maxscore']-$scores['minscore'])*($maxgrade-$mingrade);
if ($this->get_controller()->get_allow_grade_decimals()) {
return $gradeoffset + $mingrade;
}
return round($gradeoffset, 0) + $mingrade;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions grade/grading/form/rubric/version.php
Expand Up @@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'gradingform_rubric';
$plugin->version = 2013050100;
$plugin->version = 2013051401.05;

$plugin->requires = 2013050100;
$plugin->requires = 2013051401.05;

$plugin->maturity = MATURITY_STABLE;
9 changes: 9 additions & 0 deletions grade/grading/form/upgrade.txt
@@ -0,0 +1,9 @@
This files describes API changes in /grade/grading/form/* - Advanced grading methods
information provided here is intended especially for developers.

=== 2.5.2 ===

* Grading methods now can return grade with decimals. See API functions
gradingform_controller::set_grade_range() and
gradingform_controller::get_allow_grade_decimals(), and also examples
in gradingform_rubric_instance::get_grade().
7 changes: 4 additions & 3 deletions mod/assign/locallib.php
Expand Up @@ -3394,7 +3394,7 @@ public function view_student_summary($user, $showlinks) {
// Only show the grade if it is not hidden in gradebook.
if (!empty($gradebookgrade->grade) && ($cangrade || !$gradebookgrade->hidden)) {
if ($controller = $gradingmanager->get_active_controller()) {
$controller->set_grade_range(make_grades_menu($this->get_instance()->grade));
$controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0);
$gradefordisplay = $controller->render_grade($PAGE,
$grade->id,
$gradingitem,
Expand Down Expand Up @@ -3491,7 +3491,7 @@ protected function get_all_grades($userid) {

// Now get the gradefordisplay.
if ($controller) {
$controller->set_grade_range(make_grades_menu($this->get_instance()->grade));
$controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0);
$grade->gradefordisplay = $controller->render_grade($PAGE,
$grade->id,
$gradingitem,
Expand Down Expand Up @@ -4880,6 +4880,7 @@ protected function get_grading_instance($userid, $grade, $gradingdisabled) {
global $CFG, $USER;

$grademenu = make_grades_menu($this->get_instance()->grade);
$allowgradedecimals = $this->get_instance()->grade > 0;

$advancedgradingwarning = false;
$gradingmanager = get_grading_manager($this->context, 'mod_assign', 'submissions');
Expand All @@ -4904,7 +4905,7 @@ protected function get_grading_instance($userid, $grade, $gradingdisabled) {
}
}
if ($gradinginstance) {
$gradinginstance->get_controller()->set_grade_range($grademenu);
$gradinginstance->get_controller()->set_grade_range($grademenu, $allowgradedecimals);
}
return $gradinginstance;
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2013051401.04; // 20130514 = branching date YYYYMMDD - do not modify!
$version = 2013051401.05; // 20130514 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

Expand Down

0 comments on commit ed3a28d

Please sign in to comment.