forked from CIT/Vmeda.Online
		
	MOBILE-2554 course: Show all sections if non is defined
This commit is contained in:
		
							parent
							
								
									19291084d9
								
							
						
					
					
						commit
						2799bcdd5e
					
				| @ -47,8 +47,8 @@ export class CoreCourseFormatWeeksHandler implements CoreCourseFormatHandler { | |||||||
|         const now = this.timeUtils.timestamp(); |         const now = this.timeUtils.timestamp(); | ||||||
| 
 | 
 | ||||||
|         if (now < course.startdate || (course.enddate && now > course.enddate)) { |         if (now < course.startdate || (course.enddate && now > course.enddate)) { | ||||||
|             // Course hasn't started yet or it has ended already. Return the first section.
 |             // Course hasn't started yet or it has ended already. Return all sections.
 | ||||||
|             return sections[1]; |             return sections[0]; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (let i = 0; i < sections.length; i++) { |         for (let i = 0; i < sections.length; i++) { | ||||||
| @ -63,8 +63,8 @@ export class CoreCourseFormatWeeksHandler implements CoreCourseFormatHandler { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // The section wasn't found, return the first section.
 |         // The section wasn't found, return all sections.
 | ||||||
|         return sections[1]; |         return sections[0]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -98,38 +98,28 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { | |||||||
|      */ |      */ | ||||||
|     getCurrentSection(course: any, sections: any[]): any | Promise<any> { |     getCurrentSection(course: any, sections: any[]): any | Promise<any> { | ||||||
|         if (!this.coursesProvider.isGetCoursesByFieldAvailable()) { |         if (!this.coursesProvider.isGetCoursesByFieldAvailable()) { | ||||||
|             // Cannot get the current section, return the first one.
 |             // Cannot get the current section, return all of them.
 | ||||||
|             if (sections[0].id != CoreCourseProvider.ALL_SECTIONS_ID) { |  | ||||||
|             return sections[0]; |             return sections[0]; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|             return sections[1]; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         // We need the "marker" to determine the current section.
 |         // We need the "marker" to determine the current section.
 | ||||||
|         return this.coursesProvider.getCoursesByField('id', course.id).catch(() => { |         return this.coursesProvider.getCoursesByField('id', course.id).catch(() => { | ||||||
|             // Ignore errors.
 |             // Ignore errors.
 | ||||||
|         }).then((courses) => { |         }).then((courses) => { | ||||||
|             if (courses && courses[0]) { |             if (courses && courses[0] && courses[0].marker > 0) { | ||||||
|                 // Find the marked section.
 |                 // Find the marked section.
 | ||||||
|                 const course = courses[0]; |                 const course = courses[0], | ||||||
|                 for (let i = 0; i < sections.length; i++) { |                     section = sections.find((sect) => { | ||||||
|                     const section = sections[i]; |                         return sect.section == course.marker; | ||||||
|                     if (section.section == course.marker) { |                     }); | ||||||
|                         return section; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             // Marked section not found or we couldn't retrieve the marker. Return the first section.
 |                 if (section) { | ||||||
|             for (let i = 0; i < sections.length; i++) { |  | ||||||
|                 const section = sections[i]; |  | ||||||
|                 if (section.id != CoreCourseProvider.ALL_SECTIONS_ID) { |  | ||||||
|                     return section; |                     return section; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return Promise.reject(null); |             // Marked section not found or we couldn't retrieve the marker. Return all sections.
 | ||||||
|  |             return sections[0]; | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,7 +17,6 @@ import { NavController } from 'ionic-angular'; | |||||||
| import { CoreEventsProvider } from '@providers/events'; | import { CoreEventsProvider } from '@providers/events'; | ||||||
| import { CoreLoggerProvider } from '@providers/logger'; | import { CoreLoggerProvider } from '@providers/logger'; | ||||||
| import { CoreSitesProvider } from '@providers/sites'; | import { CoreSitesProvider } from '@providers/sites'; | ||||||
| import { CoreCourseProvider } from './course'; |  | ||||||
| import { CoreCourseFormatDefaultHandler } from './default-format'; | import { CoreCourseFormatDefaultHandler } from './default-format'; | ||||||
| import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; | import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; | ||||||
| 
 | 
 | ||||||
| @ -285,14 +284,11 @@ export class CoreCourseFormatDelegate extends CoreDelegate { | |||||||
|      * @return {Promise<any>} Promise resolved with current section. |      * @return {Promise<any>} Promise resolved with current section. | ||||||
|      */ |      */ | ||||||
|     getCurrentSection(course: any, sections: any[]): Promise<any> { |     getCurrentSection(course: any, sections: any[]): Promise<any> { | ||||||
|  | 
 | ||||||
|         // Convert the result to a Promise if it isn't.
 |         // Convert the result to a Promise if it isn't.
 | ||||||
|         return Promise.resolve(this.executeFunctionOnEnabled(course.format, 'getCurrentSection', [course, sections])).catch(() => { |         return Promise.resolve(this.executeFunctionOnEnabled(course.format, 'getCurrentSection', [course, sections])).catch(() => { | ||||||
|             // This function should never fail. Just return the first section.
 |             // This function should never fail. Just return all the sections.
 | ||||||
|             if (sections[0].id != CoreCourseProvider.ALL_SECTIONS_ID) { |  | ||||||
|             return sections[0]; |             return sections[0]; | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return sections[1]; |  | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -390,6 +390,7 @@ export class CoreCoursesProvider { | |||||||
|      * @param {any} [value] The value to match. |      * @param {any} [value] The value to match. | ||||||
|      * @param {string} [siteId] Site ID. If not defined, use current site. |      * @param {string} [siteId] Site ID. If not defined, use current site. | ||||||
|      * @return {Promise<any[]>} Promise resolved with the courses. |      * @return {Promise<any[]>} Promise resolved with the courses. | ||||||
|  |      * @since 3.2 | ||||||
|      */ |      */ | ||||||
|     getCoursesByField(field?: string, value?: any, siteId?: string): Promise<any[]> { |     getCoursesByField(field?: string, value?: any, siteId?: string): Promise<any[]> { | ||||||
|         siteId = siteId || this.sitesProvider.getCurrentSiteId(); |         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||||
| @ -473,6 +474,7 @@ export class CoreCoursesProvider { | |||||||
|      * Check if get courses by field WS is available. |      * Check if get courses by field WS is available. | ||||||
|      * |      * | ||||||
|      * @return {boolean} Whether get courses by field is available. |      * @return {boolean} Whether get courses by field is available. | ||||||
|  |      * @since 3.2 | ||||||
|      */ |      */ | ||||||
|     isGetCoursesByFieldAvailable(): boolean { |     isGetCoursesByFieldAvailable(): boolean { | ||||||
|         return this.sitesProvider.wsAvailableInCurrentSite('core_course_get_courses_by_field'); |         return this.sitesProvider.wsAvailableInCurrentSite('core_course_get_courses_by_field'); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user