/// <summary> /// Populates the languages recursive. /// </summary> /// <param name="folderId">The folder id.</param> private void PopulateLanguagesRecursive(int folderId) { Guid siteId = Guid.Empty; DataTable item = FileTreeItem.GetItemByIdDT(folderId); // We only care about pages if (item != null && item.Rows.Count > 0) { if ((bool)item.Rows[0]["IsFolder"]) { DataTable childItems = FileTreeItem.LoadItemByFolderIdDT(folderId); foreach (DataRow childItem in childItems.Rows) { PopulateLanguagesRecursive((int)childItem["PageId"]); } } } siteId = (Guid)item.Rows[0]["SiteId"]; PageDocument pageDocument = null; //GET PUBLISHED VERSION int statusId = WorkflowStatus.GetLast(); DataTable versionsTable = PageVersion.GetVersionByStatusIdDT(folderId, statusId); // Find page document int templateId = 0; int stateId = 0; int langId = 0; if (versionsTable != null && versionsTable.Rows.Count > 0) { foreach (DataRow versionRow in versionsTable.Rows) { int versionId = 0; int.TryParse(versionRow["VersionId"].ToString(), out versionId); templateId = Int32.Parse(versionRow["templateid"].ToString()); PageDocument.PersistentDocumentStorage = new SqlPageDocumentStorageProvider(); pageDocument = PageDocument.Open(versionId, OpenMode.View, Guid.Empty); stateId = Int32.Parse(versionRow["stateid"].ToString()); langId = Int32.Parse(versionRow["LangId"].ToString()); // Found a non empty page document if (pageDocument != null) { break; } } } // Get list of languages SiteDto siteDto = SiteManager.GetSite(siteId); foreach (SiteDto.SiteLanguageRow langRow in siteDto.SiteLanguage) { IDataReader reader = Language.GetLangByName(langRow.LanguageCode); if (reader.Read()) { int currentLangId = (int)reader["LangId"]; // We skip the default page document language if (currentLangId == langId) { reader.Close(); continue; } // If we already have a specified language define, skip it IDataReader versionReader = PageVersion.GetVersionByLangId(folderId, langId); if (!versionReader.Read()) { versionReader.Close(); continue; } int versionId = PageVersion.AddPageVersion(folderId, templateId, currentLangId, ProfileContext.Current.UserId, stateId, String.Empty); PageDocument.PersistentDocumentStorage = new SqlPageDocumentStorageProvider(); PageDocument.PersistentDocumentStorage.Save(pageDocument, versionId, ProfileContext.Current.UserId); versionReader.Close(); } reader.Close(); } }
/// <summary> /// Creates the menu. /// </summary> /// <param name="langName">Name of the lang.</param> /// <param name="langId">The lang id.</param> private void CreateMenu(string langName, int langId) { //create menu TableCell cellMenu = new TableCell(); cellMenu.Style.Add("border-left", "solid 1px silver"); cellMenu.Style.Add("width", "12px"); System.Web.UI.WebControls.Menu menuLang = new System.Web.UI.WebControls.Menu(); //set style menuLang.StaticMenuItemStyle.CssClass = menuPattern.StaticMenuItemStyle.CssClass; menuLang.DynamicMenuStyle.CssClass = menuPattern.DynamicMenuStyle.CssClass; //set templates menuLang.DynamicItemTemplate = menuPattern.DynamicItemTemplate; //disable default popup image menuLang.StaticEnableDefaultPopOutImage = false; //set orientation menuLang.Orientation = Orientation.Horizontal; System.Web.UI.WebControls.MenuItem root = new System.Web.UI.WebControls.MenuItem(); root.Selectable = false; menuLang.Items.Add(root); //add other version //get archive status id int archiveStatusId = WorkflowStatus.GetArcStatus(0); //get allowed statusId ArrayList allowedStatusId = WorkflowAccess.LoadListByRoleId(ProfileContext.Current.User.ProviderUserKey.ToString()); using (IDataReader reader = PageVersion.GetVersionByLangId(PageId, langId)) { while (reader.Read()) { int statusId = (int)reader["StatusId"]; string statusName = string.Empty; using (IDataReader status = WorkflowStatus.LoadById(statusId)) { if (status.Read()) { if (statusId != archiveStatusId && allowedStatusId.Contains(statusId)) { statusName = status["FriendlyName"].ToString(); } } status.Close(); } //add user draft Guid UserKey = (Guid)ProfileContext.Current.User.ProviderUserKey; Guid OwnerKey = new Guid(reader["EditorUID"].ToString()); if (statusId == WorkflowStatus.DraftId && UserKey == OwnerKey) { statusName = "draft"; } if (statusName != string.Empty) { System.Web.UI.WebControls.MenuItem newItem = new System.Web.UI.WebControls.MenuItem(); newItem.Text = "Version #" + reader["VersionId"] + "(" + statusName + ")"; NameValueCollection vals = new NameValueCollection(); vals.Add("lang", langName); vals.Add("VersionId", reader["VersionId"].ToString()); newItem.NavigateUrl = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals); /* * newItem.NavigateUrl = "~" + PageOutline + "?VersionId=" + reader["VersionId"].ToString() + * "&UserId=" + Membership.GetUser().ProviderUserKey.ToString() + * "&lang=" + langName; * */ root.ChildItems.Add(newItem); } } reader.Close(); } if (root.ChildItems.Count > 0) { //add menu to cell cellMenu.Controls.Add(menuLang); //add cell to row trLanguageMenu.Cells.Add(cellMenu); } }
/// <summary> /// Creates the menu. /// </summary> /// <param name="langId">The lang id.</param> private void CreateMenu(int langId) { //create menu TableCell cellMenu = new TableCell(); //cellMenu.Style.Add("border-left", "solid 1px silver"); cellMenu.Style.Add("width", "12px"); System.Web.UI.WebControls.Menu menuLang = new System.Web.UI.WebControls.Menu(); //set style menuLang.StaticMenuItemStyle.CssClass = menuPattern.StaticMenuItemStyle.CssClass; menuLang.DynamicMenuStyle.CssClass = menuPattern.DynamicMenuStyle.CssClass; //set templates //menuLang.StaticItemTemplate = menuPattern.StaticItemTemplate; menuLang.DynamicItemTemplate = menuPattern.DynamicItemTemplate; //disable default popup image menuLang.StaticEnableDefaultPopOutImage = false; //set orientation menuLang.Orientation = Orientation.Horizontal; System.Web.UI.WebControls.MenuItem root = new System.Web.UI.WebControls.MenuItem(); root.Selectable = false; menuLang.Items.Add(root); //add other version //get archive status id int archiveStatusId = WorkflowStatus.GetArcStatus(0); //get allowed statusId ArrayList allowedStatusId = WorkflowAccess.LoadListByRoleId(Membership.GetUser().ProviderUserKey.ToString()); using (IDataReader reader = PageVersion.GetVersionByLangId(PageId, langId)) { while (reader.Read()) { int statusId = (int)reader["StatusId"]; string statusName = string.Empty; using (IDataReader status = WorkflowStatus.LoadById(statusId)) { if (status.Read()) { if (statusId != archiveStatusId && allowedStatusId.Contains(statusId)) { statusName = status["FriendlyName"].ToString(); } } status.Close(); } //add user draft Guid UserKey = (Guid)Membership.GetUser().ProviderUserKey; Guid OwnerKey = new Guid(reader["EditorUID"].ToString()); if (statusId == WorkflowStatus.DraftId && UserKey == OwnerKey) { statusName = "draft"; } //TODO: for refactoring if (statusName != string.Empty) { System.Web.UI.WebControls.MenuItem newItem = new System.Web.UI.WebControls.MenuItem(); newItem.Text = "Version #" + reader["VersionId"] + "(" + statusName + ")"; newItem.Target = "_blank"; newItem.NavigateUrl = "http://" + Mediachase.Cms.GlobalVariable.GetVariable("url", SiteId) + PageOutline + "?VersionId=" + reader["VersionId"].ToString() + "&UserId=" + Membership.GetUser().ProviderUserKey.ToString(); root.ChildItems.Add(newItem); } } reader.Close(); } if (root.ChildItems.Count > 0) { //add menu to cell cellMenu.Controls.Add(menuLang); } //add cell to row trLanguageMenu.Cells.Add(cellMenu); }