MOBILE-2930 scorm: Fix no visible SCO to load

main
Dani Palou 2019-07-16 13:44:49 +02:00
parent 7619c63f70
commit b3e1e29932
2 changed files with 35 additions and 20 deletions

View File

@ -270,24 +270,31 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
sco.image = this.scormProvider.getScoStatusIcon(sco, this.scorm.incomplete);
});
// Determine current SCO if we received an ID..
if (this.initialScoId > 0) {
// SCO set by parameter, get it from TOC.
this.currentSco = this.scormHelper.getScoFromToc(this.toc, this.initialScoId);
}
if (!this.currentSco) {
// No SCO defined. Get the first valid one.
return this.scormHelper.getFirstSco(this.scorm.id, this.attempt, this.toc, this.organizationId, this.offline)
.then((sco) => {
if (this.newAttempt) {
// Creating a new attempt, use the first SCO defined by the SCORM.
this.initialScoId = this.scorm.launch;
}
if (sco) {
this.currentSco = sco;
} else {
// We couldn't find a SCO to load: they're all inactive or without launch URL.
this.errorMessage = 'addon.mod_scorm.errornovalidsco';
}
});
// Determine current SCO if we received an ID.
if (this.initialScoId > 0) {
// SCO set by parameter, get it from TOC.
this.currentSco = this.scormHelper.getScoFromToc(this.toc, this.initialScoId);
}
if (!this.currentSco) {
// No SCO defined. Get the first valid one.
return this.scormHelper.getFirstSco(this.scorm.id, this.attempt, this.toc, this.organizationId, this.mode,
this.offline).then((sco) => {
if (sco) {
this.currentSco = sco;
} else {
// We couldn't find a SCO to load: they're all inactive or without launch URL.
this.errorMessage = 'addon.mod_scorm.errornovalidsco';
}
});
}
}
}).finally(() => {
this.loadingToc = false;

View File

@ -199,12 +199,15 @@ export class AddonModScormHelperProvider {
* @param {number} attempt Attempt number.
* @param {any[]} [toc] SCORM's TOC. If not provided, it will be calculated.
* @param {string} [organization] Organization to use.
* @param {string} [mode] Mode.
* @param {boolean} [offline] Whether the attempt is offline.
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<any>} Promise resolved with the first SCO.
*/
getFirstSco(scormId: number, attempt: number, toc?: any[], organization?: string, offline?: boolean, siteId?: string)
: Promise<any> {
getFirstSco(scormId: number, attempt: number, toc?: any[], organization?: string, mode?: string, offline?: boolean,
siteId?: string): Promise<any> {
mode = mode || AddonModScormProvider.MODENORMAL;
let promise;
if (toc && toc.length) {
@ -215,15 +218,20 @@ export class AddonModScormHelperProvider {
}
return promise.then((scos) => {
// Search the first valid SCO.
for (let i = 0; i < scos.length; i++) {
const sco = scos[i];
// Return the first valid and incomplete SCO.
if (sco.isvisible && sco.prereq && sco.launch && this.scormProvider.isStatusIncomplete(sco.status)) {
if (sco.isvisible && sco.launch && sco.prereq &&
(mode != AddonModScormProvider.MODENORMAL || this.scormProvider.isStatusIncomplete(sco.status))) {
// In browse/review mode return the first visible sco. In normal mode, first incomplete sco.
return sco;
}
}
// No "valid" SCO, load the first one. In web it loads the first child because the toc contains the organization SCO.
return scos[0];
});
}