Skip to content

Commit

Permalink
Merge pull request #4142 from albertgasset/MOBILE-4580
Browse files Browse the repository at this point in the history
MOBILE-4580 courses: Use new WS parameter to fetch course by section id
  • Loading branch information
dpalou authored Aug 14, 2024
2 parents 707b3c6 + 211342e commit 5bb121c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/core/features/courses/services/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export class CoreCoursesProvider {
* shortname: course short name.
* idnumber: course id number.
* category: category id the course belongs to.
* sectionid: section id that belongs to a course, since 4.5.
* @param value The value to match.
* @param siteId Site ID. If not defined, use current site.
* @returns Promise resolved with the first course.
Expand All @@ -436,6 +437,7 @@ export class CoreCoursesProvider {
* shortname: course short name.
* idnumber: course id number.
* category: category id the course belongs to.
* sectionid: section id that belongs to a course, since 4.5.
* @param value The value to match.
* @param siteId Site ID. If not defined, use current site.
* @returns Promise resolved with the courses.
Expand All @@ -457,6 +459,7 @@ export class CoreCoursesProvider {
* shortname: course short name.
* idnumber: course id number.
* category: category id the course belongs to.
* sectionid: section id that belongs to a course, since 4.5.
* @param value The value to match.
* @param options Other options.
* @returns Observable that returns the courses.
Expand Down
20 changes: 15 additions & 5 deletions src/core/features/courses/services/handlers/section-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { makeSingleton } from '@singletons';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
import { CoreCourseBasicData, CoreCourses } from '@features/courses/services/courses';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreCourse } from '@features/course/services/course';
import { CoreCoursesLinksHandlerBase } from '@features/courses/services/handlers/base-link-handler';
Expand Down Expand Up @@ -66,14 +66,24 @@ export class CoreCoursesSectionLinkHandlerService extends CoreCoursesLinksHandle
* @param siteId Site id.
* @returns Course.
*/
private async getSectionCourse(sectionId: number | false, siteId: string | false): Promise<CoreEnrolledCourseData | null> {
private async getSectionCourse(sectionId: number | false, siteId: string | false): Promise<CoreCourseBasicData | null> {
if (!siteId || !sectionId) {
return null;
}

// Ideally, we would use a webservice to get this information; but such webservice doesn't exists.
// Given that getting all the courses from a user could be very network intensive, all the requests
// in this method will only use cache.
const site = await CoreSites.getSite(siteId);

if (site.isVersionGreaterEqualThan('4.5')) {
try {
return CoreCourses.getCourseByField('sectionid', sectionId, siteId);
} catch {
// Fallback to searching courses stored in cache.
}
}

// In 4.4 and previous versions, the web service does not allow fetching a course by section id.
// Given that getting all the courses from a user could be very network intensive, the following
// requests will only use cache.

const courses = await CoreUtils.ignoreErrors(
CoreCourses.getUserCourses(true, siteId, CoreSitesReadingStrategy.ONLY_CACHE),
Expand Down

0 comments on commit 5bb121c

Please sign in to comment.