@@ -23,7 +23,8 @@ angular.module('mm.core.course')
2323 */
2424. factory ( '$mmCourseHelper' , function ( $q , $mmCoursePrefetchDelegate , $mmFilepool , $mmUtil , $mmCourse , $mmSite , $state , $mmText ,
2525 mmCoreNotDownloaded , mmCoreOutdated , mmCoreDownloading , mmCoreCourseAllSectionsId , $mmSitesManager , $mmAddonManager ,
26- $controller , $mmCourseDelegate , $translate , $mmEvents , mmCoreEventPackageStatusChanged , mmCoreNotDownloadable ) {
26+ $controller , $mmCourseDelegate , $translate , $mmEvents , mmCoreEventPackageStatusChanged , mmCoreNotDownloadable ,
27+ mmCoreDownloaded ) {
2728
2829 var self = { } ,
2930 calculateSectionStatus = false ;
@@ -243,9 +244,10 @@ angular.module('mm.core.course')
243244 * @param {Object } module Module to get the info from.
244245 * @param {Number } courseid Course ID the section belongs to.
245246 * @param {Number } [invalidateCache=false] Invalidates the cache first.
247+ * @param {String } [component] Component of the module.
246248 * @return {Promise } Promise resolved with the download size, timemodified and module status.
247249 */
248- self . getModulePrefetchInfo = function ( module , courseId , invalidateCache ) {
250+ self . getModulePrefetchInfo = function ( module , courseId , invalidateCache , component ) {
249251
250252 var moduleInfo = {
251253 size : false ,
@@ -255,6 +257,7 @@ angular.module('mm.core.course')
255257 status : false ,
256258 statusIcon : false
257259 } ,
260+ siteId = $mmSite . getId ( ) ,
258261 promises = [ ] ;
259262
260263 if ( typeof invalidateCache != "undefined" && invalidateCache ) {
@@ -298,6 +301,22 @@ angular.module('mm.core.course')
298301 }
299302 } ) ) ;
300303
304+ // Get the time it was downloaded (if it was downloaded).
305+ promises . push ( $mmFilepool . getPackageData ( siteId , component , module . id ) . then ( function ( data ) {
306+ if ( data && data . downloadtime && ( data . status == mmCoreOutdated || data . status == mmCoreDownloaded ) ) {
307+ moduleInfo . downloadtime = data . downloadtime ;
308+ var now = $mmUtil . timestamp ( ) ;
309+ if ( now - data . downloadtime < 7 * 86400 ) {
310+ moduleInfo . downloadtimeReadable = moment ( data . downloadtime * 1000 ) . fromNow ( ) ;
311+ } else {
312+ moduleInfo . downloadtimeReadable = moment ( data . downloadtime * 1000 ) . calendar ( ) ;
313+ }
314+ }
315+ } ) . catch ( function ( ) {
316+ // Not downloaded.
317+ moduleInfo . downloadtime = 0 ;
318+ } ) ) ;
319+
301320 return $q . all ( promises ) . then ( function ( ) {
302321 return moduleInfo ;
303322 } ) ;
@@ -711,14 +730,16 @@ angular.module('mm.core.course')
711730 * @return {Promise } Promise resolved when done.
712731 */
713732 self . fillContextMenu = function ( scope , module , courseId , invalidateCache , component ) {
714- return self . getModulePrefetchInfo ( module , courseId , invalidateCache ) . then ( function ( moduleInfo ) {
733+ return self . getModulePrefetchInfo ( module , courseId , invalidateCache , component ) . then ( function ( moduleInfo ) {
715734 scope . size = moduleInfo . size > 0 ? moduleInfo . sizeReadable : 0 ;
716735 scope . prefetchStatusIcon = moduleInfo . statusIcon ;
717736
718737 if ( moduleInfo . status != mmCoreNotDownloadable ) {
719738 // Module is downloadable, calculate timemodified.
720739 if ( moduleInfo . timemodified > 0 ) {
721740 scope . timemodified = $translate . instant ( 'mm.core.lastmodified' ) + ': ' + moduleInfo . timemodifiedReadable ;
741+ } else if ( moduleInfo . downloadtime > 0 ) {
742+ scope . timemodified = $translate . instant ( 'mm.core.lastdownloaded' ) + ': ' + moduleInfo . downloadtimeReadable ;
722743 } else {
723744 // Cannot calculate time modified, show a default text.
724745 scope . timemodified = $translate . instant ( 'mm.core.download' ) ;
0 commit comments