Skip to content

Commit 55638e8

Browse files
committed
MOBILE-3589 lesson: Support unlimited attempts in question
1 parent 0cf2b3c commit 55638e8

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/addon/mod/lesson/pages/player/player.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,12 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy {
528528
const options = {
529529
password: this.password,
530530
review: this.review,
531-
inludeContents: true,
531+
includeContents: true,
532532
cmId: this.lesson.coursemodule,
533533
readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork,
534534
accessInfo: this.accessInfo,
535535
jumps: this.jumps,
536+
includeOfflineData: true,
536537
};
537538
const args = [this.lesson, pageId, options];
538539

src/addon/mod/lesson/providers/lesson.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ export class AddonModLessonProvider {
15911591
includeContents: true,
15921592
...options, // Include all options.
15931593
readingStrategy: options.readingStrategy || CoreSitesReadingStrategy.PreferCache,
1594+
includeOfflineData: false,
15941595
}).then((data) => {
15951596
return data.answers;
15961597
});
@@ -1660,7 +1661,7 @@ export class AddonModLessonProvider {
16601661
}
16611662

16621663
return site.read('mod_lesson_get_page_data', params, preSets).then((data) => {
1663-
if (preSets.omitExpires && options.accessInfo && data.page) {
1664+
if (preSets.omitExpires && options.includeOfflineData && data.page) {
16641665
// Offline mode and valid page. Calculate the data that might be affected.
16651666
return this.calculateOfflineData(lesson, options).then((calcData) => {
16661667
Object.assign(data, calcData);
@@ -2833,14 +2834,16 @@ export class AddonModLessonProvider {
28332834
attemptSet[attempt.pageid].push(attempt);
28342835
});
28352836

2836-
// Drop all attempts that go beyond max attempts for the lesson.
2837-
for (const pageId in attemptSet) {
2838-
// Sort the list by time in ascending order.
2839-
const attempts = attemptSet[pageId].sort((a, b) => {
2840-
return (a.timeseen || a.timemodified) - (b.timeseen || b.timemodified);
2841-
});
2837+
if (lesson.maxattempts > 0) {
2838+
// Drop all attempts that go beyond max attempts for the lesson.
2839+
for (const pageId in attemptSet) {
2840+
// Sort the list by time in ascending order.
2841+
const attempts = attemptSet[pageId].sort((a, b) => {
2842+
return (a.timeseen || a.timemodified) - (b.timeseen || b.timemodified);
2843+
});
28422844

2843-
attemptSet[pageId] = attempts.slice(0, lesson.maxattempts);
2845+
attemptSet[pageId] = attempts.slice(0, lesson.maxattempts);
2846+
}
28442847
}
28452848

28462849
// Get all the answers from the pages the user answered.
@@ -3113,7 +3116,7 @@ export class AddonModLessonProvider {
31133116
nAttempts = attempts.online.length + attempts.offline.length;
31143117

31153118
// Check if they have reached (or exceeded) the maximum number of attempts allowed.
3116-
if (nAttempts >= lesson.maxattempts) {
3119+
if (lesson.maxattempts > 0 && nAttempts >= lesson.maxattempts) {
31173120
result.maxattemptsreached = true;
31183121
result.feedback = this.translate.instant('addon.mod_lesson.maximumnumberofattemptsreached');
31193122
result.newpageid = AddonModLessonProvider.LESSON_NEXTPAGE;
@@ -3139,12 +3142,12 @@ export class AddonModLessonProvider {
31393142
// Check if "number of attempts remaining" message is needed.
31403143
if (!result.correctanswer && !result.newpageid) {
31413144
// Retreive the number of attempts left counter.
3142-
if (nAttempts >= lesson.maxattempts) {
3145+
if (lesson.maxattempts > 0 && nAttempts >= lesson.maxattempts) {
31433146
if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt.
31443147
result.maxattemptsreached = true;
31453148
}
31463149
result.newpageid = AddonModLessonProvider.LESSON_NEXTPAGE;
3147-
} else if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt
3150+
} else if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt or unlimited.
31483151
result.attemptsremaining = lesson.maxattempts - nAttempts;
31493152
}
31503153
}
@@ -3395,6 +3398,7 @@ export type AddonModLessonCalculateOfflineDataOptions = AddonModLessonCalculateP
33953398
*/
33963399
export type AddonModLessonGetPageDataOptions = AddonModLessonPwdReviewOptions & {
33973400
includeContents?: boolean; // Include the page rendered contents.
3401+
includeOfflineData?: boolean; // Whether to include calculated offline data. Only when ignoring cache.
33983402
accessInfo?: any; // Result of get access info. Required if offline is true.
33993403
jumps?: any; // Result of get pages possible jumps. Required if offline is true.
34003404
};

src/addon/mod/lesson/providers/prefetch-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ export class AddonModLessonPrefetchHandler extends CoreCourseActivityPrefetchHan
361361
// Get the page data. We don't pass accessInfo because we don't need to calculate the offline data.
362362
subPromises.push(this.lessonProvider.getPageData(lesson, data.page.id, {
363363
includeContents: true,
364+
includeOfflineData: false,
364365
...passwordOptions, // Include all options.
365366
}).then((pageData) => {
366367

0 commit comments

Comments
 (0)