Skip to content

Commit

Permalink
MDL-32249 completion: Make grade criteria more consistent
Browse files Browse the repository at this point in the history
Also, round course grades and remove hardcoded string.

Note: This patch also removes the ability to update the course grade
from the completion interface
  • Loading branch information
Aaron Barnes committed Jun 26, 2012
1 parent 6be7840 commit 08f19f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
10 changes: 0 additions & 10 deletions course/completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@
$aggregation->setMethod($data->role_aggregation);
$aggregation->save();

// Update course total passing grade
if (!empty($data->criteria_grade)) {
if ($grade_item = grade_category::fetch_course_category($course->id)->grade_item) {
$grade_item->gradepass = $data->criteria_grade_value;
if (method_exists($grade_item, 'update')) {
$grade_item->update('course/completion.php');
}
}
}

add_to_log($course->id, 'course', 'completion updated', 'completion.php?id='.$course->id);

$url = new moodle_url('/course/view.php', array('id' => $course->id));
Expand Down
5 changes: 4 additions & 1 deletion course/completion_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,13 @@ function definition() {
$criteria->config_form_display($mform);

// Completion on course grade
$mform->addElement('header', 'grade', get_string('grade'));
$mform->addElement('header', 'grade', get_string('coursegrade', 'completion'));

// Grade enable and passing grade
$course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
if (!$course_grade) {
$course_grade = '0.00000';
}
$criteria = new completion_criteria_grade($params);
$criteria->config_form_display($mform, $course_grade);

Expand Down
4 changes: 3 additions & 1 deletion lang/en/completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
$string['coursesavailable']='Courses available';
$string['coursesavailableexplaination']='<i>Course completion criteria must be set for a course to appear in this list</i>';
$string['criteria']='Criteria';
$string['criteriagradenote'] = 'Please note that updating the required grade here will not update the current course pass grade.';
$string['criteriagroup']='Criteria group';
$string['criteriarequiredall']='All criteria below are required';
$string['criteriarequiredany']='Any criteria below are required';
Expand All @@ -124,6 +125,8 @@
$string['daysafterenrolment']='Days after enrolment';
$string['durationafterenrolment']='Duration after enrolment';
$string['fraction']='Fraction';
$string['gradexrequired']='{$a} required';
$string['graderequired']='Grade required';
$string['inprogress']='In progress';
$string['manualcompletionby']='Manual completion by';
$string['manualselfcompletion']='Manual self completion';
Expand All @@ -136,7 +139,6 @@
$string['notenroled']='You are not enrolled in this course';
$string['notyetstarted']='Not yet started';
$string['overallcriteriaaggregation']='Overall criteria type aggregation';
$string['passinggrade']='Passing grade';
$string['pending']='Pending';
$string['periodpostenrolment']='Period post enrolment';
$string['prerequisites']='Prerequisites';
Expand Down
25 changes: 14 additions & 11 deletions lib/completion/completion_criteria_grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public static function fetch($params) {
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
$mform->addElement('text', 'criteria_grade_value', get_string('passinggrade', 'completion'));
$mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
$mform->setDefault('criteria_grade_value', $data);
$mform->addElement('static', 'criteria_grade_value_note', '', get_string('criteriagradenote', 'completion'));

if ($this->id) {
$mform->setDefault('criteria_grade', 1);
Expand Down Expand Up @@ -128,7 +129,7 @@ public function review($completion, $mark = true) {
* @return string
*/
public function get_title() {
return get_string('grade');
return get_string('coursegrade', 'completion');
}

/**
Expand All @@ -137,7 +138,8 @@ public function get_title() {
* @return string
*/
public function get_title_detailed() {
return (float) $this->gradepass . '% required';
$graderequired = round($this->gradepass, 2).'%';
return get_string('gradexrequired', 'completion', $graderequired);
}

/**
Expand All @@ -156,15 +158,16 @@ public function get_type_title() {
* @return string
*/
public function get_status($completion) {
// Cast as floats to get rid of excess decimal places
$grade = (float) $this->get_grade($completion);
$gradepass = (float) $this->gradepass;
$grade = $this->get_grade($completion);
$graderequired = $this->get_title_detailed();

if ($grade) {
return $grade.'% ('.$gradepass.'% to pass)';
$grade = round($grade, 2).'%';
} else {
return $gradepass.'% to pass';
$grade = get_string('nograde');
}

return $grade.' ('.$graderequired.')';
}

/**
Expand Down Expand Up @@ -231,11 +234,11 @@ public function cron() {
public function get_details($completion) {
$details = array();
$details['type'] = get_string('coursegrade', 'completion');
$details['criteria'] = get_string('passinggrade', 'completion');
$details['requirement'] = ((float)$this->gradepass).'%';
$details['criteria'] = get_string('graderequired', 'completion');
$details['requirement'] = round($this->gradepass, 2).'%';
$details['status'] = '';

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

0 comments on commit 08f19f4

Please sign in to comment.