コード例 #1
0
        public PortfolioHelper(SectionPortfolio currPage)
        {
            _currPage  = currPage;
            _umbHelper = ContentHelper.GetHelper();

            LoadSettings();

            //Load categories and portfolio items.
            if (_hasCategories)
            {
                _categoryItems = _currPage.Descendant <FolderGenericCategories>().Children <DGenericCategoryItem>().ToList();
            }

            _portfolioItems = _currPage.Descendants <PagePortfolioItem>().ToList();

            //If show counters enabled and categories are enabled, count portfolio items for each category
            //This is done here to preserve processing if hide categories is enabled.
            if (_currPage.ShowItemCount && !_currPage.DoNotDisplayCategories)
            {
                _categoryItemCount = new Dictionary <int, int>();

                //Get only the non-empty categories (GetCategories() gets only categories with items) and count items in each
                foreach (IPublishedContent categoryItem in this.GetCategories())
                {
                    _categoryItemCount.Add(
                        categoryItem.Id,
                        _portfolioItems.Where(x => categoryItem.Id.ToString().IsContainedInCsv(x.Categories)).Count()
                        );
                }
            }
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: nitinanand27/Drakshop
        public static List <PagePortfolioItem> GetPrevNext(this PagePortfolioItem item)
        {
            SectionPortfolio portfolioRoot = item.Ancestor <SectionPortfolio>();

            PortfolioHelper h = new PortfolioHelper(portfolioRoot);

            //Get a portfoliohelper to get items in the same order as defined in portfolio settings

            IEnumerable <DGenericCategoryItem> categories = item.GetPickerItemsByValue <DGenericCategoryItem>(item.Categories);

            //Get the next / previous item related to the current item
            IEnumerable <PagePortfolioItem> allItems = h.GetPortfolioItems();

            //See if we must restrict to current item's categories
            if (portfolioRoot.NextPrevRestrictToCategories)
            {
                allItems = allItems.Where(x => x.Categories.IsContainedInCsv(item.Categories));
            }

            List <PagePortfolioItem> sandwitchedItems = allItems.FindSandwichedItem(x => x.Id == item.Id).ToList <PagePortfolioItem>();

            //Remove current page fron list
            sandwitchedItems.RemoveAt(1);

            return(sandwitchedItems);
        }
コード例 #3
0
ファイル: Extensions.cs プロジェクト: nitinanand27/Drakshop
        public static bool MustShowRelated(this PagePortfolioItem item)
        {
            SectionPortfolio portfolioRoot = item.Ancestor <SectionPortfolio>();
            PortfolioHelper  h             = new PortfolioHelper(portfolioRoot);

            if (string.IsNullOrEmpty(item.RelatedItems) && !portfolioRoot.RandomRelated)
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: nitinanand27/Drakshop
        public static IEnumerable <PagePortfolioItem> GetRelatedItems(this PagePortfolioItem item)
        {
            SectionPortfolio portfolioRoot = item.Ancestor <SectionPortfolio>();
            PortfolioHelper  h             = new PortfolioHelper(portfolioRoot);


            if (string.IsNullOrEmpty(item.RelatedItems) && portfolioRoot.RandomRelated)
            {
                IEnumerable <PagePortfolioItem> randomItems = h.GetPortfolioItemsRandom();

                if (portfolioRoot.RandomRelatedRestrictToCategories)
                {
                    return(randomItems.Where(x => x.Categories.IsContainedInCsv(item.Categories)).Take(h.GlobalRandomRelatedNumber));
                }
                else
                {
                    return(randomItems.Take(h.GlobalRandomRelatedNumber));
                }
            }
            else
            {
                return(item.GetPickerItemsByValue <PagePortfolioItem>(item.RelatedItems));
            }
        }
コード例 #5
0
 public static PortfolioHelper GetCachedPortfolioHelper(ApplicationContext cx, SectionPortfolio portfolioRoot)
 {
     return((PortfolioHelper)cx.ApplicationCache.RuntimeCache.GetCacheItem(string.Format("portfolioHelper{0}", portfolioRoot.Id.ToString()), () => new PortfolioHelper(portfolioRoot)));
 }