Merge pull request #4142 from albertgasset/MOBILE-4580
MOBILE-4580 courses: Use new WS parameter to fetch course by section idmain
commit
5bb121ce04
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
|
|
@ -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';
|
||||
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue