Bufgix where checking page progress on an empty page would result in division by sero

This commit is contained in:
PMKuipers 2023-12-01 11:12:21 +01:00
parent 5ca74f8b1a
commit c9d9703a04
2 changed files with 19 additions and 7 deletions

View File

@ -629,11 +629,15 @@ class studyplan {
$progress = 0;
$pages = $this->pages();
foreach ($pages as $p) {
$progress += $p->scanuserprogress($userid);
$prg = $p->scanuserprogress($userid);
$progress += $prg;
}
// Now average it out over the amount of pages
$progress = $progress / count($pages);
return $progress;
if (count($pages) > 0 ) {
return $progress / count($pages);
} else {
return 0;
}
}
/**
@ -642,7 +646,10 @@ class studyplan {
* @return array Webservice data model
*/
public function user_model($userid) {
$progress = $this->scanuserprogress($userid);
if (is_nan($progress)) {
$progress = 0;
}
$model = [
'id' => $this->r->id,
'userid' => $userid,
@ -652,7 +659,7 @@ class studyplan {
'descriptionformat' => $this->r->descriptionformat,
'icon' => $this->icon(),
'idnumber' => $this->r->idnumber,
'progress' => $this->scanuserprogress($userid),
'progress' => $progress,
'pages' => [],
'aggregation_info' => $this->aggregator->basic_model(),
];
@ -865,7 +872,7 @@ class studyplan {
$sql = "SELECT COUNT(i.id)
FROM {local_treestudyplan}
INNER JOIN {local_treestudyplan_line} l ON p.id = l.studyplan_id
INNER JOIN {local_treestudyplan_item} i ON l.id = i.line_id
{local_treestudyplan_item} i ON l.id = i.line_id
WHERE p.id = :planid
AND i.course_id = :courseid";
$count = $DB->get_field_sql($sql, ["courseid" => $courseid, "planid" => $this->id]);

View File

@ -405,7 +405,12 @@ class studyplanpage {
}
}
}
if ( $courses > 0 ) {
return ($completed/$courses);
} else {
return 0;
}
}
/**