Exemple #1
0
        /// <summary>
        /// Updates the social media dropdowns.
        /// </summary>
        /// <param name="channelGuid">The channel unique identifier.</param>
        private void UpdateSocialMediaDropdowns(Guid?channelGuid)
        {
            List <AttributeCache> channelAttributes = new List <AttributeCache>();
            List <AttributeCache> itemAttributes    = new List <AttributeCache>();

            if (channelGuid.HasValue)
            {
                var rockContext = new RockContext();
                var channel     = new ContentChannelService(rockContext).GetNoTracking(channelGuid.Value);

                // add channel attributes
                channel.LoadAttributes();
                channelAttributes = channel.Attributes.Select(a => a.Value).ToList();

                // add item attributes
                AttributeService attributeService = new AttributeService(rockContext);
                itemAttributes = attributeService.GetByEntityTypeId(new ContentChannelItem().TypeId, false).AsQueryable()
                                 .Where(a => (
                                            a.EntityTypeQualifierColumn.Equals("ContentChannelTypeId", StringComparison.OrdinalIgnoreCase) &&
                                            a.EntityTypeQualifierValue.Equals(channel.ContentChannelTypeId.ToString())
                                            ) || (
                                            a.EntityTypeQualifierColumn.Equals("ContentChannelId", StringComparison.OrdinalIgnoreCase) &&
                                            a.EntityTypeQualifierValue.Equals(channel.Id.ToString())
                                            ))
                                 .OrderByDescending(a => a.EntityTypeQualifierColumn)
                                 .ThenBy(a => a.Order)
                                 .ToAttributeCacheList();
            }

            RockDropDownList[] attributeDropDowns = new RockDropDownList[]
            {
                ddlMetaDescriptionAttribute,
                ddlOpenGraphTitleAttribute,
                ddlOpenGraphDescriptionAttribute,
                ddlOpenGraphImageAttribute,
                ddlTwitterTitleAttribute,
                ddlTwitterDescriptionAttribute,
                ddlTwitterImageAttribute,
                ddlMetaDescriptionAttribute
            };

            RockDropDownList[] attributeDropDownsImage = new RockDropDownList[]
            {
                ddlOpenGraphImageAttribute,
                ddlTwitterImageAttribute,
            };

            foreach (var attributeDropDown in attributeDropDowns)
            {
                attributeDropDown.Items.Clear();
                attributeDropDown.Items.Add(new ListItem());
                foreach (var attribute in channelAttributes)
                {
                    string computedKey = "C^" + attribute.Key;
                    if (attributeDropDownsImage.Contains(attributeDropDown))
                    {
                        if (attribute.FieldType.Name == "Image")
                        {
                            attributeDropDown.Items.Add(new ListItem("Channel: " + attribute.Name, computedKey));
                        }
                    }
                    else
                    {
                        attributeDropDown.Items.Add(new ListItem("Channel: " + attribute.Name, computedKey));
                    }
                }

                // get all the possible Item attributes for items in this Content Channel and add those as options too
                foreach (var attribute in itemAttributes.DistinctBy(a => a.Key).ToList())
                {
                    string computedKey = "I^" + attribute.Key;
                    if (attributeDropDownsImage.Contains(attributeDropDown))
                    {
                        if (attribute.FieldType.Name == "Image")
                        {
                            attributeDropDown.Items.Add(new ListItem("Item: " + attribute.Name, computedKey));
                        }
                    }
                    else
                    {
                        attributeDropDown.Items.Add(new ListItem("Item: " + attribute.Name, computedKey));
                    }
                }
            }
        }