@@ -21,7 +21,7 @@ angular.module('mm.addons.mod_scorm')
2121 * @ngdoc service
2222 * @name $mmCourseHelper
2323 */
24- . factory ( '$mmaModScormHelper' , function ( $mmaModScorm , $mmUtil , $translate , $q , $mmaModScormOffline , $mmaModScormSync ) {
24+ . factory ( '$mmaModScormHelper' , function ( $mmaModScorm , $mmUtil , $translate , $q , $mmaModScormOffline , $mmaModScormSync , $mmSite ) {
2525
2626 var self = { } ,
2727 elementsToIgnore = [ 'status' , 'score_raw' , 'total_time' , 'session_time' , 'student_id' , 'student_name' , 'credit' ,
@@ -54,14 +54,17 @@ angular.module('mm.addons.mod_scorm')
5454 * @name $mmaModScormHelper#convertAttemptToOffline
5555 * @param {Object } scorm SCORM.
5656 * @param {Number } attempt Number of the online attempt.
57+ * @param {String } [siteId] Site ID. If not defined, current site.
5758 * @return {Promise } Promise resolved when the attempt is created.
5859 */
59- self . convertAttemptToOffline = function ( scorm , attempt ) {
60+ self . convertAttemptToOffline = function ( scorm , attempt , siteId ) {
61+ siteId = siteId || $mmSite . getId ( ) ;
62+
6063 // Get data from the online attempt.
61- return $mmaModScorm . getScormUserData ( scorm . id , attempt ) . then ( function ( onlineData ) {
64+ return $mmaModScorm . getScormUserData ( scorm . id , attempt , false , siteId ) . then ( function ( onlineData ) {
6265 // The SCORM API might have written some data to the offline attempt already.
6366 // We don't want to override it with cached online data.
64- return $mmaModScormOffline . getScormUserData ( scorm . id , attempt ) . catch ( function ( ) {
67+ return $mmaModScormOffline . getScormUserData ( siteId , scorm . id , attempt ) . catch ( function ( ) {
6568 // Ignore errors.
6669 } ) . then ( function ( offlineData ) {
6770 var dataToStore = angular . copy ( onlineData ) ;
@@ -85,7 +88,7 @@ angular.module('mm.addons.mod_scorm')
8588 }
8689 } ) ;
8790
88- return $mmaModScormOffline . createNewAttempt ( scorm , undefined , attempt , dataToStore , onlineData ) ;
91+ return $mmaModScormOffline . createNewAttempt ( siteId , scorm , undefined , attempt , dataToStore , onlineData ) ;
8992 } ) ;
9093 } ) . catch ( function ( ) {
9194 // Shouldn't happen.
@@ -102,11 +105,13 @@ angular.module('mm.addons.mod_scorm')
102105 * @param {Object } scorm SCORM.
103106 * @param {Number } newAttempt Number of the new attempt.
104107 * @param {Number } lastOnline Number of the last online attempt.
108+ * @param {String } [siteId] Site ID. If not defined, current site.
105109 * @return {Promise } Promise resolved when the attempt is created.
106110 */
107- self . createOfflineAttempt = function ( scorm , newAttempt , lastOnline ) {
111+ self . createOfflineAttempt = function ( scorm , newAttempt , lastOnline , siteId ) {
112+ siteId = siteId || $mmSite . getId ( ) ;
108113 // Try to get data from online attempts.
109- return self . searchOnlineAttemptUserData ( scorm . id , lastOnline ) . then ( function ( userData ) {
114+ return self . searchOnlineAttemptUserData ( scorm . id , lastOnline , siteId ) . then ( function ( userData ) {
110115 // We're creating a new attempt, remove all the user data that is not needed for a new attempt.
111116 // We need to get the SCO data from here because WS get_scoes doesn't return sco_data in Moodle 3.0.
112117 angular . forEach ( userData , function ( sco ) {
@@ -119,7 +124,7 @@ angular.module('mm.addons.mod_scorm')
119124 } ) ;
120125 sco . userdata = filtered ;
121126 } ) ;
122- return $mmaModScormOffline . createNewAttempt ( scorm , undefined , newAttempt , userData ) ;
127+ return $mmaModScormOffline . createNewAttempt ( siteId , scorm , undefined , newAttempt , userData ) ;
123128 } ) . catch ( function ( ) {
124129 return $q . reject ( $translate . instant ( 'mma.mod_scorm.errorcreateofflineattempt' ) ) ;
125130 } ) ;
@@ -162,9 +167,11 @@ angular.module('mm.addons.mod_scorm')
162167 * @name $mmaModScormHelper#determineAttemptToContinue
163168 * @param {Object } scorm SCORM.
164169 * @param {Object } attempts Result of $mmaModScorm#getAttemptCount.
170+ * @param {String } [siteId] Site ID. If not defined, current site.
165171 * @return {Promise } Promise resolved with an object with 2 properties: 'number' and 'offline'.
166172 */
167- self . determineAttemptToContinue = function ( scorm , attempts ) {
173+ self . determineAttemptToContinue = function ( scorm , attempts , siteId ) {
174+ siteId = siteId || $mmSite . getId ( ) ;
168175 var lastOnline ,
169176 result = {
170177 number : 0 ,
@@ -190,7 +197,7 @@ angular.module('mm.addons.mod_scorm')
190197 if ( lastOnline ) {
191198 // Check if last online incomplete.
192199 var hasOffline = attempts . offline . indexOf ( lastOnline ) > - 1 ;
193- return $mmaModScorm . isAttemptIncomplete ( scorm . id , lastOnline , hasOffline ) . then ( function ( incomplete ) {
200+ return $mmaModScorm . isAttemptIncomplete ( scorm . id , lastOnline , hasOffline , false , siteId ) . then ( function ( incomplete ) {
194201 if ( incomplete ) {
195202 result . number = lastOnline ;
196203 result . offline = hasOffline ;
@@ -212,20 +219,22 @@ angular.module('mm.addons.mod_scorm')
212219 * @module mm.addons.mod_scorm
213220 * @ngdoc method
214221 * @name $mmaModScormHelper#getFirstSco
215- * @param {String } scormid Scorm ID.
222+ * @param {String } scormId Scorm ID.
216223 * @param {Object[] } [toc] SCORM's TOC.
217224 * @param {String } [organization] Organization to use.
218225 * @param {Number } attempt Attempt number.
219226 * @param {Boolean } offline True if attempt is offline, false otherwise.
227+ * @param {String } [siteId] Site ID. If not defined, current site.
220228 * @return {Promise } Promise resolved with the first SCO.
221229 */
222- self . getFirstSco = function ( scormid , toc , organization , attempt , offline ) {
230+ self . getFirstSco = function ( scormId , toc , organization , attempt , offline , siteId ) {
231+ siteId = siteId || $mmSite . getId ( ) ;
223232 var promise ;
224233 if ( toc && toc . length ) {
225234 promise = $q . when ( toc ) ;
226235 } else {
227236 // SCORM doesn't have a TOC. Get all the scos.
228- promise = $mmaModScorm . getScosWithData ( scormid , organization , attempt , offline ) ;
237+ promise = $mmaModScorm . getScosWithData ( scormId , organization , attempt , offline , false , siteId ) ;
229238 }
230239
231240 return promise . then ( function ( scos ) {
@@ -312,10 +321,11 @@ angular.module('mm.addons.mod_scorm')
312321 * @ngdoc method
313322 * @name $mmaModScormHelper#getScormReadableSyncTime
314323 * @param {Number } scormId SCORM ID.
324+ * @param {String } [siteId] Site ID. If not defined, current site.
315325 * @return {Promise } Promise resolved with the readable time.
316326 */
317- self . getScormReadableSyncTime = function ( scormId ) {
318- return $mmaModScormSync . getScormSyncTime ( scormId ) . then ( function ( time ) {
327+ self . getScormReadableSyncTime = function ( scormId , siteId ) {
328+ return $mmaModScormSync . getScormSyncTime ( scormId , siteId ) . then ( function ( time ) {
319329 if ( time == 0 ) {
320330 return $translate ( 'mm.core.none' ) ;
321331 } else {
@@ -331,15 +341,17 @@ angular.module('mm.addons.mod_scorm')
331341 * @module mm.addons.mod_scorm
332342 * @ngdoc method
333343 * @name $mmaModScormHelper#searchOnlineAttemptUserData
334- * @param {Number } scormId SCORM ID.
335- * @param {Number } attempt Online attempt to get the data.
336- * @return {Promise } Promise resolved with user data.
344+ * @param {Number } scormId SCORM ID.
345+ * @param {Number } attempt Online attempt to get the data.
346+ * @param {String } [siteId] Site ID. If not defined, current site.
347+ * @return {Promise } Promise resolved with user data.
337348 */
338- self . searchOnlineAttemptUserData = function ( scormId , attempt ) {
339- return $mmaModScorm . getScormUserData ( scormId , attempt ) . catch ( function ( ) {
349+ self . searchOnlineAttemptUserData = function ( scormId , attempt , siteId ) {
350+ siteId = siteId || $mmSite . getId ( ) ;
351+ return $mmaModScorm . getScormUserData ( scormId , attempt , false , siteId ) . catch ( function ( ) {
340352 if ( attempt > 0 ) {
341353 // We couldn't retrieve the data. Try again with the previous online attempt.
342- return self . searchOnlineAttemptUserData ( scormId , attempt - 1 ) ;
354+ return self . searchOnlineAttemptUserData ( scormId , attempt - 1 , siteId ) ;
343355 } else {
344356 // No more attempts to try. Reject
345357 return $q . reject ( ) ;
0 commit comments