mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
MDL-64644 completion: ensure we return array for provider
This commit is contained in:
parent
b39f7194a8
commit
124c24eb0e
2 changed files with 59 additions and 40 deletions
|
@ -161,47 +161,48 @@ class provider implements
|
|||
$completioninfo = new \completion_info($course);
|
||||
$completion = $completioninfo->is_enabled();
|
||||
|
||||
if ($completion == COMPLETION_ENABLED) {
|
||||
|
||||
$coursecomplete = $completioninfo->is_course_complete($user->id);
|
||||
$criteriacomplete = $completioninfo->count_course_user_data($user->id);
|
||||
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
||||
|
||||
$status = ($coursecomplete) ? get_string('complete') : '';
|
||||
$status = (!$criteriacomplete && !$ccompletion->timestarted) ? get_string('notyetstarted', 'completion') :
|
||||
get_string('inprogress', 'completion');
|
||||
|
||||
$completions = $completioninfo->get_completions($user->id);
|
||||
$overall = get_string('nocriteriaset', 'completion');
|
||||
if (!empty($completions)) {
|
||||
if ($completioninfo->get_aggregation_method() == COMPLETION_AGGREGATION_ALL) {
|
||||
$overall = get_string('criteriarequiredall', 'completion');
|
||||
} else {
|
||||
$overall = get_string('criteriarequiredany', 'completion');
|
||||
}
|
||||
}
|
||||
|
||||
$coursecompletiondata = [
|
||||
'status' => $status,
|
||||
'required' => $overall,
|
||||
];
|
||||
|
||||
$coursecompletiondata['criteria'] = array_map(function($completion) use ($completioninfo) {
|
||||
$criteria = $completion->get_criteria();
|
||||
$aggregation = $completioninfo->get_aggregation_method($criteria->criteriatype);
|
||||
$required = ($aggregation == COMPLETION_AGGREGATION_ALL) ? get_string('all', 'completion') :
|
||||
get_string('any', 'completion');
|
||||
$data = [
|
||||
'required' => $required,
|
||||
'completed' => transform::yesno($completion->is_complete()),
|
||||
'timecompleted' => isset($completion->timecompleted) ? transform::datetime($completion->timecompleted) : ''
|
||||
];
|
||||
$details = $criteria->get_details($completion);
|
||||
$data = array_merge($data, $details);
|
||||
return $data;
|
||||
}, $completions);
|
||||
return $coursecompletiondata;
|
||||
if ($completion != COMPLETION_ENABLED) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$coursecomplete = $completioninfo->is_course_complete($user->id);
|
||||
$criteriacomplete = $completioninfo->count_course_user_data($user->id);
|
||||
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
||||
|
||||
$status = ($coursecomplete) ? get_string('complete') : '';
|
||||
$status = (!$criteriacomplete && !$ccompletion->timestarted) ? get_string('notyetstarted', 'completion') :
|
||||
get_string('inprogress', 'completion');
|
||||
|
||||
$completions = $completioninfo->get_completions($user->id);
|
||||
$overall = get_string('nocriteriaset', 'completion');
|
||||
if (!empty($completions)) {
|
||||
if ($completioninfo->get_aggregation_method() == COMPLETION_AGGREGATION_ALL) {
|
||||
$overall = get_string('criteriarequiredall', 'completion');
|
||||
} else {
|
||||
$overall = get_string('criteriarequiredany', 'completion');
|
||||
}
|
||||
}
|
||||
|
||||
$coursecompletiondata = [
|
||||
'status' => $status,
|
||||
'required' => $overall,
|
||||
];
|
||||
|
||||
$coursecompletiondata['criteria'] = array_map(function($completion) use ($completioninfo) {
|
||||
$criteria = $completion->get_criteria();
|
||||
$aggregation = $completioninfo->get_aggregation_method($criteria->criteriatype);
|
||||
$required = ($aggregation == COMPLETION_AGGREGATION_ALL) ? get_string('all', 'completion') :
|
||||
get_string('any', 'completion');
|
||||
$data = [
|
||||
'required' => $required,
|
||||
'completed' => transform::yesno($completion->is_complete()),
|
||||
'timecompleted' => isset($completion->timecompleted) ? transform::datetime($completion->timecompleted) : ''
|
||||
];
|
||||
$details = $criteria->get_details($completion);
|
||||
$data = array_merge($data, $details);
|
||||
return $data;
|
||||
}, $completions);
|
||||
return $coursecompletiondata;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -202,4 +202,22 @@ class core_completion_privacy_test extends \core_privacy\tests\provider_testcase
|
|||
$hasyes = array_search('Yes', $coursecompletion1['criteria'], true);
|
||||
$this->assertFalse($hasyes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting course completion information with completion disabled.
|
||||
*/
|
||||
public function test_get_course_completion_info_completion_disabled() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 0]);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, 'student');
|
||||
|
||||
$coursecompletion = \core_completion\privacy\provider::get_course_completion_info($user, $course);
|
||||
|
||||
$this->assertTrue(is_array($coursecompletion));
|
||||
$this->assertEmpty($coursecompletion);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue