/// <summary> /// Sets the current combination as default /// </summary> protected void btnUseCombination_Click(object sender, EventArgs e) { if ((DocumentContext.CurrentPageInfo != null)) { // Keep current page template instance PageInfo pi = DocumentContext.CurrentPageInfo; // Get combination from cookies string combinationName = CookieHelper.GetValue(cookieTestName); // Get the page template id int templateId = GetPageTemplateId(pi); // Get combination info MVTCombinationInfo currentCombination = MVTCombinationInfoProvider.GetMVTCombinationInfo(templateId, combinationName); // Get default combination info MVTCombinationInfo defaultCombination = MVTCombinationInfoProvider.GetDefaultCombinationInfo(templateId); // Check whether default and current combination exists if ((currentCombination != null) && (defaultCombination != null)) { // Do not save default combination if (currentCombination.MVTCombinationID != defaultCombination.MVTCombinationID) { // Copy the combination custom name defaultCombination.MVTCombinationCustomName = currentCombination.MVTCombinationCustomName; defaultCombination.Update(); // Tree provider instance TreeProvider tp = new TreeProvider(currentUser); // Documents - use the Preview view mode to ensure that only chosen variant will be rendered (Design mode renders all web part/zone variants and does not combine the instance with the variants) PageTemplateInstance instance = MVTestInfoProvider.CombineWithMVT(pi, pi.UsedPageTemplateInfo.TemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, instance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tp); // Widgets - use the Preview view mode to ensure that only chosen variant will be rendered (Edit mode renders all widget variants and does not combine the instance with the variants) instance = MVTestInfoProvider.CombineWithMVT(pi, pi.DocumentTemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, instance, WidgetZoneTypeEnum.Editor, ViewModeEnum.Edit, tp); } // Remove all variants var variants = MVTVariantInfoProvider.GetMVTVariants().WhereEquals("MVTVariantPageTemplateID", templateId); foreach (MVTVariantInfo info in variants) { MVTVariantInfoProvider.DeleteMVTVariantInfo(info); } // Clear cached template info pi.UsedPageTemplateInfo.Update(); // Redirect to the same page to update the current view URLHelper.Redirect(RequestContext.CurrentURL); } } }
/// <summary> /// Sets the current combination as default /// </summary> void btnUseCombination_Click(object sender, EventArgs e) { if ((CMSContext.CurrentPageInfo != null)) { // Keep current page template insatnce PageInfo pi = CMSContext.CurrentPageInfo; // Set the selected combination (from cookie by default) MVTestInfo mvTestInfo = MVTestInfoProvider.GetRunningTest(CMSContext.CurrentAliasPath, CMSContext.CurrentSiteID, CMSContext.CurrentDocumentCulture.CultureCode); // Get combination from cookies string combinationName = CookieHelper.GetValue(cookieTestName); // Get combination info MVTCombinationInfo currentCombination = MVTCombinationInfoProvider.GetMVTCombinationInfo(pi.DocumentPageTemplateID, combinationName); // Get default combination info MVTCombinationInfo defaultCombination = MVTCombinationInfoProvider.GetDefaultCombinationInfo(pi.DocumentPageTemplateID); // Check whether default and current combination exists if ((currentCombination != null) && (defaultCombination != null)) { // Do not save default combination if (currentCombination.MVTCombinationID != defaultCombination.MVTCombinationID) { // Copy the combination custom name defaultCombination.MVTCombinationCustomName = currentCombination.MVTCombinationCustomName; defaultCombination.Update(); // Tree provider instance TreeProvider tp = new TreeProvider(currentUser); // Documents - use the Preview view mode to ensure that only chosen variant will be rendered (Design mode renders all web part/zone variants and does not combine the instance with the variants) PageTemplateInstance instance = MVTestInfoProvider.CombineWithMVT(pi, pi.PageTemplateInfo.TemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, instance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tp); // Widgets - use the Preview view mode to ensure that only chosen variant will be rendered (Edit mode renders all widget variants and does not combine the instance with the variants) instance = MVTestInfoProvider.CombineWithMVT(pi, pi.DocumentTemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview); CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, instance, WidgetZoneTypeEnum.Editor, ViewModeEnum.Edit, tp); } // Remove all variants InfoDataSet <MVTVariantInfo> variants = MVTVariantInfoProvider.GetMVTVariants("MVTVariantPageTemplateID = " + pi.DocumentPageTemplateID, null); if (!DataHelper.DataSourceIsEmpty(variants)) { foreach (MVTVariantInfo info in variants) { MVTVariantInfoProvider.DeleteMVTVariantInfo(info); } } // Clear cached template info pi.PageTemplateInfo.Update(); // Redirect to the same page to update the current view URLHelper.Redirect(URLHelper.CurrentURL); } } }