Esempio n. 1
0
        public void CopyTab(int portalId, int fromTabId, int toTabId, bool asReference)
        {
            var modules = new ModuleController();
            TabInfo sourceTab = GetTab(fromTabId, portalId, false);
            TabInfo destinationTab = GetTab(fromTabId, toTabId, false);

            if (sourceTab != null && destinationTab != null)
            {
                modules.CopyModules(sourceTab, destinationTab, asReference);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the localized copy.
        /// </summary>
        /// <param name="originalTab">The original tab.</param>
        /// <param name="locale">The locale.</param>
        /// <param name="clearCache">Clear the cache?</param>
        public void CreateLocalizedCopy(TabInfo originalTab, Locale locale, bool clearCache)
        {
            try
            {
                Logger.TraceFormat("Localizing TabId: {0}, TabPath: {1}, Locale: {2}",originalTab.TabID,originalTab.TabPath,locale.Code);
                var defaultLocale = LocaleController.Instance.GetDefaultLocale(originalTab.PortalID);

                //First Clone the Tab
                TabInfo localizedCopy = originalTab.Clone();
                localizedCopy.TabID = Null.NullInteger;

                //Set Guids and Culture Code
                localizedCopy.UniqueId = Guid.NewGuid();
                localizedCopy.VersionGuid = Guid.NewGuid();
                localizedCopy.LocalizedVersionGuid = Guid.NewGuid();
                localizedCopy.CultureCode = locale.Code;
                localizedCopy.TabName = localizedCopy.TabName + " (" + locale.Code + ")";                    
                if (locale == defaultLocale)
                {
                    originalTab.DefaultLanguageGuid = localizedCopy.UniqueId;
                    UpdateTab(originalTab);
                }
                else
                {
                    localizedCopy.DefaultLanguageGuid = originalTab.UniqueId;                   
                }

                //Copy Permissions from original Tab for Admins only
                var portalCtrl = new PortalController();
                PortalInfo portal = portalCtrl.GetPortal(originalTab.PortalID);
                localizedCopy.TabPermissions.AddRange(
                    originalTab.TabPermissions.Where(p => p.RoleID == portal.AdministratorRoleId));

                //Get the original Tabs Parent
                //check the original whether have parent.
                if (!Null.IsNull(originalTab.ParentId))
                {
                    TabInfo originalParent = GetTab(originalTab.ParentId, originalTab.PortalID, false);

                    if (originalParent != null)
                    {
                        //Get the localized parent
                        TabInfo localizedParent = GetTabByCulture(originalParent.TabID, originalParent.PortalID, locale);

                        localizedCopy.ParentId = localizedParent.TabID;
                    }
                }

                //Save Tab
                AddTabInternal(localizedCopy, -1, -1, true);

                //Make shallow copies of all modules
                var moduleCtrl = new ModuleController();
                moduleCtrl.CopyModules(originalTab, localizedCopy, true);

                //Convert these shallow copies to deep copies
                foreach (KeyValuePair<int, ModuleInfo> kvp in moduleCtrl.GetTabModules(localizedCopy.TabID))
                {
                    moduleCtrl.LocalizeModule(kvp.Value, locale);
                }

                //Add Translator Role
                GiveTranslatorRoleEditRights(localizedCopy, null);
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                throw;
            }

            //Clear the Cache
            if (clearCache)
                ClearCache(originalTab.PortalID);
        }