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:
co-authored by
Carlos Castillo
parent
ab5692acdf
commit
e1688e7094
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user