Exemple #1
0
        public List <string> LoadEngagementStates()
        {
            List <string> states = new List <string>();

            try
            {
                var engagementstates = AutomationStateManager.Create(Tracker.Current.Contact).GetAutomationStates();

                if (engagementstates.Any())
                {
                    foreach (
                        AutomationStateContext context in
                        AutomationStateManager.Create(Tracker.Current.Contact).GetAutomationStates())
                    {
                        states.Add(String.Format("{0}: {1}", context.PlanItem.DisplayName, context.StateItem.DisplayName));
                    }
                }
                else
                {
                    states.Add(SiteConfiguration.GetDictionaryText("No Engagement States"));
                }
            }
            catch (Exception)
            {
                states.Add(SiteConfiguration.GetDictionaryText("Unable to load Engagement States"));
            }
            return(states);
        }
        public ActionResult RelatedArticles()
        {
            /* make sure the datasource or current has children in the current language and render accordingly */
            List <SimpleItem> items = new List <SimpleItem>();

            //first get items related to me...
            MultilistField related = Sitecore.Context.Item.Fields["Prerequisite Articles"];

            if (related != null)
            {
                foreach (Item i in related.GetItems())
                {
                    if (SiteConfiguration.DoesItemExistInCurrentLanguage(i))
                    {
                        items.Add(new SimpleItem(i));
                    }
                }
            }

            //now get items I am related to
            foreach (Item i in Sitecore.Context.Database.SelectItems(SiteConfiguration.GetFurtherReadingArticlesQuery(Sitecore.Context.Item.ID.ToString())))
            {
                if (SiteConfiguration.DoesItemExistInCurrentLanguage(i))
                {
                    items.Add(new SimpleItem(i));
                }
            }

            SimpleItemList results = new SimpleItemList(SiteConfiguration.GetDictionaryText("Related Articles"), items);

            return(!items.IsNullOrEmpty() ? View("LinkList", results) : ShowListIsEmptyPageEditorAlert());
        }
        public ActionResult ArticlesByContributor()
        {
            if (Sitecore.Context.Item.Template.Key != "team member")
            {
                return(null);
            }

            // this query will get the articles by the current team member
            // The queried list can also handle this by setting the datasource to a query.
            // The Standard Values can even pass in the id when the item is created.
            // Example Query: +template:d9019e30f95446ccaa703e928c40b5d0;+location:63ABEE8A4E3841599193D5F0A33AD666;+custom:contributors|$id;
            string            query = String.Format("+custom:contributors|{0};+template:d9019e30f95446ccaa703e928c40b5d0;+location:63ABEE8A4E3841599193D5F0A33AD666;", Sitecore.Context.Item.ID.ToString());
            List <SimpleItem> items = new List <SimpleItem>();

            foreach (Item i in GetDataSourceItemsFromQuery(query))
            {
                items.Add(new SimpleItem(i));
            }
            SimpleItemList results = new SimpleItemList(SiteConfiguration.GetDictionaryText("Articles"), items);

            return(!items.IsNullOrEmpty() ? View("LinkList", results) : ShowListIsEmptyPageEditorAlert());
        }
