Exemple #1
0
        /// <summary>
        /// Gets the properties and attributes for the entity
        /// </summary>
        /// <param name="contentChannelTypeId">The content channel type identifier.</param>
        /// <returns></returns>
        private List <EntityField> GetContentChannelItemAttributes(int?contentChannelTypeId)
        {
            List <EntityField> entityAttributeFields = new List <EntityField>();

            if (contentChannelTypeId.HasValue)
            {
                var fakeContentChannelItem = new Rock.Model.ContentChannelItem {
                    ContentChannelTypeId = contentChannelTypeId.Value
                };
                Rock.Attribute.Helper.LoadAttributes(fakeContentChannelItem);
                foreach (var attribute in fakeContentChannelItem.Attributes.Select(a => a.Value))
                {
                    EntityHelper.AddEntityFieldForAttribute(entityAttributeFields, attribute, true);
                }
            }

            int index        = 0;
            var sortedFields = new List <EntityField>();

            foreach (var entityProperty in entityAttributeFields.OrderBy(p => p.TitleWithoutQualifier).ThenBy(p => p.Name))
            {
                entityProperty.Index = index;
                index++;
                sortedFields.Add(entityProperty);
            }

            return(sortedFields);
        }
 /// <summary>
 /// Copies the properties from another ContentChannelItem object to this ContentChannelItem object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this ContentChannelItem target, ContentChannelItem source)
 {
     target.Id = source.Id;
     target.ApprovedByPersonAliasId = source.ApprovedByPersonAliasId;
     target.ApprovedDateTime        = source.ApprovedDateTime;
     target.Content              = source.Content;
     target.ContentChannelId     = source.ContentChannelId;
     target.ContentChannelTypeId = source.ContentChannelTypeId;
     target.ExpireDateTime       = source.ExpireDateTime;
     target.ForeignGuid          = source.ForeignGuid;
     target.ForeignKey           = source.ForeignKey;
     target.Permalink            = source.Permalink;
     target.Priority             = source.Priority;
     target.StartDateTime        = source.StartDateTime;
     target.Status                  = source.Status;
     target.Title                   = source.Title;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid      = source.Guid;
     target.ForeignId = source.ForeignId;
 }
Exemple #3
0
        /// <summary>
        /// Adds the synced content channel item for the media element by
        /// the given identifier.
        /// </summary>
        /// <param name="mediaElement">The media element.</param>
        /// <param name="rockContext">The <see cref="RockContext"/> to perform the save in.</param>
        /// <remarks>Must be called on a MediaElement that has a valid <see cref="MediaElement.MediaFolder"/> property.</remarks>
        private static void AddSyncedContentChannelItem(MediaElement mediaElement, RockContext rockContext)
        {
            try
            {
                // Freak accident, either we are in a transaction or the
                // media element got deleted before we started executing.
                if (mediaElement == null || mediaElement.MediaFolder == null)
                {
                    return;
                }

                // No sync, just exit.
                if (!mediaElement.MediaFolder.IsContentChannelSyncEnabled)
                {
                    return;
                }

                var contentChannelTypeId = mediaElement.MediaFolder.ContentChannel?.ContentChannelTypeId;
                var contentChannelId     = mediaElement.MediaFolder.ContentChannelId;
                var attributeId          = mediaElement.MediaFolder.ContentChannelAttributeId;
                var status = mediaElement.MediaFolder.ContentChannelItemStatus;

                // Missing required information.
                if (!contentChannelTypeId.HasValue || !contentChannelId.HasValue || !attributeId.HasValue || !status.HasValue)
                {
                    return;
                }

                var attribute = AttributeCache.Get(attributeId.Value);

                // Shouldn't happen, but make sure we don't hit a NRE later.
                if (attribute == null)
                {
                    return;
                }

                var contentChannelItemService = new ContentChannelItemService(rockContext);
                var contentChannelItem        = new ContentChannelItem();
                contentChannelItemService.Add(contentChannelItem);

                contentChannelItem.ContentChannelId     = contentChannelId.Value;
                contentChannelItem.ContentChannelTypeId = contentChannelTypeId.Value;
                contentChannelItem.Title         = mediaElement.Name;
                contentChannelItem.Content       = mediaElement.Description;
                contentChannelItem.StartDateTime = mediaElement.SourceCreatedDateTime ?? mediaElement.CreatedDateTime ?? RockDateTime.Now;
                contentChannelItem.Status        = status.Value;

                // We want both the content channel item and it's attributes
                // to be saved either together or not at all.
                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();

                    // 2.5x faster than LoadAttributes/SaveAttributeValues.
                    Rock.Attribute.Helper.SaveAttributeValue(contentChannelItem, attribute, mediaElement.Guid.ToString(), rockContext);
                });
            }
            catch (Exception ex)
            {
                var exception = new Exception("Error while creating synced content channel item for media element.", ex);
                ExceptionLogService.LogException(exception);
            }
        }
        /// <summary>
        /// Gets the properties and attributes for the entity
        /// </summary>
        /// <param name="contentChannelTypeId">The content channel type identifier.</param>
        /// <returns></returns>
        private List<EntityField> GetContentChannelItemAttributes( int? contentChannelTypeId )
        {
            List<EntityField> entityAttributeFields = new List<EntityField>();

            if ( contentChannelTypeId.HasValue )
            {
                var fakeContentChannelItem = new Rock.Model.ContentChannelItem { ContentChannelTypeId = contentChannelTypeId.Value };
                Rock.Attribute.Helper.LoadAttributes( fakeContentChannelItem );
                foreach ( var attribute in fakeContentChannelItem.Attributes.Select( a => a.Value ) )
                {
                    EntityHelper.AddEntityFieldForAttribute( entityAttributeFields, attribute, true );
                }
            }

            int index = 0;
            var sortedFields = new List<EntityField>();
            foreach ( var entityProperty in entityAttributeFields.OrderBy( p => p.TitleWithoutQualifier ).ThenBy( p => p.Name ) )
            {
                entityProperty.Index = index;
                index++;
                sortedFields.Add( entityProperty );
            }

            return sortedFields;
        }