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