예제 #1
0
        /// <summary>
        /// Returns the CSS classes (if any) associated with the theme(s) of the content, as decided by its categories
        /// </summary>
        /// <param name="content"></param>
        /// <returns>CSS classes associated with the content's theme(s), or an empty string array if no theme is applicable</returns>
        /// <remarks>Content's categorization may map to more than one theme. This method assumes there are website categories called "Meet", "Track", and "Plan"</remarks>
        public static string[] GetThemeCssClassNames(this ICategorizable content)
        {
            if (content.Category == null)
            {
                return(new string[0]);
            }

            var cssClasses         = new HashSet <string>(); // Although with some overhead, a HashSet allows us to ensure we never add a CSS class more than once
            var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>();

            foreach (var categoryName in content.Category.Select(category => categoryRepository.Get(category).Name.ToLower()))
            {
                switch (categoryName)
                {
                case "meet":
                    cssClasses.Add("theme1");
                    break;

                case "track":
                    cssClasses.Add("theme2");
                    break;

                case "plan":
                    cssClasses.Add("theme3");
                    break;
                }
            }

            return(cssClasses.ToArray());
        }
        /// <summary>
        /// Filters out content references to content that does not match current category filters, if any
        /// </summary>
        /// <param name="contentReferences">
        /// The content references.
        /// </param>
        /// <returns>
        /// A filtered <see cref="IList{ContentReference}"/>.
        /// </returns>
        private IList <ContentReference> FilterByCategory(IEnumerable <ContentReference> contentReferences)
        {
            if (this.Category == null || !this.Category.Any())
            {
                return(contentReferences.ToList());
            }

            // Filter by category if a category filter has been set
            List <ContentReference> filteredChildren = new List <ContentReference>();

            foreach (ContentReference contentReference in contentReferences)
            {
                ICategorizable content = DataFactory.Instance.Get <IContent>(contentReference) as ICategorizable;

                if (content != null)
                {
                    bool atleastOneMatchingCategory = content.Category.Any(c => this.Category.Contains(c));

                    if (atleastOneMatchingCategory)
                    {
                        filteredChildren.Add(contentReference);
                    }
                }
                else
                {
                    // Non-categorizable content will also be included
                    filteredChildren.Add(contentReference);
                }
            }

            return(filteredChildren);
        }
 public static IEnumerable <string> SearchCategories(this ICategorizable categorizable)
 {
     ObjectExtensions.ValidateNotNullArgument((object)categorizable, "categorizable");
     if (ObjectExtensions.IsNull((object)categorizable.Category))
     {
         return((IEnumerable <string>)null);
     }
     else
     {
         return((IEnumerable <string>)Enumerable.ToList <string>(Enumerable.Select <int, string>((IEnumerable <int>)categorizable.Category, (Func <int, string>)(x => Category.Find(x).Name))));
     }
 }
예제 #4
0
        /// <summary>
        /// Filters out content references to content that does not match current category filters, if any
        /// </summary>
        /// <param name="contentReferences"></param>
        /// <returns></returns>
        private IList <T> FilterByCategory <T>(IEnumerable <T> contentReferences)
        {
            if (Category == null || !Category.Any())
            {
                return(contentReferences.ToList());
            }

            // Filter by category if a category filter has been set
            var filteredChildren = new List <T>();

            foreach (var contentReference in contentReferences)
            {
                ICategorizable content = null;
                if (contentReference is ContentReference)
                {
                    content = (contentReference as ContentReference).Get <IContent>() as ICategorizable;
                }
                else if (typeof(T) == typeof(GetChildrenReferenceResult))
                {
                    content = (contentReference as GetChildrenReferenceResult).ContentLink.Get <IContent>() as ICategorizable;
                }

                if (content != null)
                {
                    var atLeastOneMatchingCategory = content.Category.Any(c => Category.Contains(c));

                    if (atLeastOneMatchingCategory)
                    {
                        filteredChildren.Add(contentReference);
                    }
                }
                else // Non-categorizable content will also be included
                {
                    filteredChildren.Add(contentReference);
                }
            }

            return(filteredChildren);
        }