Bufgix where checking page progress on an empty page would result in division by sero
This commit is contained in:
parent
5ca74f8b1a
commit
c9d9703a04
2 changed files with 19 additions and 7 deletions
|
@ -629,11 +629,15 @@ class studyplan {
|
||||||
$progress = 0;
|
$progress = 0;
|
||||||
$pages = $this->pages();
|
$pages = $this->pages();
|
||||||
foreach ($pages as $p) {
|
foreach ($pages as $p) {
|
||||||
$progress += $p->scanuserprogress($userid);
|
$prg = $p->scanuserprogress($userid);
|
||||||
|
$progress += $prg;
|
||||||
}
|
}
|
||||||
// Now average it out over the amount of pages
|
// Now average it out over the amount of pages
|
||||||
$progress = $progress / count($pages);
|
if (count($pages) > 0 ) {
|
||||||
return $progress;
|
return $progress / count($pages);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -642,7 +646,10 @@ class studyplan {
|
||||||
* @return array Webservice data model
|
* @return array Webservice data model
|
||||||
*/
|
*/
|
||||||
public function user_model($userid) {
|
public function user_model($userid) {
|
||||||
|
$progress = $this->scanuserprogress($userid);
|
||||||
|
if (is_nan($progress)) {
|
||||||
|
$progress = 0;
|
||||||
|
}
|
||||||
$model = [
|
$model = [
|
||||||
'id' => $this->r->id,
|
'id' => $this->r->id,
|
||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
|
@ -652,7 +659,7 @@ class studyplan {
|
||||||
'descriptionformat' => $this->r->descriptionformat,
|
'descriptionformat' => $this->r->descriptionformat,
|
||||||
'icon' => $this->icon(),
|
'icon' => $this->icon(),
|
||||||
'idnumber' => $this->r->idnumber,
|
'idnumber' => $this->r->idnumber,
|
||||||
'progress' => $this->scanuserprogress($userid),
|
'progress' => $progress,
|
||||||
'pages' => [],
|
'pages' => [],
|
||||||
'aggregation_info' => $this->aggregator->basic_model(),
|
'aggregation_info' => $this->aggregator->basic_model(),
|
||||||
];
|
];
|
||||||
|
@ -865,7 +872,7 @@ class studyplan {
|
||||||
$sql = "SELECT COUNT(i.id)
|
$sql = "SELECT COUNT(i.id)
|
||||||
FROM {local_treestudyplan}
|
FROM {local_treestudyplan}
|
||||||
INNER JOIN {local_treestudyplan_line} l ON p.id = l.studyplan_id
|
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
|
WHERE p.id = :planid
|
||||||
AND i.course_id = :courseid";
|
AND i.course_id = :courseid";
|
||||||
$count = $DB->get_field_sql($sql, ["courseid" => $courseid, "planid" => $this->id]);
|
$count = $DB->get_field_sql($sql, ["courseid" => $courseid, "planid" => $this->id]);
|
||||||
|
|
|
@ -405,7 +405,12 @@ class studyplanpage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ($completed/$courses);
|
if ( $courses > 0 ) {
|
||||||
|
return ($completed/$courses);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue