Merge pull request #3785 from dpalou/MOBILE-4323

MOBILE-4323 enrol: Handle methods without get_enrol_info
main
Pau Ferrer Ocaña 2023-09-13 10:07:29 +02:00 committed by GitHub
commit 23f0d07343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View File

@ -211,18 +211,20 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
}
}
await this.getEnrolmentInfo();
await this.getEnrolmentInfo(courseByField?.enrollmentmethods);
}
/**
* Get course enrolment methods.
* Get course enrolment info.
*
* @param enrolmentMethods Enrolment methods.
*/
protected async getEnrolmentInfo(): Promise<void> {
protected async getEnrolmentInfo(enrolmentMethods?: string[]): Promise<void> {
if (this.isEnrolled) {
return;
}
const enrolByType = await CoreEnrolHelper.getEnrolmentsByType(this.courseId);
const enrolByType = await CoreEnrolHelper.getEnrolmentsByType(this.courseId, enrolmentMethods);
this.hasBrowserEnrolments = enrolByType.hasBrowser;
this.selfEnrolInstances = enrolByType.self;

View File

@ -75,10 +75,12 @@ export class CoreEnrolHelperService {
* Get enrolment methods divided by type.
*
* @param courseId Course Id.
* @param allMethodTypes List of enrolment methods returned by getCourseByField.
* @returns Enrolment info divided by types.
*/
async getEnrolmentsByType(courseId: number): Promise<CoreEnrolmentsByType> {
const enrolmentMethods = await CoreEnrol.getSupportedCourseEnrolmentMethods(courseId);
async getEnrolmentsByType(courseId: number, allMethodTypes?: string[]): Promise<CoreEnrolmentsByType> {
// Don't use getSupportedCourseEnrolmentMethods to treat unsupported methods and methods with disabled status.
const enrolmentMethods = await CoreEnrol.getCourseEnrolmentMethods(courseId);
const self: CoreEnrolEnrolmentMethod[] = [];
const guest: CoreEnrolEnrolmentMethod[] = [];
@ -108,6 +110,17 @@ export class CoreEnrolHelperService {
}
});
// Now treat the methods returned by getCourseByField but not by getCourseEnrolmentMethods.
allMethodTypes?.forEach(type => {
if (enrolmentMethods.some(method => method.type === type)) {
return; // Already treated.
}
const action = CoreEnrolDelegate.getEnrolmentAction(type);
hasBrowser = hasBrowser || action === CoreEnrolAction.BROWSER;
hasNotSupported = hasNotSupported || action === CoreEnrolAction.NOT_SUPPORTED;
});
return {
self,
guest,

View File

@ -29,12 +29,14 @@ export class CoreEnrolService {
/**
* Get the enrolment methods from a course.
* Please notice that this function will only return methods that implement get_enrol_info, it won't return all
* enrolment methods in a course.
*
* @param courseId ID of the course.
* @param siteId Site ID. If not defined, use current site.
* @returns Promise resolved with the methods.
*/
protected async getCourseEnrolmentMethods(courseId: number, siteId?: string): Promise<CoreEnrolEnrolmentMethod[]> {
async getCourseEnrolmentMethods(courseId: number, siteId?: string): Promise<CoreEnrolEnrolmentMethod[]> {
const site = await CoreSites.getSite(siteId);
const params: CoreEnrolGetCourseEnrolmentMethodsWSParams = {
@ -50,6 +52,8 @@ export class CoreEnrolService {
/**
* Get the enrolment methods from a course that are enabled and supported by the app.
* Please notice that this function will only return methods that implement get_enrol_info, it won't return all
* enrolment methods in a course.
*
* @param courseId ID of the course.
* @param options Options.