|
@ -265,81 +265,6 @@ function attendance_cron () { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Return grade for given user or all users. |
|
|
|
|
|
* |
|
|
|
|
|
* @param int $attendanceid id of attendance |
|
|
|
|
|
* @param int $userid optional user id, 0 means all users |
|
|
|
|
|
* @return array array of grades, false if none |
|
|
|
|
|
*/ |
|
|
|
|
|
/*function attendance_get_user_grades($attendance, $userid=0) { |
|
|
|
|
|
global $CFG, $DB; |
|
|
|
|
|
|
|
|
|
|
|
require_once('_locallib.php'); |
|
|
|
|
|
|
|
|
|
|
|
if (! $course = $DB->get_record('course', array('id'=> $attendance->course))) { |
|
|
|
|
|
error("Course is misconfigured"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$result = false; |
|
|
|
|
|
if ($userid) { |
|
|
|
|
|
$result = array(); |
|
|
|
|
|
$result[$userid]->userid = $userid; |
|
|
|
|
|
$result[$userid]->rawgrade = $attendance->grade * get_percent($userid, $course, $attendance) / 100; |
|
|
|
|
|
} else { |
|
|
|
|
|
if ($students = get_course_students($course->id)) { |
|
|
|
|
|
$result = array(); |
|
|
|
|
|
foreach ($students as $student) { |
|
|
|
|
|
$result[$student->id]->userid = $student->id; |
|
|
|
|
|
$result[$student->id]->rawgrade = $attendance->grade * get_percent($student->id, $course, $attendance) / 100; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Update grades by firing grade_updated event |
|
|
|
|
|
* |
|
|
|
|
|
* @param object $attendance null means all attendances |
|
|
|
|
|
* @param int $userid specific user only, 0 mean all |
|
|
|
|
|
*/ |
|
|
|
|
|
/*function attendance_update_grades($attendance=null, $userid=0, $nullifnone=true) { |
|
|
|
|
|
global $CFG, $DB; |
|
|
|
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions |
|
|
|
|
|
require_once($CFG->libdir.'/gradelib.php'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($attendance != null) { |
|
|
|
|
|
if ($grades = attendance_get_user_grades($attendance, $userid)) { |
|
|
|
|
|
foreach($grades as $k=>$v) { |
|
|
|
|
|
if ($v->rawgrade == -1) { |
|
|
|
|
|
$grades[$k]->rawgrade = null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
attendance_grade_item_update($attendance, $grades); |
|
|
|
|
|
} else { |
|
|
|
|
|
attendance_grade_item_update($attendance); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid |
|
|
|
|
|
FROM {attendance} a, {course_modules} cm, {modules} m |
|
|
|
|
|
WHERE m.name='attendance' AND m.id=cm.module AND cm.instance=a.id"; |
|
|
|
|
|
if ($rs = $DB->get_records_sql($sql)) { |
|
|
|
|
|
foreach ($rs as $attendance) { |
|
|
|
|
|
// if ($attendance->grade != 0) { |
|
|
|
|
|
attendance_update_grades($attendance); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// attendance_grade_item_update($attendance); |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
$rs->close($rs); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Create grade item for given attendance |
|
|
* Create grade item for given attendance |
|
|
* |
|
|
* |
|
|