mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-62384 core_completion: Update to sql to improve performance.
This commit is contained in:
parent
8a5b84cf8b
commit
d8eec7ee38
@ -89,8 +89,10 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
||||
|
||||
$join = "JOIN {course_completion_criteria} {$cccalias} ON {$joinfield} = {$cccalias}.course
|
||||
LEFT JOIN {course_modules_completion} {$cmcalias} ON {$cccalias}.moduleinstance = {$cmcalias}.coursemoduleid
|
||||
LEFT JOIN {course_completion_crit_compl} {$ccccalias} ON {$ccccalias}.criteriaid = {$cccalias}.id";
|
||||
$where = "{$cmcalias}.userid = :{$prefix}_moduleuserid OR {$ccccalias}.userid = :{$prefix}_courseuserid";
|
||||
AND {$cmcalias}.userid = :{$prefix}_moduleuserid
|
||||
LEFT JOIN {course_completion_crit_compl} {$ccccalias} ON {$ccccalias}.criteriaid = {$cccalias}.id
|
||||
AND {$ccccalias}.userid = :{$prefix}_courseuserid";
|
||||
$where = "{$cmcalias}.id IS NOT NULL OR {$ccccalias}.id IS NOT NULL";
|
||||
$params = ["{$prefix}_moduleuserid" => $userid, "{$prefix}_courseuserid" => $userid];
|
||||
|
||||
return [$join, $where, $params];
|
||||
|
@ -103,8 +103,9 @@ trait completion_creation {
|
||||
* Complete some of the course completion criteria.
|
||||
*
|
||||
* @param stdClass $user The user object
|
||||
* @param bool $modulecompletion If true will complete the activity module completion thing.
|
||||
*/
|
||||
public function complete_course($user) {
|
||||
public function complete_course($user, $modulecompletion = true) {
|
||||
$this->getDataGenerator()->enrol_user($user->id, $this->course->id, 'student');
|
||||
$completion = new \completion_info($this->course);
|
||||
$criteriacompletions = $completion->get_completions($user->id, COMPLETION_CRITERIA_TYPE_ROLE);
|
||||
@ -112,7 +113,9 @@ trait completion_creation {
|
||||
foreach ($criteriacompletions as $ccompletion) {
|
||||
$criteria->complete($ccompletion);
|
||||
}
|
||||
// Set activity as complete.
|
||||
$completion->update_state($this->cm, COMPLETION_COMPLETE, $user->id);
|
||||
if ($modulecompletion) {
|
||||
// Set activity as complete.
|
||||
$completion->update_state($this->cm, COMPLETION_COMPLETE, $user->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class core_completion_privacy_test extends \core_privacy\tests\provider_testcase
|
||||
$this->resetAfterTest();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->create_course_completion();
|
||||
$this->complete_course($user);
|
||||
$this->complete_course($user, false);
|
||||
|
||||
list($join, $where, $params) = \core_completion\privacy\provider::get_course_completion_join_sql($user->id, 'comp', 'c.id');
|
||||
$sql = "SELECT DISTINCT c.id
|
||||
|
Loading…
x
Reference in New Issue
Block a user