MDL-83917 core_completion: Create function count_modules_completed

The function returns the number of modules completed by a user and
executes a COUNT aggregate function to avoid running many queries
to obtain this information, aiming to optimize performance.

Co-authored-by: Carlos Castillo <[email protected]>
This commit is contained in:
Pedro Jordao
2025-01-07 22:16:46 -03:00
co-authored by Carlos Castillo
parent ab5692acdf
commit e1688e7094
4 changed files with 179 additions and 10 deletions
+2 -10
View File
@@ -77,16 +77,8 @@ class progress {
}
// Get the number of modules that have been completed.
$completed = 0;
foreach ($modules as $module) {
$data = $completion->get_data($module, true, $userid);
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
$completed += 0;
} else {
$completed += 1;
};
}
$totalcompleted = $completion->count_modules_completed($userid);
return ($completed / $count) * 100;
return ($totalcompleted / $count) * 100;
}
}