From 8127c500c9ff2cf3a765f5aff8ecbf9650d1f827 Mon Sep 17 00:00:00 2001 From: dpalou Date: Wed, 26 Sep 2018 15:57:19 +0200 Subject: [PATCH 1/2] MOBILE-2600 scorm: Support always force new attempt --- src/addon/mod/scorm/components/index/index.ts | 4 +++- src/addon/mod/scorm/providers/scorm.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/addon/mod/scorm/components/index/index.ts b/src/addon/mod/scorm/components/index/index.ts index 56adc3e0f..fcb892d5b 100644 --- a/src/addon/mod/scorm/components/index/index.ts +++ b/src/addon/mod/scorm/components/index/index.ts @@ -207,7 +207,9 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom this.scorm.numAttempts = this.attempts.total; this.scorm.gradeMethodReadable = this.scormProvider.getScormGradeMethod(this.scorm); this.scorm.attemptsLeft = this.scormProvider.countAttemptsLeft(this.scorm, this.attempts.lastAttempt.number); - if (this.scorm.forceattempt && this.scorm.incomplete) { + + if (this.scorm.forcenewattempt == AddonModScormProvider.SCORM_FORCEATTEMPT_ALWAYS || + (this.scorm.forcenewattempt && !this.scorm.incomplete)) { this.scormOptions.newAttempt = true; } diff --git a/src/addon/mod/scorm/providers/scorm.ts b/src/addon/mod/scorm/providers/scorm.ts index b71ac4800..6c3a7a151 100644 --- a/src/addon/mod/scorm/providers/scorm.ts +++ b/src/addon/mod/scorm/providers/scorm.ts @@ -77,6 +77,10 @@ export class AddonModScormProvider { static MODENORMAL = 'normal'; static MODEREVIEW = 'review'; + static SCORM_FORCEATTEMPT_NO = 0; + static SCORM_FORCEATTEMPT_ONCOMPLETE = 1; + static SCORM_FORCEATTEMPT_ALWAYS = 2; + // Events. static LAUNCH_NEXT_SCO_EVENT = 'addon_mod_scorm_launch_next_sco'; static LAUNCH_PREV_SCO_EVENT = 'addon_mod_scorm_launch_prev_sco'; @@ -233,6 +237,15 @@ export class AddonModScormProvider { } } + if (scorm.forcenewattempt == AddonModScormProvider.SCORM_FORCEATTEMPT_ALWAYS) { + // This SCORM is configured to force a new attempt on every re-entry. + return { + mode: AddonModScormProvider.MODENORMAL, + attempt: attempt + 1, + newAttempt: true + }; + } + // Validate user request to start a new attempt. if (attempt == 0) { newAttempt = true; From 1b139da49c346e5160f583b32c69f5cc5e507fb1 Mon Sep 17 00:00:00 2001 From: dpalou Date: Wed, 26 Sep 2018 16:44:20 +0200 Subject: [PATCH 2/2] MOBILE-2600 scorm: Use first incomplete SCO when continuing --- src/addon/mod/scorm/providers/helper.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/addon/mod/scorm/providers/helper.ts b/src/addon/mod/scorm/providers/helper.ts index 721148e85..95dd3c31b 100644 --- a/src/addon/mod/scorm/providers/helper.ts +++ b/src/addon/mod/scorm/providers/helper.ts @@ -193,12 +193,11 @@ export class AddonModScormHelperProvider { } /** - * Get the first SCO to load in a SCORM. If a non-empty TOC is provided, it will be the first valid SCO in the TOC. - * Otherwise, it will be the first valid SCO returned by $mmaModScorm#getScos. + * Get the first SCO to load in a SCORM: the first valid and incomplete SCO. * * @param {number} scormId Scorm ID. * @param {number} attempt Attempt number. - * @param {any[]} [toc] SCORM's TOC. + * @param {any[]} [toc] SCORM's TOC. If not provided, it will be calculated. * @param {string} [organization] Organization to use. * @param {boolean} [offline] Whether the attempt is offline. * @param {string} [siteId] Site ID. If not defined, current site. @@ -220,7 +219,8 @@ export class AddonModScormHelperProvider { for (let i = 0; i < scos.length; i++) { const sco = scos[i]; - if (sco.isvisible && sco.prereq && sco.launch) { + // Return the first valid and incomplete SCO. + if (sco.isvisible && sco.prereq && sco.launch && this.scormProvider.isStatusIncomplete(sco.status)) { return sco; } }