public static string GetObjectPostTypeText(ObjectPostTypes objectPostTypeValue) { // Get description of the type from system strings string systemStringName = "Extensions_OP_Type_" + (short) objectPostTypeValue; string objectPostTypesTranslation = Solution.Instance.SystemStrings.GetValue(systemStringName, FoundationContext.Current.Culture, true); if (string.IsNullOrEmpty(objectPostTypesTranslation)) { objectPostTypesTranslation = objectPostTypeValue + string.Format(" (Create a systemstring named {0} to set type name)", systemStringName); } return objectPostTypesTranslation; }
/// <summary> /// Returns number of reports for a ObjectPostType /// </summary> /// <param name="objectPostType">Type of the object post.</param> /// <returns>number of reports for a ObjectPostType</returns> public static int GetReportsForObjectPostType(ObjectPostTypes objectPostType) { List<Litium.Extensions.ObjectPost.ObjectPost> objectPosts = Litium.Extensions.Extensions.Instance.ObjectPosts.GetObjectPostByType((short) objectPostType); int reports = 0; foreach (Litium.Extensions.ObjectPost.ObjectPost objectPost in objectPosts) { reports += objectPost.Reports.All.Count; } return reports; }
/// <summary> /// Gets the hyper link for object post object. /// </summary> /// <param name="objectPostId">The object post id</param> /// <param name="objectPostType">Type of the object post.</param> /// <param name="webSiteID">The web site ID.</param> /// <returns></returns> public static string GetHyperLinkForObjectPostObject(Guid objectPostId, ObjectPostTypes objectPostType) { Litium.Extensions.ObjectPost.ObjectPost objectPost = Litium.Extensions.Extensions.Instance.ObjectPosts.GetObjectPost(objectPostId); if (objectPost == null) return string.Empty; switch (objectPostType) { case ObjectPostTypes.CMS_PAGE: return GetHyperLinkForPage(objectPost.ObjectID); case ObjectPostTypes.PRODUCTCATALOG_PRODUCT: return GetHyperLinkForProduct(objectPost.ObjectID, objectPost.WebSiteID); // NOTE: I extensions för 4.4.3 finns websiteid på objectPost objectet. default: return string.Empty; } }
/// <summary> /// Inits dropdownlist with ObjectPostTypes and number of posts for web site. Sorts ascending on text /// Use Guid.Empty for web site id to get number of post for all websites. /// </summary> public static void InitDropDownObjectPostTypesAllPosts(ObjectPostTypes selectedObjectPostType, DropDownList dropDownList, Guid webSiteID) { List<ListItem> listItems = new List<ListItem>(); string selectedObjectPostTypeValue = ((short) selectedObjectPostType).ToString(); foreach (int objectPostTypeValue in Enum.GetValues(typeof (ObjectPostTypes))) { List<Litium.Extensions.ObjectPost.ObjectPost> objectPosts; if(webSiteID != Guid.Empty) objectPosts = Litium.Extensions.Extensions.Instance.ObjectPosts.GetObjectPostByWebSiteAndType(webSiteID, (short)objectPostTypeValue); else objectPosts = Litium.Extensions.Extensions.Instance.ObjectPosts.GetObjectPostByType((short)objectPostTypeValue); string posts = " (" + objectPosts.Count + ")"; string objectPostTypesTranslation = GetObjectPostTypeText((ObjectPostTypes) objectPostTypeValue); ListItem listItem = new ListItem(objectPostTypesTranslation + posts, objectPostTypeValue.ToString()); if (listItem.Value == selectedObjectPostTypeValue) { listItem.Selected = true; } listItems.Add(listItem); } listItems.Sort(GenericListListItemComparer.TextAscendingComparison); dropDownList.Items.Clear(); dropDownList.Items.AddRange(listItems.ToArray()); }
/// <summary> /// Inits dropdownlist with ObjectPostTypes and number of reports. Includes only ObjectPostTypes that has reported ObjectPosts. Sorts ascending on text /// </summary> public static void InitDropDownObjectPostTypes(ObjectPostTypes selectedObjectPostType, DropDownList dropDownList) { List<ListItem> listItems = new List<ListItem>(); string selectedObjectPostTypeValue = ((short) selectedObjectPostType).ToString(); foreach (int objectPostTypeValue in Enum.GetValues(typeof (ObjectPostTypes))) { string reports = " (" + GetReportsForObjectPostType((ObjectPostTypes) objectPostTypeValue) + ")"; string objectPostTypesTranslation = GetObjectPostTypeText((ObjectPostTypes) objectPostTypeValue); ListItem listItem = new ListItem(objectPostTypesTranslation + reports, objectPostTypeValue.ToString()); if (listItem.Value == selectedObjectPostTypeValue) { listItem.Selected = true; } listItems.Add(listItem); } listItems.Sort(GenericListListItemComparer.TextAscendingComparison); dropDownList.Items.Clear(); dropDownList.Items.AddRange(listItems.ToArray()); }