diff --git a/src/addon/mod/scorm/pages/player/player.ts b/src/addon/mod/scorm/pages/player/player.ts index 63d148aca..93024042c 100644 --- a/src/addon/mod/scorm/pages/player/player.ts +++ b/src/addon/mod/scorm/pages/player/player.ts @@ -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; diff --git a/src/addon/mod/scorm/providers/helper.ts b/src/addon/mod/scorm/providers/helper.ts index 95dd3c31b..ec0e1523b 100644 --- a/src/addon/mod/scorm/providers/helper.ts +++ b/src/addon/mod/scorm/providers/helper.ts @@ -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} Promise resolved with the first SCO. */ - getFirstSco(scormId: number, attempt: number, toc?: any[], organization?: string, offline?: boolean, siteId?: string) - : Promise { + getFirstSco(scormId: number, attempt: number, toc?: any[], organization?: string, mode?: string, offline?: boolean, + siteId?: string): Promise { + + 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]; }); }