Example #1
0
        public static string GetCommaSeperatedTagList(BlogPost blogItem)
        {
            StringBuilder display = new StringBuilder();

            int totalTags = blogItem.Tags.Count;
            int currentCount = 1;

            foreach (Tag tagItem in blogItem.Tags)
            {
                display.Append(String.Format("<a href=\"{0}\">{1}</a>", GetTagUrl(tagItem.TagName, blogItem.InnerItem), tagItem.TagName));
                if (currentCount < totalTags)
                    display.Append(", ");

                currentCount++;
            }

            return display.ToString();
        }
Example #2
0
        public static IList<BlogPost> GetBlogRelatedValues(BlogPost currentItem)
        {
            Dictionary<string, int> blogItems = new Dictionary<string, int>();
            IList<BlogPost> blogList = new List<BlogPost>();

            try
            {
                Item repositorySearchItem = XBlogHelper.General.DataManager.GetBlogHomeItem(currentItem.InnerItem);
                BlogSettings settingsItem = XBlogHelper.General.DataManager.GetBlogSettingsItem(currentItem.InnerItem);

                ISearchIndex index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(repositorySearchItem));

                using (IProviderSearchContext context = index.CreateSearchContext())
                {

                    // look at the pipe seperated list.  break them out and loop through.  Build dictionary based on Ids
                    // create as blog post item
                    // could even pass a max item as a dictionary definition
                    Expression<Func<SearchResultItem, bool>> predicate = PredicateBuilder.True<SearchResultItem>();
                    predicate = predicate.And(item => item.TemplateName == BlogPost.BlogPostTemplate && item.Paths.Contains(repositorySearchItem.ID));

                    IEnumerable<BlogPost> resultList = context.GetQueryable<SearchResultItem>().Where(predicate).OrderBy(t => t.Name).CreateAs<BlogPost>();

                    foreach (BlogPost item in resultList)
                    {
                        if (item.ItemId != currentItem.ItemId)
                        {
                            string itemID = item.ItemId.ToString();
                            blogItems.Add(itemID, 0);
                            foreach (Author author in item.Authors)
                            {
                                foreach (Author currentAuthor in currentItem.Authors)
                                {
                                    if (currentAuthor.ItemId == author.ItemId)
                                    {
                                        blogItems[itemID] = blogItems[itemID] + XBSettings.RelatedAuthorValue;
                                    }
                                }

                            }

                            foreach (Category category in item.Categories)
                            {
                                foreach (Category currenCategory in currentItem.Categories)
                                {
                                    if (currenCategory.ItemId == category.ItemId)
                                    {
                                        blogItems[itemID] = blogItems[itemID] + XBSettings.RelatedCategoryValue;
                                    }
                                }
                            }

                            foreach (Tag tag in item.Tags)
                            {
                                foreach (Tag currentTag in currentItem.Tags)
                                {
                                    if (currentTag.ItemId == tag.ItemId)
                                    {
                                        blogItems[itemID] = blogItems[itemID] + XBSettings.RelatedTagValue;
                                    }
                                }

                            }
                        }

                    }
                }

                // order the count descending then build list based on this order.
                var items = from pair in blogItems
                            orderby pair.Value descending
                            select pair;

                Sitecore.Data.Database current = Sitecore.Context.Database;
                foreach (KeyValuePair<string, int> pair in items)
                {
                    if (Sitecore.Data.ID.IsID(pair.Key))
                    {
                        BlogPost thisItem = current.GetItem(Sitecore.Data.ID.Parse(pair.Key)).CreateAs<BlogPost>();
                        if (!blogList.Contains(thisItem))
                        {
                            blogList.Add(thisItem);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("XBlog GetAuthorCount error", ex, new object());
            }
            return blogList;
        }
Example #3
0
        public static string GetCommaSeperatedCategoryList(BlogPost blogItem)
        {
            StringBuilder display = new StringBuilder();

            int totalCategories = blogItem.Categories.Count;
            int currentCount = 1;

            foreach (Category categoryItem in blogItem.Categories)
            {
                display.Append(String.Format("<a href=\"{0}\">{1}</a>", GetCategoryUrl(categoryItem.CategoryName, blogItem.InnerItem), categoryItem.CategoryName));
                if (currentCount < totalCategories)
                    display.Append(", ");

                currentCount++;
            }

            return display.ToString();
        }