Exemple #4
0
        public List <string> LoadGoals()
        {
            List <string> goals = new List <string>();

            var conversions = (from page in Tracker.Current.Interaction.GetPages()
                               from pageEventData in page.PageEvents
                               where pageEventData.IsGoal
                               select pageEventData).ToList();

            if (conversions.Any())
            {
                conversions.Reverse();
                foreach (var goal in conversions)
                {
                    goals.Add(String.Format("{0} ({1})", goal.Name, goal.Value));
                }
            }
            else
            {
                goals.Add(SiteConfiguration.GetDictionaryText("No Goals"));
            }

            return(goals);
        }
        public SearchResults(string searchStr, string[] facets)
        {
            // if we don't have a searchStr for some reason...
            if (searchStr == string.Empty)
            {
                searchStr = "*";
            }

            List <Item> ResultsList = new List <Item>();

            string indexname = "sitecore_master_index";

            if (Sitecore.Context.PageMode.IsNormal || Sitecore.Context.PageMode.IsDebugging)
            {
                indexname = "sitecore_web_index";
            }

            using (var context = ContentSearchManager.GetIndex(indexname).CreateSearchContext())
            {
                // Start the search query building
                var query = context.GetQueryable <SitecoreItem>().Where(item => item.Path.StartsWith(Sitecore.Context.Site.StartPath));

                // we will split the spaces and require all words to be in the index.
                foreach (string word in searchStr.Split(' '))
                {
                    query = query.Where(item => item.Title.Contains(word) || item.Content.Contains(word));
                }

                if (facets != null)
                {
                    foreach (string facet in facets)
                    {
                        if (facet.Contains("|"))
                        {
                            string[] values = facet.Split('|');
                            string   val    = values[1];
                            if (values[0] == SiteConfiguration.GetDictionaryText("Type"))
                            {
                                query = query.Where(item => item.TemplateName.Equals(val));
                            }
                            if (values[0] == SiteConfiguration.GetDictionaryText("Tags"))
                            {
                                query = query.Where(item => item.Tags.Equals(val));
                            }
                        }
                    }
                }

                var results = query
                              .Filter(item => item.Language == Sitecore.Context.Language.Name)
                              .Filter(item => item.HasPresentation)
                              .Filter(item => item.ShowInSearchResults)
                              .FacetOn(item => item.Tags).FacetOn(item => item.TemplateName)
                              .GetResults();

                this.Results = new List <SimpleItem>();
                this.Facets  = new List <Facet>();

                this.SearchString = searchStr;
                foreach (SearchHit <SitecoreItem> result in results.Hits)
                {
                    this.Results.Add(new SimpleItem(result.Document.GetItem()));
                }

                foreach (FacetCategory fc in results.Facets.Categories)
                {
                    Facet f = new Facet();
                    f.Items = new List <FacetItem>();

                    if (fc.Name == "_templatename")
                    {
                        f.FacetName = SiteConfiguration.GetDictionaryText("Type");
                        foreach (var a in fc.Values)
                        {
                            f.Items.Add(new FacetItem(a.Name, String.Format("{0} ({1})", a.Name, a.AggregateCount), false));
                        }
                    }

                    if (fc.Name == "__semantics")
                    {
                        f.FacetName = SiteConfiguration.GetDictionaryText("Tags");
                        foreach (var a in fc.Values)
                        {
                            Item tag = Sitecore.Context.Database.GetItem(new ID(a.Name));
                            f.Items.Add(new FacetItem(a.Name, String.Format("{0} ({1})", tag.Name, a.AggregateCount), false));
                        }
                    }

                    // set the correct facet entries to selected
                    if (facets != null)
                    {
                        foreach (string facet in facets)
                        {
                            if (facet.Contains("|"))
                            {
                                string[] values = facet.Split('|');
                                if (values[0] == f.FacetName)
                                {
                                    foreach (FacetItem fi in f.Items)
                                    {
                                        if (fi.Id == values[1])
                                        {
                                            fi.Selected = true;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (f.Items.Count > 0)
                    {
                        this.Facets.Add(f);
                    }
                }
            }
        }
Exemple #6
0
 public ActionResult Search(string searchStr, string tag)
 {
     return(View(new SearchResults("*", new string[] { String.Format("{0}|{1}", SiteConfiguration.GetDictionaryText("Tags"), tag) })));
 }
        public SearchResults(string searchStr, string[] facets)
        {
            try
            {
                isSearchReturningItem = false;
                // if we don't have a searchStr for some reason...
                //if (searchStr == string.Empty) searchStr = "*";

                Item folderTemplateId        = Sitecore.Context.Database.GetItem("{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}");
                Item profileDataTemplateId   = Sitecore.Context.Database.GetItem("{E4BAA41C-C350-40E7-9795-F1E937D8A792}");
                Item profileFieldsTemplateId = Sitecore.Context.Database.GetItem("{7B2FBB10-1448-466C-82AB-9D6359BE091C}");
                Item profileListTemplateId   = Sitecore.Context.Database.GetItem("{EE5273A1-8E36-4A36-8CE7-FDF98B0D0157}");
                Item contactFieldTemplateId  = Sitecore.Context.Database.GetItem("{08C77347-B0CF-48DF-B9CD-7F33E5A7FBC0}");
                Item medialibrarytemplateId  = Sitecore.Context.Database.GetItem("{CC80011D-8EAE-4BFC-84F1-67ECD0223E9E}");
                Item SearchResultPage        = Sitecore.Context.Database.GetItem("{1C9826B5-5C14-4DC2-9054-861D9C6C6F6B}");
                Item SuccessPage             = Sitecore.Context.Database.GetItem("{BDDFF05D-F7E8-468C-8A57-6933A9CD94FC}");
                Item ResultItem = Sitecore.Context.Database.GetItem("{20296C64-BD89-4768-A340-836B1EF13DF4}");
                //Item itemName=Sitecore.Context.Database.get
                List <Item> ResultsList = new List <Item>();

                string indexname = "sitecore_master_index";
                //if (Sitecore.Context.PageMode.IsNormal || Sitecore.Context.PageMode.IsDebugging) indexname = "sitecore_web_index";

                using (var context = ContentSearchManager.GetIndex(indexname).CreateSearchContext())
                {
                    //generic search
                    var query = context.GetQueryable <SitecoreItem>().Where(item => item.Path.StartsWith("/sitecore/content/EmployeeBenefits/Pages")).
                                Where(item => item.TemplateId != folderTemplateId.ID).
                                Where(item => item.TemplateId != profileDataTemplateId.ID).
                                Where(item => item.TemplateId != profileFieldsTemplateId.ID)
                                .Where(item => item.TemplateId != profileListTemplateId.ID).
                                Where(item => item.TemplateId != contactFieldTemplateId.ID).
                                Where(item => item.ItemId != SearchResultPage.ID).Where(item => item.ItemId != SuccessPage.ID);


                    // var mediaQuerySearch = context.GetQueryable<SitecoreItem>().Where(item => item.Path.StartsWith("/sitecore/content/EmployeeBenefits/MediaFiles"));
                    var mediaQuerySearch = context.GetQueryable <SitecoreItem>().Where(item => item.Path.StartsWith("/sitecore")).Where(item => item.TemplateId == medialibrarytemplateId.ID);
                    //    Where(item => item.TemplateId != profileDataTemplateId.ID).
                    //    Where(item => item.TemplateId != profileFieldsTemplateId.ID)
                    //   .Where(item => item.TemplateId != profileListTemplateId.ID).
                    //   Where(item => item.TemplateId != contactFieldTemplateId.ID).
                    //   Where(item => item.ItemId != SearchResultPage.ID).Where(item => item.ItemId != SuccessPage.ID);
                    //var itemBasedQuery=context.GetQueryable<SitecoreItem>().Where(item=>item.GetField())


                    foreach (string word in searchStr.Split(' '))
                    {
                        query = query.Where(item => item.Title.Contains(word) || item.Content.Contains(word));
                    }
                    foreach (string word in searchStr.Split(' '))
                    {
                        mediaQuerySearch = mediaQuerySearch.Where(item => item.Title.Contains(word) || item.Content.Contains(word));
                    }
                    if (facets != null)
                    {
                        foreach (string facet in facets)
                        {
                            if (facet.Contains("|"))
                            {
                                string[] values = facet.Split('|');
                                string   val    = values[1];
                                if (values[0] == SiteConfiguration.GetDictionaryText("Type"))
                                {
                                    query = query.Where(item => item.TemplateName.Equals(val));
                                }
                                if (values[0] == SiteConfiguration.GetDictionaryText("Tags"))
                                {
                                    query = query.Where(item => item.Tags.Equals(val));
                                }
                            }
                        }
                    }


                    var results = query
                                  .Filter(item => item.Language == Sitecore.Context.Language.Name)
                                  .GetResults();
                    // Show media results for all languages
                    var mediaresults = mediaQuerySearch.GetResults();
                    this.Results = new List <SimpleItem>();
                    this.Facets  = new List <Facet>();

                    this.SearchString = searchStr;

                    List <ResultItems> lst = new List <ResultItems>();

                    //List<SimpleItem> list = new List<SimpleItem>();
                    if (results.Count() > 0)
                    {
                        this.isSearchReturningItem = true;

                        foreach (SearchHit <SitecoreItem> result in results.Hits)
                        {
                            ResultItems items = new ResultItems();
                            //this.Results.Add(new SimpleItem(result.Document.GetItem()));
                            if (result.Document.Name != null && result.Document.GetItem().TemplateID != medialibrarytemplateId.ID)
                            {
                                items.Name  = result.Document.Name;
                                items.Title = result.Document.GetItem().Fields["Title"].ToString();
                                //this.SearchItemName= result.Document.GetItem().Fields["Title"].ToString();
                                items.Description = result.Document.GetItem().Fields["Body"].ToString();
                                items.Url         = Sitecore.Links.LinkManager.GetItemUrl(result.Document.GetItem());
                            }
                            lst.Add(items);
                        }

                        ResultItems = lst;
                    }


                    else if (mediaresults.Count() > 0)

                    {
                        this.isSearchReturningItem = true;

                        foreach (SearchHit <SitecoreItem> result in mediaresults.Hits)
                        {
                            ResultItems mediaitems = new ResultItems();
                            // this.Results.Add(new SimpleItem(result.Document.GetItem()));
                            if (result.Document.GetItem().Fields["Extension"].Value == "pdf" || (result.Document.GetItem().Fields["Extension"].Value == "PDF"))
                            {
                                // ResultItems mediaitems = new ResultItems();
                                Media media = MediaManager.GetMedia(result.Document.GetItem());
                                mediaitems.Title       = media.MediaData.MediaItem.Title;
                                mediaitems.Name        = media.MediaData.MediaItem.Name;
                                mediaitems.Description = media.MediaData.MediaItem.Description;
                                // this.mediaItemPath = media.MediaData.MediaItem.Path;
                                mediaitems.MediaUrl = StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(result.Document.GetItem()));
                            }
                            lst.Add(mediaitems);
                        }
                        ResultItems = lst;
                    }

                    else
                    {
                        this.isSearchReturningItem = false;
                        this.SearchItemName        = "Sorry!! No results Found";
                        this.SearchitemDescription = searchStr + "is not Found";
                    }

                    //  ResultItems = lst;
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Info("Exception occured in SearchResults Page", ex.Message);
            }

            finally
            {
                this.SearchItemTitle = "Some Error Occured";
            }
        }