Merge pull request #2598 from dpalou/MOBILE-3589

MOBILE-3589 lesson: Support unlimited attempts in question
main
Juan Leyva 2020-11-10 15:59:15 +01:00 committed by GitHub
commit 585fcebca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 12 deletions

View File

@ -528,11 +528,12 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy {
const options = { const options = {
password: this.password, password: this.password,
review: this.review, review: this.review,
inludeContents: true, includeContents: true,
cmId: this.lesson.coursemodule, cmId: this.lesson.coursemodule,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork, readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork,
accessInfo: this.accessInfo, accessInfo: this.accessInfo,
jumps: this.jumps, jumps: this.jumps,
includeOfflineData: true,
}; };
const args = [this.lesson, pageId, options]; const args = [this.lesson, pageId, options];

View File

@ -1591,6 +1591,7 @@ export class AddonModLessonProvider {
includeContents: true, includeContents: true,
...options, // Include all options. ...options, // Include all options.
readingStrategy: options.readingStrategy || CoreSitesReadingStrategy.PreferCache, readingStrategy: options.readingStrategy || CoreSitesReadingStrategy.PreferCache,
includeOfflineData: false,
}).then((data) => { }).then((data) => {
return data.answers; return data.answers;
}); });
@ -1660,7 +1661,7 @@ export class AddonModLessonProvider {
} }
return site.read('mod_lesson_get_page_data', params, preSets).then((data) => { return site.read('mod_lesson_get_page_data', params, preSets).then((data) => {
if (preSets.omitExpires && options.accessInfo && data.page) { if (preSets.omitExpires && options.includeOfflineData && data.page) {
// Offline mode and valid page. Calculate the data that might be affected. // Offline mode and valid page. Calculate the data that might be affected.
return this.calculateOfflineData(lesson, options).then((calcData) => { return this.calculateOfflineData(lesson, options).then((calcData) => {
Object.assign(data, calcData); Object.assign(data, calcData);
@ -2833,6 +2834,7 @@ export class AddonModLessonProvider {
attemptSet[attempt.pageid].push(attempt); attemptSet[attempt.pageid].push(attempt);
}); });
if (lesson.maxattempts > 0) {
// Drop all attempts that go beyond max attempts for the lesson. // Drop all attempts that go beyond max attempts for the lesson.
for (const pageId in attemptSet) { for (const pageId in attemptSet) {
// Sort the list by time in ascending order. // Sort the list by time in ascending order.
@ -2842,6 +2844,7 @@ export class AddonModLessonProvider {
attemptSet[pageId] = attempts.slice(0, lesson.maxattempts); attemptSet[pageId] = attempts.slice(0, lesson.maxattempts);
} }
}
// Get all the answers from the pages the user answered. // Get all the answers from the pages the user answered.
return this.getPagesAnswers(lesson, pageIds, options); return this.getPagesAnswers(lesson, pageIds, options);
@ -3113,7 +3116,7 @@ export class AddonModLessonProvider {
nAttempts = attempts.online.length + attempts.offline.length; nAttempts = attempts.online.length + attempts.offline.length;
// Check if they have reached (or exceeded) the maximum number of attempts allowed. // Check if they have reached (or exceeded) the maximum number of attempts allowed.
if (nAttempts >= lesson.maxattempts) { if (lesson.maxattempts > 0 && nAttempts >= lesson.maxattempts) {
result.maxattemptsreached = true; result.maxattemptsreached = true;
result.feedback = this.translate.instant('addon.mod_lesson.maximumnumberofattemptsreached'); result.feedback = this.translate.instant('addon.mod_lesson.maximumnumberofattemptsreached');
result.newpageid = AddonModLessonProvider.LESSON_NEXTPAGE; result.newpageid = AddonModLessonProvider.LESSON_NEXTPAGE;
@ -3139,12 +3142,12 @@ export class AddonModLessonProvider {
// Check if "number of attempts remaining" message is needed. // Check if "number of attempts remaining" message is needed.
if (!result.correctanswer && !result.newpageid) { if (!result.correctanswer && !result.newpageid) {
// Retreive the number of attempts left counter. // Retreive the number of attempts left counter.
if (nAttempts >= lesson.maxattempts) { if (lesson.maxattempts > 0 && nAttempts >= lesson.maxattempts) {
if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt. if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt.
result.maxattemptsreached = true; result.maxattemptsreached = true;
} }
result.newpageid = AddonModLessonProvider.LESSON_NEXTPAGE; result.newpageid = AddonModLessonProvider.LESSON_NEXTPAGE;
} else if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt } else if (lesson.maxattempts > 1) { // Don't bother with message if only one attempt or unlimited.
result.attemptsremaining = lesson.maxattempts - nAttempts; result.attemptsremaining = lesson.maxattempts - nAttempts;
} }
} }
@ -3395,6 +3398,7 @@ export type AddonModLessonCalculateOfflineDataOptions = AddonModLessonCalculateP
*/ */
export type AddonModLessonGetPageDataOptions = AddonModLessonPwdReviewOptions & { export type AddonModLessonGetPageDataOptions = AddonModLessonPwdReviewOptions & {
includeContents?: boolean; // Include the page rendered contents. includeContents?: boolean; // Include the page rendered contents.
includeOfflineData?: boolean; // Whether to include calculated offline data. Only when ignoring cache.
accessInfo?: any; // Result of get access info. Required if offline is true. accessInfo?: any; // Result of get access info. Required if offline is true.
jumps?: any; // Result of get pages possible jumps. Required if offline is true. jumps?: any; // Result of get pages possible jumps. Required if offline is true.
}; };

View File

@ -361,6 +361,7 @@ export class AddonModLessonPrefetchHandler extends CoreCourseActivityPrefetchHan
// Get the page data. We don't pass accessInfo because we don't need to calculate the offline data. // Get the page data. We don't pass accessInfo because we don't need to calculate the offline data.
subPromises.push(this.lessonProvider.getPageData(lesson, data.page.id, { subPromises.push(this.lessonProvider.getPageData(lesson, data.page.id, {
includeContents: true, includeContents: true,
includeOfflineData: false,
...passwordOptions, // Include all options. ...passwordOptions, // Include all options.
}).then((pageData) => { }).then((pageData) => {