mirror of
https://github.com/moodle/moodle.git
synced 2025-03-21 08:00:37 +01:00
Merge branch 'MDL-65363-starred-courses-only-include-enroled-courses-MOODLE_4.1' of https://github.com/stopfstedt/moodle into MOODLE_401_STABLE
This commit is contained in:
commit
6f0e80bd21
@ -82,14 +82,41 @@ class block_starredcourses_external extends core_course_external {
|
||||
// Get the favourites, by type, for the user.
|
||||
$favourites = $userservice->find_favourites_by_type('core_course', 'courses', $offset, $limit);
|
||||
|
||||
$favouritecourseids = [];
|
||||
if ($favourites) {
|
||||
$favouritecourseids = array_map(
|
||||
function($favourite) {
|
||||
return $favourite->itemid;
|
||||
}, $favourites);
|
||||
}
|
||||
|
||||
// Get all courses that the current user is enroled in, restricted down to favourites.
|
||||
$filteredcourses = [];
|
||||
if ($favouritecourseids) {
|
||||
$courses = course_get_enrolled_courses_for_logged_in_user(0, 0, null, null,
|
||||
COURSE_DB_QUERY_LIMIT, $favouritecourseids);
|
||||
list($filteredcourses, $processedcount) = course_filter_courses_by_favourites(
|
||||
$courses,
|
||||
$favouritecourseids,
|
||||
0
|
||||
);
|
||||
}
|
||||
// Grab the course ids.
|
||||
$filteredcourseids = array_column($filteredcourses, 'id');
|
||||
|
||||
// Filter out any favourites that are not in the list of enroled courses.
|
||||
$filteredfavourites = array_filter($favourites, function($favourite) use ($filteredcourseids) {
|
||||
return in_array($favourite->itemid, $filteredcourseids);
|
||||
});
|
||||
|
||||
// Sort the favourites getting last added first.
|
||||
usort($favourites, function($a, $b) {
|
||||
usort($filteredfavourites, function($a, $b) {
|
||||
if ($a->timemodified == $b->timemodified) return 0;
|
||||
return ($a->timemodified > $b->timemodified) ? -1 : 1;
|
||||
});
|
||||
|
||||
$formattedcourses = array();
|
||||
foreach ($favourites as $favourite) {
|
||||
foreach ($filteredfavourites as $favourite) {
|
||||
$course = get_course($favourite->itemid);
|
||||
$context = \context_course::instance($favourite->itemid);
|
||||
$canviewhiddencourses = has_capability('moodle/course:viewhiddencourses', $context);
|
||||
|
Loading…
x
Reference in New Issue
Block a user