@@ -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 */
33963399export 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} ;
0 commit comments