1515angular . module ( 'mm.addons.mod_quiz' )
1616
1717. constant ( 'mmaModQuizSynchronizationStore' , 'mod_quiz_sync' )
18+ . constant ( 'mmaModQuizSynchronizationWarningsStore' , 'mod_quiz_sync_warnings' )
1819
19- . config ( function ( $mmSitesFactoryProvider , mmaModQuizSynchronizationStore ) {
20+ . config ( function ( $mmSitesFactoryProvider , mmaModQuizSynchronizationStore , mmaModQuizSynchronizationWarningsStore ) {
2021 var stores = [
2122 {
2223 name : mmaModQuizSynchronizationStore ,
2324 keyPath : 'quizid' ,
2425 indexes : [ ]
26+ } ,
27+ {
28+ name : mmaModQuizSynchronizationWarningsStore ,
29+ keyPath : 'quizid' ,
30+ indexes : [ ]
2531 }
2632 ] ;
2733 $mmSitesFactoryProvider . registerStores ( stores ) ;
@@ -36,7 +42,7 @@ angular.module('mm.addons.mod_quiz')
3642 */
3743. factory ( '$mmaModQuizSync' , function ( $log , $mmaModQuiz , $mmSite , $mmSitesManager , $q , $mmaModQuizOffline , $mmQuestion ,
3844 $mmQuestionDelegate , $mmApp , $mmConfig , $mmEvents , $translate , mmaModQuizSynchronizationStore , mmaModQuizSyncTime ,
39- mmaModQuizEventAutomSynced , mmCoreSettingsSyncOnlyOnWifi ) {
45+ mmaModQuizEventAutomSynced , mmCoreSettingsSyncOnlyOnWifi , mmaModQuizSynchronizationWarningsStore ) {
4046
4147 $log = $log . getInstance ( '$mmaModQuizSync' ) ;
4248
@@ -64,6 +70,27 @@ angular.module('mm.addons.mod_quiz')
6470 } ) ;
6571 } ;
6672
73+ /**
74+ * Get the synchronization warnings of a quiz.
75+ *
76+ * @module mm.addons.mod_quiz
77+ * @ngdoc method
78+ * @name $mmaModQuizSync#getQuizSyncTime
79+ * @param {Number } quizId Quiz ID.
80+ * @param {String } [siteId] Site ID. If not defined, current site.
81+ * @return {Promise } Promise resolved with the time.
82+ */
83+ self . getQuizSyncWarnings = function ( quizId , siteId ) {
84+ siteId = siteId || $mmSite . getId ( ) ;
85+ return $mmSitesManager . getSiteDb ( siteId ) . then ( function ( db ) {
86+ return db . get ( mmaModQuizSynchronizationWarningsStore , quizId ) . then ( function ( entry ) {
87+ return entry . warnings ;
88+ } ) . catch ( function ( ) {
89+ return [ ] ;
90+ } ) ;
91+ } ) ;
92+ } ;
93+
6794 /**
6895 * Check if a quiz has data to synchronize.
6996 *
@@ -83,15 +110,15 @@ angular.module('mm.addons.mod_quiz')
83110 } ;
84111
85112 /**
86- * Get the synchronization time of a quiz. Returns 0 if no time stored .
113+ * Set the synchronization time for a quiz.
87114 *
88115 * @module mm.addons.mod_quiz
89116 * @ngdoc method
90117 * @name $mmaModQuizSync#setQuizSyncTime
91118 * @param {Number } quizId Quiz ID.
92119 * @param {String } [siteId] Site ID. If not defined, current site.
93120 * @param {Number } [time] Time to set. If not defined, current time.
94- * @return {Promise } Promise resolved with the time .
121+ * @return {Promise } Promise resolved when done .
95122 */
96123 self . setQuizSyncTime = function ( quizId , siteId , time ) {
97124 siteId = siteId || $mmSite . getId ( ) ;
@@ -103,6 +130,27 @@ angular.module('mm.addons.mod_quiz')
103130 } ) ;
104131 } ;
105132
133+ /**
134+ * Set the synchronization warnings for a quiz.
135+ *
136+ * @module mm.addons.mod_quiz
137+ * @ngdoc method
138+ * @name $mmaModQuizSync#setQuizSyncWarnings
139+ * @param {Number } quizId Quiz ID.
140+ * @param {String[] } warnings Warnings to set.
141+ * @param {String } [siteId] Site ID. If not defined, current site.
142+ * @return {Promise } Promise resolved when done.
143+ */
144+ self . setQuizSyncWarnings = function ( quizId , warnings , siteId ) {
145+ siteId = siteId || $mmSite . getId ( ) ;
146+ return $mmSitesManager . getSiteDb ( siteId ) . then ( function ( db ) {
147+ if ( typeof warnings == 'undefined' ) {
148+ warnings = [ ] ;
149+ }
150+ return db . insert ( mmaModQuizSynchronizationWarningsStore , { quizid : quizId , warnings : warnings } ) ;
151+ } ) ;
152+ } ;
153+
106154 /**
107155 * Try to synchronize all quizzes from current site that need it and haven't been synchronized in a while.
108156 *
@@ -161,6 +209,13 @@ angular.module('mm.addons.mod_quiz')
161209 if ( ! $mmaModQuiz . isQuizBeingPlayed ( quiz . id , siteId ) ) {
162210 promises . push ( $mmaModQuiz . getQuizById ( quiz . courseid , quiz . id , siteId ) . then ( function ( quiz ) {
163211 return self . syncQuizIfNeeded ( quiz , siteId ) . then ( function ( warnings ) {
212+ if ( warnings && warnings . length ) {
213+ // Store the warnings to show them when the user opens the quiz.
214+ return self . setQuizSyncWarnings ( quiz . id , warnings , siteId ) . then ( function ( ) {
215+ return warnings ;
216+ } ) ;
217+ }
218+ } ) . then ( function ( warnings ) {
164219 if ( typeof warnings != 'undefined' ) {
165220 // We tried to sync. Send event.
166221 $mmEvents . trigger ( mmaModQuizEventAutomSynced , {
0 commit comments