Browse Source

Fixes #51 Support for scales

Thanks to Greg (cedict) for the original patch.
MOODLE_29_STABLE
Dan Marsden 9 years ago
parent
commit
fcdd37b0fb
  1. 12
      classes/structure.php
  2. 11
      locallib.php

12
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',

11
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;
}

Loading…
Cancel
Save