@@ -23,7 +23,7 @@ angular.module('mm.addons.mod_quiz')
2323 */
2424. factory ( '$mmaModQuiz' , function ( $log , $mmSite , $mmSitesManager , $q , $translate , $mmUtil , $mmText , $mmQuestionDelegate ,
2525 $mmaModQuizAccessRulesDelegate , $mmQuestionHelper , $mmFilepool , $mmaModQuizOnline , $mmaModQuizOffline , $state ,
26- mmaModQuizComponent , mmCoreDownloaded , mmCoreDownloading ) {
26+ mmaModQuizComponent , mmCoreDownloaded , mmCoreDownloading , mmCoreNotDownloaded ) {
2727
2828 $log = $log . getInstance ( '$mmaModQuiz' ) ;
2929
@@ -1996,7 +1996,10 @@ angular.module('mm.addons.mod_quiz')
19961996 siteId = siteId || $mmSite . getId ( ) ;
19971997
19981998 var attempts ,
1999- promises = [ ] ;
1999+ promises = [ ] ,
2000+ component = mmaModQuizComponent ,
2001+ revision ,
2002+ timemod ;
20002003
20012004 // Get quiz data.
20022005 promises . push ( self . getQuizAccessInformation ( quiz . id , false , true , siteId ) ) ;
@@ -2019,11 +2022,19 @@ angular.module('mm.addons.mod_quiz')
20192022 return self . prefetchAttempt ( quiz , attempts [ attempts . length - 1 ] , siteId ) ;
20202023 }
20212024 } ) . then ( function ( ) {
2022- // Prefetch finished, mark as downloaded.
2023- var revision = self . getQuizRevisionFromAttempts ( attempts ) ,
2024- timemod = self . getQuizTimemodifiedFromAttempts ( attempts ) ;
2025- return $mmFilepool . storePackageStatus ( siteId , mmaModQuizComponent ,
2026- quiz . coursemodule , mmCoreDownloaded , revision , timemod ) ;
2025+ // Prefetch finished, get current status to determine if we need to change it.
2026+ revision = self . getQuizRevisionFromAttempts ( attempts ) ;
2027+ timemod = self . getQuizTimemodifiedFromAttempts ( attempts ) ;
2028+
2029+ return $mmFilepool . getPackageStatus ( siteId , component , quiz . coursemodule , revision , timemod ) ;
2030+ } ) . then ( function ( status ) {
2031+ if ( status !== mmCoreNotDownloaded ) {
2032+ // Quiz was downloaded, set the new status.
2033+ // If no attempts or last is finished we'll mark it as not downloaded to show download icon.
2034+ var isLastFinished = ! attempts . length || self . isAttemptFinished ( attempts [ attempts . length - 1 ] . state ) ,
2035+ newStatus = isLastFinished ? mmCoreNotDownloaded : mmCoreDownloaded ;
2036+ return $mmFilepool . storePackageStatus ( siteId , component , quiz . coursemodule , newStatus , revision , timemod ) ;
2037+ }
20272038 } ) ;
20282039 } ;
20292040
0 commit comments