Exemplo n.º 1
0
        //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();
        //}

        //public ActionResult Carousel()
        //{
        //    /* Use the base class to get the results of the query */
        //    if (IsDataSourceItemNull) return ShowListIsEmptyPageEditorAlert();

        //    IEnumerable<CarouselItem> items = new CarouselItem(DataSourceItem).ChildrenInCurrentLanguage;
        //    return !items.IsNullOrEmpty() ? View(items) : ShowListIsEmptyPageEditorAlert();
        //}

        //public ActionResult IconAndTitleList()
        //{
        //    /* Populate with: Children of Datasource OR Children of Current */
        //    IEnumerable<SimpleItem> items = new SimpleItem(DataSourceItemOrCurrentItem).ChildrenInCurrentLanguage;
        //    return !items.IsNullOrEmpty() ? View(items) : ShowListIsEmptyPageEditorAlert();
        //}

        //public ActionResult LinkList()
        //{
        //    /* make sure the datasource or current has children in the current language and render accordingly */
        //    IEnumerable<SimpleItem> items = new SimpleItem(DataSourceItemOrCurrentItem).ChildrenInCurrentLanguage;
        //    SimpleItemList results = new SimpleItemList(DataSourceItem["Menu Title"], items);
        //    return !items.IsNullOrEmpty() ? View(results) : ShowListIsEmptyPageEditorAlert();
        //}

        //public ActionResult IconAndTitleListForQuery()
        //{
        //    /* Run the query and show the same view as IconAndTitleList */
        //    IEnumerable<SimpleItem> items = DataSourceItems.Select(x => new SimpleItem(x)).Where(x => SiteConfiguration.DoesItemExistInCurrentLanguage(x.Item));
        //    return !items.IsNullOrEmpty() ? View("IconAndTitleList", items) : ShowListIsEmptyPageEditorAlert();
        //}

        //public ActionResult QueriedList()
        //{
        //    if (IsDataSourceItemNull) return null;

        //    IEnumerable<SimpleItem> items = DataSourceItems.Select(x => new SimpleItem(x)).Where(x => SiteConfiguration.DoesItemExistInCurrentLanguage(x.Item));
        //    SimpleItemList results = new SimpleItemList(DataSourceItem["Title"], items);
        //    return !items.IsNullOrEmpty() ? View("LinkList", results) : ShowListIsEmptyPageEditorAlert();
        //}

        //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 Tags()
        {
            List <SimpleItem> items = new List <SimpleItem>();
            MultilistField    tags  = Sitecore.Context.Item.Fields["__semantics"];

            if (tags != null && tags.GetItems().Length > 0)
            {
                foreach (Item i in tags.GetItems())
                {
                    items.Add(new SimpleItem(i));
                }
            }
            return(View(items));
        }
        public ActionResult Tags()
        {
            List <SimpleItem> items = new List <SimpleItem>();
            MultilistField    tags  = Sitecore.Context.Item.Fields["__semantics"];

            if (tags != null && tags.GetItems().Length > 0)
            {
                foreach (Item i in tags.GetItems())
                {
                    items.Add(new SimpleItem(i));
                }
            }
            return(!items.IsNullOrEmpty() ? View(items) : ShowItemNotTaggedPageEditorAlert());
        }
