Skip to content

Commit

Permalink
MDL-31635 completion: do not show % for the grade
Browse files Browse the repository at this point in the history
Also show grades with the configured number of decimal points
  • Loading branch information
marinaglancy committed Jan 25, 2016
1 parent e8d5100 commit 5824335
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions completion/criteria/completion_criteria_grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public function config_form_display(&$mform, $data = null) {
$mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
$mform->disabledIf('criteria_grade_value', 'criteria_grade');
$mform->setType('criteria_grade_value', PARAM_RAW); // Uses unformat_float.
$mform->setDefault('criteria_grade_value', format_float($data));
// Grades are stored in Moodle with 5 decimal points, make sure we do not accidentally round them
// when setting the form value.
$mform->setDefault('criteria_grade_value', format_float($data, 5));

if ($this->id) {
$mform->setDefault('criteria_grade', 1);
$mform->setDefault('criteria_grade_value', format_float($this->gradepass));
$mform->setDefault('criteria_grade_value', format_float($this->gradepass, 5));
}
}

Expand Down Expand Up @@ -141,7 +143,10 @@ public function get_title() {
* @return string
*/
public function get_title_detailed() {
$graderequired = round($this->gradepass, 2).'%';
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);
$graderequired = format_float($this->gradepass, $decimalpoints);
return get_string('gradexrequired', 'completion', $graderequired);
}

Expand All @@ -161,11 +166,15 @@ public function get_type_title() {
* @return string
*/
public function get_status($completion) {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);

$grade = $this->get_grade($completion);
$graderequired = $this->get_title_detailed();

if ($grade) {
$grade = round($grade, 2).'%';
$grade = format_float($grade, $decimalpoints);
} else {
$grade = get_string('nograde');
}
Expand Down Expand Up @@ -235,15 +244,19 @@ public function cron() {
* type, criteria, requirement, status
*/
public function get_details($completion) {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);

$details = array();
$details['type'] = get_string('coursegrade', 'completion');
$details['criteria'] = get_string('graderequired', 'completion');
$details['requirement'] = round($this->gradepass, 2).'%';
$details['requirement'] = format_float($this->gradepass, $decimalpoints);
$details['status'] = '';

$grade = round($this->get_grade($completion), 2);
$grade = format_float($this->get_grade($completion), $decimalpoints);
if ($grade) {
$details['status'] = $grade.'%';
$details['status'] = $grade;
}

return $details;
Expand Down

0 comments on commit 5824335

Please sign in to comment.