コード例 #1
0
        private string GetSearchQuery(IRelatedItemsComposition composition)
        {
            var searchTerm = composition.RelatedItemsSearchQuery;

            if (string.IsNullOrWhiteSpace(searchTerm))
            {
                return(composition.GetHeadline());
            }

            return(searchTerm);
        }
コード例 #2
0
        private IEnumerable <string> GetNodeIdsToExcludeFromSearchResults(IRelatedItemsComposition composition)
        {
            var nodeIds = new List <string>
            {
                composition.Id.ToString()
            };

            if (ExistenceUtility.IsNullOrEmpty(composition.RelatedItems))
            {
                return(nodeIds);
            }

            var pickedRelatedItemIds = composition.RelatedItems.Select(x => x.Id.ToString());

            nodeIds.AddRange(pickedRelatedItemIds);

            return(nodeIds);
        }
コード例 #3
0
        public IEnumerable <RelatedItemViewModel> GetViewModels(IRelatedItemsComposition composition, HomePage homePage)
        {
            var viewModels = new List <RelatedItemViewModel>();

            if (composition.ShowRelatedItems == false)
            {
                return(viewModels);
            }
            var pickedRelatedItemViewModels = GetPickedRelatedItemViewModels(composition.RelatedItems, homePage);

            viewModels.AddRange(pickedRelatedItemViewModels);

            if (viewModels.Count < MaximumRelatedItems)
            {
                var excludedNodeIds                = GetNodeIdsToExcludeFromSearchResults(composition);
                var searchQuery                    = GetSearchQuery(composition);
                var numberOfItemsToTake            = MaximumRelatedItems - viewModels.Count();
                var searchedRelatedItemsViewModels = GetSearchQueryRelatedItemViewModels(searchQuery, MaximumNumberOfSearchResults, numberOfItemsToTake, excludedNodeIds, homePage);

                viewModels.AddRange(searchedRelatedItemsViewModels);
            }

            return(viewModels);
        }
コード例 #4
0
 /// <summary>Static getter for Search Query</summary>
 public static string GetRelatedItemsSearchQuery(IRelatedItemsComposition that)
 {
     return(that.GetPropertyValue <string>("relatedItemsSearchQuery"));
 }
コード例 #5
0
 /// <summary>Static getter for Items</summary>
 public static IEnumerable <IPublishedContent> GetRelatedItems(IRelatedItemsComposition that)
 {
     return(that.GetPropertyValue <IEnumerable <IPublishedContent> >("relatedItems"));
 }
コード例 #6
0
 /// <summary>Static getter for Show Related Items</summary>
 public static bool GetShowRelatedItems(IRelatedItemsComposition that)
 {
     return(that.GetPropertyValue <bool>("showRelatedItems"));
 }