Exemplo n.º 3
0
        // GET: RelatedEvents
        public ActionResult Index()
        {
            //get the current item using rendering item, this can also bring back the data source item and if not set defaults back to the current item
            var currentItem = RenderingContext.Current.Rendering.Item;

            if (currentItem == null)
            {
                return(new EmptyResult());
            }

            //get the related events list
            MultilistField relatedEvents = currentItem.Fields["Related-Events"];

            if (relatedEvents == null)
            {
                return(new EmptyResult());
            }

            //get the set items
            var setEvents = relatedEvents.GetItems();

            if (!setEvents.Any() && !Sitecore.Context.PageMode.IsExperienceEditorEditing)
            {
                return(new EmptyResult());
            }

            var displayEvents = setEvents.Select(eventItem => new NavigationItemModel()
            {
                Title = eventItem.DisplayName,
                Url   = LinkManager.GetItemUrl(eventItem)
            });

            // return the view with the events
            return(View(displayEvents));
        }
        public static IEnumerable <Item> AddIdToMultilist(this Item hostItem, string fieldName, string newId, bool checkSecurity = false)
        {
            Assert.IsNotNull(hostItem, "hostItem cannot be null");
            Assert.IsNotNullOrEmpty(fieldName, "fieldName cannot be null or empty");
            Assert.IsNotNullOrEmpty(newId, "newId cannot be null or empty");
            Assert.IsTrue(ID.IsID(newId), "newId is not a proper GUID");

            var field      = hostItem.Fields[fieldName];
            var targetItem = hostItem.Database.GetItem(newId);

            if (field != null && field.IsOfType <MultilistField>())
            {
                var state = SecurityState.Enabled;
                if (!checkSecurity)
                {
                    state = SecurityState.Disabled;
                }

                using (new SecurityStateSwitcher(state))
                {
                    using (new EditContext(hostItem))
                    {
                        MultilistField mlField = field;
                        mlField.Add(targetItem.ID.ToString());
                        return(mlField.GetItems());
                    }
                }
            }

            return(new Item[0]);
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var item = Sitecore.Context.Item;

            if (item.TemplateID == TemplateReferences.Holiday)
            {
                var json = new JSONHoliday();

                json.PageHeading = FieldRenderer.Render(item, "Page Heading");
                json.PageContent = FieldRenderer.Render(item, "Page Content");

                ReferenceField difficulty = item.Fields["Difficulty"];

                json.DifficultyLabel = Sitecore.Globalization.Translate.Text("Difficulty");
                json.Difficulty      = FieldRenderer.Render(difficulty.TargetItem, "Text");

                ReferenceField type = item.Fields["Type"];

                json.TypeLabel = Sitecore.Globalization.Translate.Text("Type");
                json.Type      = FieldRenderer.Render(type.TargetItem, "Text");

                MultilistField terrain = item.Fields["Terrain"];

                json.TerrainLabel = Sitecore.Globalization.Translate.Text("Terrain");
                json.Terrain      = string.Join(",", terrain.GetItems().Select(x => FieldRenderer.Render(x, "Text")));

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Response.Write(serializer.Serialize(json));
            }
        }
        public IEnumerable <Carousel> GetCarousels()
        {
            var             db              = RenderingContext.Current.ContextItem.Database;
            var             homeItem        = db.GetItem(Sitecore.Context.Site.StartPath);
            MultilistField  carouselEntries = homeItem.Fields["Carousels"];
            var             carouselItems   = carouselEntries.GetItems();
            List <Carousel> carousels       = new List <Carousel>();

            foreach (var cItem in carouselItems)
            {
                var address   = (LookupField)cItem.Fields["Event"];
                var eventItem = address?.TargetItem;
                var active    = (CheckboxField)cItem.Fields["IsActive"];
                carousels.Add(new Carousel
                {
                    Image    = cItem.GetMediaUrl("Image"),
                    Url      = (eventItem != null) ? LinkManager.GetItemUrl(eventItem) : "",
                    Title    = cItem.Fields["Title"].Value,
                    Intro    = cItem.Fields["Intro"].Value,
                    IsActive = active.Checked
                });
            }

            return(carousels);
        }
