@@ -22,7 +22,7 @@ angular.module('mm.addons.mod_data')
2222 * @name $mmaModDataHelper
2323 */
2424. factory ( '$mmaModDataHelper' , function ( $mmaModData , $mmaModDataFieldsDelegate , $q , mmaModDataComponent , $mmFileUploader , $mmSite ,
25- $mmaModDataOffline , $mmFS , $mmFileUploaderHelper ) {
25+ $mmaModDataOffline , $mmFS , $mmFileUploaderHelper , $mmSitesManager ) {
2626
2727 var self = {
2828 searchOther : {
@@ -660,6 +660,48 @@ angular.module('mm.addons.mod_data')
660660 } ) ;
661661 } ;
662662
663+ /**
664+ * Get an online or offline entry.
665+ *
666+ * @module mm.addons.mod_data
667+ * @ngdoc method
668+ * @name $mmaModDataHelper#getEntry
669+ * @param {Object } data Database.
670+ * @param {Number } entryId Entry ID.
671+ * @param {Object } [offlineActions] Offline data with the actions done. Required for offline entries.
672+ * @param {String } [siteId] Site ID. If not defined, current site.
673+ * @return {Promise } Promise resolved with the entry.
674+ */
675+ self . getEntry = function ( data , entryId , offlineActions , siteId ) {
676+ if ( entryId > 0 ) {
677+ // It's an online entry, get it from WS.
678+ return $mmaModData . getEntry ( data . id , entryId , siteId ) ;
679+ }
680+
681+ // It's an offline entry, search it in the offline actions.
682+ return $mmSitesManager . getSite ( siteId ) . then ( function ( site ) {
683+ for ( var x in offlineActions ) {
684+ if ( offlineActions [ x ] . action == 'add' ) {
685+ var offlineEntry = offlineActions [ x ] ,
686+ siteInfo = site . getInfo ( ) ,
687+ entryData = {
688+ id : offlineEntry . entryid ,
689+ canmanageentry : true ,
690+ approved : ! data . approval || data . manageapproved ,
691+ dataid : offlineEntry . dataid ,
692+ groupid : offlineEntry . groupid ,
693+ timecreated : - offlineEntry . entryid ,
694+ timemodified : - offlineEntry . entryid ,
695+ userid : siteInfo . userid ,
696+ fullname : siteInfo . fullname ,
697+ contents : { }
698+ } ;
699+
700+ return { entry : entryData } ;
701+ }
702+ }
703+ } ) ;
704+ } ;
663705
664706 return self ;
665707} ) ;
0 commit comments