@@ -69,16 +69,7 @@ angular.module('mm.addons.mod_quiz')
6969 * @return {Number } Promise resolved with revision.
7070 */
7171 self . getRevision = function ( module , courseId ) {
72- var promise ;
73- if ( module . instance ) {
74- promise = $q . when ( module . instance ) ;
75- } else {
76- promise = $mmaModQuiz . getQuiz ( courseId , module . id ) . then ( function ( quiz ) {
77- return quiz . id ;
78- } ) ;
79- }
80-
81- return promise . then ( function ( quizId ) {
72+ return $mmaModQuiz . getQuizIdFromModule ( module , courseId ) . then ( function ( quizId ) {
8273 return $mmaModQuiz . getUserAttempts ( quizId ) . then ( function ( attempts ) {
8374 return $mmaModQuiz . getQuizRevisionFromAttempts ( attempts ) ;
8475 } ) ;
@@ -96,16 +87,7 @@ angular.module('mm.addons.mod_quiz')
9687 * @return {Promise } Promise resolved with timemodified.
9788 */
9889 self . getTimemodified = function ( module , courseId ) {
99- var promise ;
100- if ( module . instance ) {
101- promise = $q . when ( module . instance ) ;
102- } else {
103- promise = $mmaModQuiz . getQuiz ( courseId , module . id ) . then ( function ( quiz ) {
104- return quiz . id ;
105- } ) ;
106- }
107-
108- return promise . then ( function ( quizId ) {
90+ return $mmaModQuiz . getQuizIdFromModule ( module , courseId ) . then ( function ( quizId ) {
10991 return $mmaModQuiz . getUserAttempts ( quizId ) . then ( function ( attempts ) {
11092 return $mmaModQuiz . getQuizTimemodifiedFromAttempts ( attempts ) ;
11193 } ) ;
@@ -124,7 +106,15 @@ angular.module('mm.addons.mod_quiz')
124106 */
125107 self . isDownloadable = function ( module , courseId ) {
126108 return $mmaModQuiz . getQuiz ( courseId , module . id ) . then ( function ( quiz ) {
127- return quiz . allowofflineattempts === 1 ;
109+ if ( quiz . allowofflineattempts !== 1 || quiz . hasquestions === 0 ) {
110+ return false ;
111+ }
112+
113+ // Not downloadable if we reached max attempts.
114+ return $mmaModQuiz . getUserAttempts ( quiz . id ) . then ( function ( attempts ) {
115+ var isLastFinished = ! attempts . length || $mmaModQuiz . isAttemptFinished ( attempts [ attempts . length - 1 ] . state ) ;
116+ return quiz . attempts === 0 || quiz . attempts > attempts . length || ! isLastFinished ;
117+ } ) ;
128118 } ) ;
129119 } ;
130120
0 commit comments