Exemplo n.º 7
0
        public ActionResult BestRecipes()
        {
            if (Sitecore.Context.Item == null)
            {
                return(null);
            }

            var dataSourceId = Sitecore.Context.Item.ID.ToString();

            Assert.IsNotNullOrEmpty(dataSourceId, "dataSourceId is null or empty");
            var item = Sitecore.Context.Database.GetItem(dataSourceId);

            if (item == null)
            {
                return(null);
            }

            HomepageModel.Homepage homePageModel = new HomepageModel.Homepage();

            homePageModel.BestRecipesTitle = item.Fields[Templates.BestRecipes.Fields.BestRecipesTitle.ToString()].Value;


            //Multilist
            MultilistField bestRecipesListField = item.Fields[Templates.BestRecipes.Fields.BestRecipesList];

            Item[]        bestRecipesListItems = bestRecipesListField.GetItems();
            List <Recipe> recipes = new List <Recipe>();

            if (bestRecipesListItems != null && bestRecipesListItems.Count() > 0)
            {
                foreach (Item recipeListItem in bestRecipesListItems)
                {
                    Recipe recipe     = new Recipe();
                    Item   recipeItem = Sitecore.Context.Database.GetItem(recipeListItem.ID);
                    recipe.RecipeName = recipeItem.Fields[Templates.Recipe.Fields.RecipName.ToString()].Value;


                    recipe.RecipeAbscractText = recipeItem.Fields[Templates.Recipe.Fields.RecipeAbscractText.ToString()].Value;

                    ImageField recipeImage = recipeItem.Fields[Templates.Recipe.Fields.RecipeAbscractImage];
                    if (recipeImage != null && recipeImage.MediaItem != null)
                    {
                        recipe.RecipeAbscractImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(recipeImage.MediaItem);
                    }


                    recipe.RecipeURL = Sitecore.Links.LinkManager.GetItemUrl(recipeItem);
                    int rating = 0;
                    int.TryParse(recipeItem.Fields[Templates.Recipe.Fields.RecipeRating.ToString()].Value, out rating);
                    recipe.RecipeRating = rating;
                    //hero.HeroBackgroundImageUrlAlt = heroImage.Alt;

                    recipes.Add(recipe);
                }
            }

            homePageModel.BestRecipesList = recipes;

            return(View(homePageModel));
        }
        public void GetEventList(EventModel eventModel)
        {
            string dataSource = RenderingContext.Current.Rendering.DataSource;

            if (!string.IsNullOrEmpty(dataSource))
            {
                Item           userGroupItem      = Sitecore.Context.Database.GetItem(dataSource);
                MultilistField selectedEventField = userGroupItem.Fields[EventConstant.GroupEvent];

                if (selectedEventField != null)
                {
                    Item[] eventItems = selectedEventField.GetItems();
                    if (eventItems != null && eventItems.Length > 0)
                    {
                        foreach (var item in eventItems)
                        {
                            GroupEvent eventItem = new GroupEvent();
                            eventItem.Name  = item[EventConstant.EventName];
                            eventItem.Venue = item[EventConstant.EventVenue];
                            DateField dateTimeField = item.Fields[EventConstant.EventDate];
                            eventItem.EventDate = Sitecore.DateUtil.IsoDateToDateTime(dateTimeField.Value);
                            MultilistField photoslist = item.Fields[EventConstant.EventPhotos];
                            Item[]         photos     = null;
                            if (photoslist != null)
                            {
                                photos = photoslist.GetItems();
                            }
                            eventItem.Photos = GetUrlOfPhotos(photos);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public ViewResult HeroSlider()
        {
            var viewModel = new HeroSliderViewModel();

            if (!String.IsNullOrEmpty(RenderingContext.Current.Rendering.DataSource))
            {
                var contentItem = _repository.GetItem(RenderingContext.Current.Rendering.DataSource);
                if (contentItem != null)
                {
                    var heroImagesField = new MultilistField(contentItem.Fields["Hero Image"]);

                    if (heroImagesField != null)
                    {
                        var items       = heroImagesField.GetItems();
                        var itemCounter = 0;

                        foreach (var item in items)
                        {
                            var mediaItem = (MediaItem)item;
                            viewModel.HeroImages.Add(new HeroSliderImageViewModel()
                            {
                                MediaUrl = MediaManager.GetMediaUrl(mediaItem),
                                AltText  = mediaItem.Alt,
                                IsActive = itemCounter == 0
                            });

                            itemCounter++;
                        }
                    }
                }
            }

            return(View(viewModel));
        }
Exemplo n.º 10
0
        public IEnumerable <MetaNavigationItem> Build(Item datasource)
        {
            if (datasource == null)
            {
                return(null);
            }

            string         title, url;
            var            pages            = new List <MetaNavigationItem>();
            MultilistField multiselectField = datasource.Fields["MetaPages"];

            if (multiselectField == null)
            {
                return(null);
            }

            Item[] items = multiselectField.GetItems();

            if (items != null)
            {
                foreach (var item in items)
                {
                    title = item.Fields["ContentHeading"].Value ?? string.Empty;
                    url   = LinkManager.GetItemUrl(item);
                    pages.Add(new MetaNavigationItem(title, url));
                }
            }

            return(pages);
        }
Exemplo n.º 11
0
        public List <PatternMatch> LoadPatterns()
        {
            List <PatternMatch> patternMatches = new List <PatternMatch>();

            if (Tracker.IsActive)
            {
                if (SiteConfiguration.GetSiteSettingsItem() != null)
                {
                    MultilistField profiles = SiteConfiguration.GetSiteSettingsItem().Fields["Visible Profiles"];
                    foreach (Item visibleProfile in profiles.GetItems())
                    {
                        Item visibleProfileItem = Sitecore.Context.Database.GetItem(visibleProfile.ID);
                        if (visibleProfileItem != null)
                        {
                            // show the pattern match if there is one.
                            var userPattern = Tracker.Current.Interaction.Profiles[visibleProfileItem.Name];
                            if (userPattern != null)
                            {
                                // load the details about the matching pattern
                                Item matchingPattern = Sitecore.Context.Database.GetItem(userPattern.PatternId.ToId());
                                if (matchingPattern != null)
                                {
                                    Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(((ImageField)matchingPattern.Fields["Image"]).MediaItem);
                                    string src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));
                                    patternMatches.Add(new PatternMatch(visibleProfileItem["Name"], matchingPattern.Name, src));
                                }
                            }
                        }
                    }
                }
            }
            return(patternMatches);
        }
        // GET: RelatedEvents
        public ActionResult Index()
        {
            var item = RenderingContext.Current.Rendering.Item;

            if (item == null)
            {
                return(new EmptyResult());
            }

            MultilistField relatedEvents = item.Fields["Related Events"];

            if (relatedEvents == null)
            {
                return(new EmptyResult());
            }

            var events = relatedEvents.GetItems()
                         .Select(i => new NavigationItem()
            {
                Title = i.DisplayName,
                URL   = LinkManager.GetItemUrl(i)
            });

            return(View(events));
        }
Exemplo n.º 13
0
        public void UserGroupHeaderProperties(UserGroupHeader model)
        {
            string dataSource = RenderingContext.Current.Rendering.DataSource;

            if (string.IsNullOrEmpty(dataSource))
            {
                Item itemUserGroupHeader = Sitecore.Context.Database.GetItem(dataSource);
                Item currentItem         = Sitecore.Context.Item;
                if (itemUserGroupHeader != null && currentItem != null)
                {
                    ImageField userGroupLocationId = itemUserGroupHeader.Fields[UserGroupConstant.UserGroupLocationIcon];
                    model.UserGroupLocationIcon = GetIconUrl(userGroupLocationId);
                    ImageField userGroupMemberIconId = itemUserGroupHeader.Fields[UserGroupConstant.UserGroupMemberIcon];
                    model.UserGroupMemberIcon = GetIconUrl(userGroupMemberIconId);
                    ImageField userGroupOrganisationIconId = itemUserGroupHeader.Fields[UserGroupConstant.UserGroupOrganiserICon];
                    model.UserGroupOrganiserICon = GetIconUrl(userGroupOrganisationIconId);
                    model.UserGroupLocation      = currentItem[UserGroupConstant.UserGroupLocation];
                    MultilistField orgainsers  = currentItem.Fields[UserGroupConstant.UserGroupOrganizer];
                    Item[]         _organizers = orgainsers.GetItems();

                    if (_organizers.Length > 0)
                    {
                        foreach (var item in _organizers)
                        {
                            model.UserGroupOrganizer += item["Name"];
                        }
                    }
                    //ToDo Count the Member using search
                    model.UserGroupMembers = "345";
                }
            }
        }
Exemplo n.º 14
0
        // GET: SingleMenu
        public ActionResult MenuList()
        {
            Item           pageItem      = Context.Item;
            string         pageTitle     = pageItem["Title"];
            MultilistField menuItems     = pageItem.Fields["Menus"];
            int            numberofItems = menuItems.Count;

            int[] classesIndexes = getClassesIndexes(numberofItems);
            int   counter        = 0;
            List <Models.SingleMenu> singleMenuList = new List <Models.SingleMenu>();

            foreach (Item item in menuItems.GetItems())
            {
                Models.SingleMenu currentMenuItem = new Models.SingleMenu(item["Title"], cssClasses[classesIndexes[counter]]);
                singleMenuList.Add(currentMenuItem);
                counter++;
            }

            //only for testing purposes
            //int[] indexes1 = getClassesIndexes(2);
            //int[] indexes2 = getClassesIndexes(3);
            //int[] indexes3 = getClassesIndexes(4);
            //int[] indexes4 = getClassesIndexes(5);
            //int[] indexes5 = getClassesIndexes(6);
            return(View(singleMenuList));
        }
        public ActionResult SCNavigationBoxList()
        {
            List <SCNavigationBoxVM> navboxlist = new List <SCNavigationBoxVM>();
            ChildList navBoxItems = Sitecore.Context.Database.GetItem("{2BDE8942-7089-46D4-A959-32A1C709B566}").Children;

            foreach (var navBox in navBoxItems)
            {
                Sitecore.Data.Items.Item navBoxItem = (Sitecore.Data.Items.Item)navBox;
                var navigationBoxVM = new SCNavigationBoxVM(navBoxItem);
                //var navboxitem = Sitecore.Context.Database.GetItem("{568325BB-0387-4FC2-90B5-6DE79965FDCF}");
                //SCNavigationBoxVM navigationBoxVM = new SCNavigationBoxVM(navboxitem);
                List <SCNavigationVM> navList        = new List <SCNavigationVM>();
                MultilistField        multilistField = Sitecore.Context.Database.GetItem(navBoxItem.ID.ToString()).Fields["NavigationList"];
                if (multilistField != null)
                {
                    Item[] navItems = multilistField.GetItems();
                    foreach (Item item in navItems)
                    {
                        navList.Add(new SCNavigationVM(item));
                    }
                }
                navigationBoxVM.NavigationList = navList;
                navboxlist.Add(navigationBoxVM);
            }
            return(PartialView(navboxlist));
        }
Exemplo n.º 16
0
        /// <summary>
        /// The rendering of the context page
        /// </summary>
        /// <param name="rendering">Rendering to initialize</param>
        public override void Initialize(Rendering rendering)
        {
            base.Initialize(rendering);

            if (!string.IsNullOrEmpty(Item[FieldConstants.TeaserGroup.Source]))
            {
                MultilistField source = Item.Fields[FieldConstants.TeaserGroup.Source];

                if (source != null)
                {
                    OwlTeasers = source.GetItems().ToList();
                }
            }

            // Findout dispaly social icons or not; this is droplist field
            SocialDisplay = Item[FieldConstants.TeaserGroup.Display];

            if (string.IsNullOrEmpty(SocialDisplay) || string.Equals(SocialDisplay, "show", StringComparison.CurrentCultureIgnoreCase))
            {
                SocialDisplay = "show";
            }

            if (string.Equals(SocialDisplay, "none", StringComparison.CurrentCultureIgnoreCase))
            {
                SocialDisplay = "none";
            }
        }
Exemplo n.º 17
0
        public Store(Item item)
        {
            if (item == null)
            {
                return;
            }

            this.Id      = item.ID;
            this.Name    = item.Fields[Templates.Store.StoreName].Value;
            this.UnitNo  = item.Fields[Templates.Store.UnitNo].Value;
            this.PhoneNo = item.Fields[Templates.Store.PhoneNo].Value;

            // Get Logo image
            this.Logo = item.ImageUrl(Templates.Store.Logo);

            this.OpeningHours = item.Fields[Templates.Store.OpeningHours].Value;
            this.Description  = item.Fields[Templates.Store.Description].Value;

            // Get Halal / GilfCard / FrasersPoint
            MultilistField storeOffers = item.Fields[Templates.Store.StoreOffers];

            if (storeOffers != null)
            {
                var items = storeOffers.GetItems();
                this.Halal        = items.Count(x => x.ID.ToString().Equals(Templates.StoreOffers.HalalCertified.ToString())) == 1;
                this.GilfCard     = items.Count(x => x.ID.ToString().Equals(Templates.StoreOffers.AcceptsGiftCards.ToString())) == 1;
                this.FrasersPoint = items.Count(x => x.ID.ToString().Equals(Templates.StoreOffers.EarnFrasersPoints.ToString())) == 1;
            }

            // Get ShareLink
            this.ShareLink = item.Url(Constants.DefaultUrlOptions);
        }
        public static IEnumerable <Item> RemoveIdFromMultilist(this Item item, string fieldId, string valueToRemove, bool checkSecurity = false)
        {
            var field = item.Fields[fieldId];

            if (field == null)
            {
                return(new Item[0]);
            }

            if (!field.IsOfType <MultilistField>())
            {
                return(new Item[0]);
            }

            var state = SecurityState.Enabled;

            if (!checkSecurity)
            {
                state = SecurityState.Disabled;
            }

            using (new SecurityStateSwitcher(state))
            {
                using (new EditContext(item))
                {
                    MultilistField mlField = field;
                    mlField.Remove(valueToRemove);
                    return(mlField.GetItems());
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Parse the component parameters to get the correct display for the component
        /// </summary>
        /// <param name="rendering">The rendering to initialize</param>
        public override void Initialize(Rendering rendering)
        {
            base.Initialize(rendering);

            Testimonials = new List <Item>();

            if (!string.IsNullOrEmpty(rendering["Parameters"]))
            {
                NameValueCollection parameters = WebUtil.ParseUrlParameters(rendering["Parameters"]);

                if (parameters == null || parameters.Count <= 0)
                {
                    return;
                }

                DisplayStars       = MainUtil.GetBool(parameters["Show Star Rating"], false);
                TextBalloonVariant = MainUtil.GetBool(parameters["TitleFontSize"], false);
            }

            if (Item != null)
            {
                MultilistField field = Item.Fields[FieldConstants.TeaserGroup.Source];
                if (field != null)
                {
                    Testimonials = field.GetItems();
                }
            }
        }
Exemplo n.º 20
0
        protected virtual AccordionModel GetModel(Item actionItem)
        {
            var accordionItems = new List <AccordionItemModel>();

            if (actionItem.Fields["Accordion Shared Items"] != null)
            {
                MultilistField mlf = actionItem.Fields["Accordion Shared Items"];

                foreach (Item accordionItem in mlf.GetItems())
                {
                    accordionItems.Add(GetAccordionItemModel(accordionItem));
                }
            }

            foreach (Item accordionItem in actionItem.GetChildren())
            {
                accordionItems.Add(GetAccordionItemModel(accordionItem));
            }

            if (accordionItems.Any())
            {
                accordionItems.ForEach(a => a.Collapsed = true);
                accordionItems.First().Collapsed = false;
            }

            var model = new AccordionModel
            {
                // numericLiterals only support up to 10. Expand as needed. Yes. Don't ask.
                AccordionItems = accordionItems.Take(10),
            };

            return(model);
        }
Exemplo n.º 21
0
        public ActionResult FeaturedRecipes()
        {
            if (Sitecore.Context.Item == null)
            {
                return(null);
            }

            var dataSourceId = Sitecore.Context.Item.ID.ToString();

            Assert.IsNotNullOrEmpty(dataSourceId, "dataSourceId is null or empty");
            var item = Sitecore.Context.Database.GetItem(dataSourceId);

            if (item == null)
            {
                return(null);
            }

            FeaturedRecipes featuredRecipes = new FeaturedRecipes();

            //Featured Recipe - DropTree Field
            ReferenceField featuredRecipeField = item.Fields[Templates.FeaturedRecipe.Fields.FeaturedRecipe];
            Item           featuredRecipeItem  = Sitecore.Context.Database.GetItem(featuredRecipeField.TargetID);

            if (featuredRecipeItem != null)
            {
                Recipe featuredRecipe = new Recipe();
                featuredRecipe.RecipeName        = featuredRecipeItem.Fields[Templates.Recipe.Fields.RecipeName.ToString()].Value;
                featuredRecipe.RecipeDescription = featuredRecipeItem.Fields[Templates.Recipe.Fields.RecipeDescription.ToString()].Value;
                featuredRecipes.FeaturedRecipe   = featuredRecipe;
                ImageField featuredRecipeImage = featuredRecipeItem.Fields[Templates.Recipe.Fields.RecipeImage];
                featuredRecipe.RecipeImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(featuredRecipeImage.MediaItem);
                featuredRecipe.RecipeImageAlt = featuredRecipeImage.Alt;
            }

            //Featured Recipes List - TreeList Field
            MultilistField featuredRecipesListField = item.Fields[Templates.FeaturedRecipe.Fields.FeaturedRecipesList];

            Item[]        featuredRecipeItems = featuredRecipesListField.GetItems();
            List <Recipe> featuredRecipesList = new List <Recipe>();

            if (featuredRecipeItems != null && featuredRecipeItems.Count() > 0)
            {
                foreach (Item i in featuredRecipeItems)
                {
                    Recipe recipe     = new Recipe();
                    Item   recipeItem = Sitecore.Context.Database.GetItem(i.ID);
                    recipe.RecipeName        = recipeItem.Fields[Templates.Recipe.Fields.RecipeName.ToString()].Value;
                    recipe.RecipeDescription = recipeItem.Fields[Templates.Recipe.Fields.RecipeDescription.ToString()].Value;
                    ImageField recipeImage = recipeItem.Fields[Templates.Recipe.Fields.RecipeImage];
                    recipe.RecipeImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(recipeImage.MediaItem);
                    recipe.RecipeImageAlt = recipeImage.Alt;

                    featuredRecipesList.Add(recipe);
                }
            }

            featuredRecipes.FeaturedRecipesList = featuredRecipesList;

            return(View(featuredRecipes));
        }
        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));
                }
            }

            // items.Sort(); // TODO: need to implement Comparer
            return(!items.IsNullOrEmpty() ? View(items) : ShowListIsEmptyPageEditorAlert());
        }
        public ActionResult LoadScriptSpecificPages()
        {
            Item globalScriptsItem       = Sitecore.Context.Database.GetItem(globalScriptsItemID);
            Item currentPageItem         = Context.Item;
            List <MvcHtmlString> scripts = new List <MvcHtmlString>();

            MvcHtmlString inlinePageScript = new MvcHtmlString(currentPageItem["Script"]);

            if (inlinePageScript != null)
            {
                scripts.Add(inlinePageScript);
            }

            IEnumerable <Item> specificScripts = globalScriptsItem.GetChildren();

            foreach (var item in specificScripts)
            {
                MvcHtmlString  currentScript = new MvcHtmlString(item["Script"]);
                MultilistField pagesItems    = item.Fields["Pages"];

                foreach (TemplateItem pageTemplate in pagesItems.GetItems())
                {
                    if (currentPageItem.TemplateID == pageTemplate.ID)
                    {
                        scripts.Add(currentScript);
                    }
                }
            }

            return(View(scripts));
        }
Exemplo n.º 24
0
        private void Page_Load(object sender, EventArgs e)
        {
            //Detect WebDav Support in PageEditor
            if (Request.Browser.Browser.Contains("IE") && Sitecore.Context.PageMode.IsPageEditor)
            {
                if (FileDrop != null)
                {
                    FileDrop.Visible = true;
                }
            }

            //Page Mode Detection
            AutoScroll = Sitecore.Context.PageMode.IsPageEditor ? "false" : "true";

            //Debug Mode
            if (Sitecore.Context.PageMode.IsDebugging)
            {
                //Put in Debug Information here about marketing information.
            }

            //Rendering Parameter Templates
            string rawParameters           = Attributes["sc_parameters"];
            NameValueCollection parameters = Sitecore.Web.WebUtil.ParseUrlParameters(rawParameters);

            GetMaxItems          = parameters["Max Items"] ?? "5";
            GetSlideDelay        = parameters["Slide Delay"] ?? "6000";
            GetDetailsSlideDelay = parameters["Detail Slide Duration"] ?? "1000";
            GetTransitionType    = parameters["Transition Type"] ?? "swing";

            var            getDataSource = Sitecore.Context.Database.GetItem(DataSource);
            MultilistField imageList     = getDataSource.Fields["Image List"];
            MultilistField videoList     = getDataSource.Fields["Video List"];


            //DetailsList.DataSource =
            ImageItems.DataSource = imageList.GetItems();
            VideoItems.DataSource = videoList.GetItems();

            var combinedItems = new List <Item>(imageList.GetItems());

            combinedItems.AddRange(videoList.GetItems());

            DetailsList.DataSource = combinedItems;
            DetailsList.DataBind();
            ImageItems.DataBind();
            VideoItems.DataBind();
        }
Exemplo n.º 25
0
        private void Page_Load(object sender, EventArgs e)
        {
            MultilistField tags = Sitecore.Context.Item.Fields["__semantics"];

            if (tags != null && tags.GetItems().Length > 0)
            {
                rptTags.DataSource = tags.GetItems();
                rptTags.DataBind();
            }
            else
            {
                if (IsPageEditorEditing)
                {
                    WriteAlert("item is not tagged");
                }
            }
        }
Exemplo n.º 26
0
        public static IEnumerable <Item> GetEventTypes()
        {
            var            db       = RenderingContext.Current.ContextItem.Database;
            var            homeItem = db.GetItem(Sitecore.Context.Site.StartPath);
            MultilistField events   = homeItem.Fields["Events"];

            return(events.GetItems());
        }
        /// <summary>
        /// This method returns a list of ProductSearchResults for a datasource
        /// </summary>
        /// <param name="dataSource">The datasource to perform the searches with</param>
        /// <param name="productSearchOptions">The search options.</param>
        /// <returns>A list of ProductSearchResults</returns>
        public MultipleProductSearchResults GetMultipleProductSearchResults(BaseItem dataSource, CommerceSearchOptions productSearchOptions)
        {
            Assert.ArgumentNotNull(productSearchOptions, "productSearchOptions");

            MultilistField searchesField         = dataSource.Fields[StorefrontConstants.KnownFieldNames.NamedSearches];
            var            searches              = searchesField.GetItems();
            var            productsSearchResults = new List <SearchResults>();

            foreach (Item search in searches)
            {
                var itemType = search.ItemType();
                switch (itemType)
                {
                case StorefrontConstants.ItemTypes.NamedSearch:
                {
                    var productsSearchResult = GetProductSearchResults(search, productSearchOptions);
                    if (productsSearchResult != null)
                    {
                        productsSearchResult.NamedSearchItem = search;
                        productsSearchResult.DisplayName     = search[StorefrontConstants.KnownFieldNames.Title];
                        productsSearchResults.Add(productsSearchResult);
                    }

                    break;
                }

                case StorefrontConstants.ItemTypes.SelectedProducts:
                {
                    int           itemCount        = 0;
                    SearchResults staticSearchList = new SearchResults();
                    staticSearchList.DisplayName     = search[StorefrontConstants.KnownFieldNames.Title];
                    staticSearchList.NamedSearchItem = search;

                    MultilistField productListField = search.Fields[StorefrontConstants.KnownFieldNames.ProductList];
                    var            productList      = productListField.GetItems();
                    foreach (Item productItem in productList)
                    {
                        var catalogItemtype = productItem.ItemType();
                        if (catalogItemtype == StorefrontConstants.ItemTypes.Category || catalogItemtype == StorefrontConstants.ItemTypes.Product)
                        {
                            staticSearchList.SearchResultItems.Add(productItem);

                            itemCount++;
                        }
                    }

                    staticSearchList.TotalItemCount = itemCount;
                    staticSearchList.TotalPageCount = itemCount;
                    productsSearchResults.Add(staticSearchList);

                    break;
                }
                }
            }

            return(new MultipleProductSearchResults(productsSearchResults));
        }
 public static Item[] GetMultiListItemsFromField(this Item item, string fieldName)
 {
     if (item.IsFieldExists(fieldName))
     {
         MultilistField multilistField = item.Fields[fieldName];
         return(multilistField.GetItems());
     }
     return(new Item[] { });
 }
        private List <ID> GetIdListFromField(Field field)
        {
            MultilistField multilistField = field;

            if (multilistField == null)
            {
                return(new List <ID>());
            }
            return(multilistField.GetItems().Select(i => i.ID).ToList());
        }
        public IEnumerable <InputParams> selectedMultilistValues(MultilistField data)
        {
            IEnumerable <InputParams> selectedInputs = data.GetItems().Select(x => new InputParams
            {
                Key   = x.Fields["Key"].ToString(),
                Value = x.Fields["Value"].ToString()
            });

            return(selectedInputs);
        }
Exemplo n.º 31
0
    public static MetaKeywordsModel GetKeywords(Item item)
    {
      if (item.IsDerived(Templates.PageMetadata.ID))
      {
        var keywordsField = item.Fields[Templates.PageMetadata.Fields.Keywords];
        if (keywordsField == null)
        {
          return null;
        }

        var keywordMultilist = new MultilistField(keywordsField);
        var keywords = keywordMultilist.GetItems().Select(keywrdItem => keywrdItem[Templates.Keyword.Fields.Keyword]);
        var metaKeywordModel = new MetaKeywordsModel {Keywords = keywords.ToList()};

        return metaKeywordModel;
      }

      return null;
    }
Exemplo n.º 32
0
    public static IEnumerable<Language> GetSupportedLanguages()
    {
      var languages = GetAll();
      var siteContext = new SiteContext();
      var siteDefinition = siteContext.GetSiteDefinition(Sitecore.Context.Item);
      
      if (siteDefinition?.Item == null || !siteDefinition.Item.IsDerived(Feature.Language.Templates.LanguageSettings.ID))
      {
        return languages;
      }

      var supportedLanguagesField = new MultilistField(siteDefinition.Item.Fields[Feature.Language.Templates.LanguageSettings.Fields.SupportedLanguages]);
      if (supportedLanguagesField.Count == 0)
      {
        return languages;
      }

      var supportedLanguages = supportedLanguagesField.GetItems();

      languages = languages.Where(language => supportedLanguages.Any(item => item.Name.Equals(language.Name)));

      return languages;
    } 
        /// <summary>
        /// Converts the multisites.
        /// </summary>
        /// <param name="multisitesCollection">The multisites collection.</param>
        /// <returns></returns>
        public static string ConvertMultisites(MultilistField multisitesCollection)
        {
            if (Multisites == null || multisitesCollection == null)
              {
            return string.Empty;
              }

              var sites = (from site in multisitesCollection.GetItems()
                   where Multisites.ContainsKey(site.ID)
                   select Multisites[site.ID]).Aggregate(string.Empty, (current, prefix) => string.Format("{0}|{1}", current, prefix));

              return UrlNormalizer.DecodeUrl(sites.TrimStart('|').ToLower());
        }
Exemplo n.º 34
0
 private static Item GetFirstCategoryItem(MultilistField field)
 {
     return field.GetItems().FirstOrDefault();
 }