diff --git a/classes/structure.php b/classes/structure.php index 47fd79d..67d67ff 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -857,13 +857,23 @@ class mod_attendance_structure { } public function update_users_grade($userids) { + global $DB; $grades = array(); + if ($this->grade < 0) { + $dbparams = array('id' => -($this->grade)); + $this->scale = $DB->get_record('scale', $dbparams); + $scalearray = explode(',', $this->scale->scale); + $attendancegrade = count($scalearray); + } else { + $attendancegrade = $this->grade; + } + foreach ($userids as $userid) { $grades[$userid] = new stdClass(); $grades[$userid]->userid = $userid; $grades[$userid]->rawgrade = attendance_calc_user_grade_fraction($this->get_user_grade($userid), - $this->get_user_max_grade($userid)) * $this->grade; + $this->get_user_max_grade($userid)) * $attendancegrade; } return grade_update('mod/attendance', $this->course->id, 'mod', 'attendance', diff --git a/locallib.php b/locallib.php index 6f1eb6b..dc5dff3 100644 --- a/locallib.php +++ b/locallib.php @@ -211,6 +211,7 @@ function attendance_calc_user_grade_fraction($grade, $maxgrade) { * @return float the calculated grade. */ function attendance_update_all_users_grades(mod_attendance_structure $attendance, $coursemodule) { + global $DB; $grades = array(); $course = $attendance->course; @@ -222,6 +223,14 @@ function attendance_update_all_users_grades(mod_attendance_structure $attendance $usergrades = $attgrades->items[0]->grades; } $statuses = attendance_get_statuses($attendance->id); + if ($attendance->grade < 0) { + $dbparams = array('id' => -($attendance->grade)); + $scale = $DB->get_record('scale', $dbparams); + $scalearray = explode(',', $scale->scale); + $gradebook_maxgrade = count($scalearray); + } else { + $gradebook_maxgrade = $attendance->grade; + } foreach ($usergrades as $userid => $existinggrade) { if (is_null($existinggrade->grade)) { // Don't update grades where one doesn't exist yet. @@ -233,7 +242,7 @@ function attendance_update_all_users_grades(mod_attendance_structure $attendance $usertakensesscount = attendance_get_user_taken_sessions_count($attendance->id, $course->startdate, $userid, $coursemodule); $usergrade = attendance_get_user_grade($userstatusesstat, $statuses); $usermaxgrade = attendance_get_user_max_grade($usertakensesscount, $statuses); - $grade->rawgrade = attendance_calc_user_grade_fraction($usergrade, $usermaxgrade) * $attendance->grade; + $grade->rawgrade = attendance_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebook_maxgrade; $grades[$userid] = $grade; }