Browse Source

Fix grade calculation bug

2021092200_STABLE
Sesostris Vieira 3 years ago
parent
commit
aeb059c69d
  1. 14
      classes/task/grade_participation_task.php
  2. 1
      grade.php
  3. 8
      lib.php

14
classes/task/grade_participation_task.php

@ -44,17 +44,17 @@ class grade_participation_task extends \core\task\scheduled_task {
$palestras = $DB->get_records_sql("
select p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval
from {palestra} p
inner join {palestra_presence} pp on pp.palestraid = p.id
inner join {course} c on c.id = p.course
where
(p.needsupdate = 1) and
(c.visible = 1) and
((c.startdate <= ?) and (c.enddate = 0 or c.enddate >= ?))
and ((p.startdate + (p.duration*60)) < ?)
group by p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval
having max(pp.lastcheck) < ? - p.checkinterval*60
", [$now, $now, $now, $now]);
((c.startdate <= ?) and (c.enddate = 0 or c.enddate >= ?)) and
(select count(*)
from {palestra_presence} pp
where pp.palestraid = p.id and
(pp.lastcheck+(p.duration*60)) < ?
) > 0
", [$now, $now, $now]);
mtrace(count($palestras)." palestras to grade...");

1
grade.php

@ -26,6 +26,7 @@
require_once(__DIR__ . '/../../config.php');
require_once("lib.php");
require_once($CFG->libdir."/gradelib.php");
$id = required_param('id', PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);

8
lib.php

@ -207,10 +207,12 @@ function palestra_update_grades($palestra, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
$now = time();
if ($userid) {
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id, "userid"=>$userid), 'userid, starttime, lastcheck');
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id, "userid"=>$userid), 'id, userid, starttime, lastcheck');
} else {
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id), 'userid, starttime, lastcheck');
$presences = $DB->get_records_select("palestra_presence", "palestraid=? and lastcheck+? < ?", [$palestra->id, $palestra->duration*60, $now], 'userid, starttime', 'id, userid, starttime, lastcheck');
}
$audiences = array();
@ -231,7 +233,9 @@ function palestra_update_grades($palestra, $userid=0, $nullifnone=true) {
continue;
}
if ($presence->starttime < ($start + $minimal)) {
if ($end < $presence->lastcheck) {
$end = $presence->lastcheck;
}
} else {
$audiences[$user] = (isset($audiences[$user])?$audiences[$user]:0) + (max($end - $start, $minimal)/60);
$start = $presence->starttime;

Loading…
Cancel
Save