예제 #1
0
        /// <summary>
        /// Handles the Delete event of the gContentChannels control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gContentChannels_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            ContentChannelService contentChannelService = new ContentChannelService(rockContext);

            ContentChannel contentChannel = contentChannelService.Get(e.RowKeyId);

            if (contentChannel != null)
            {
                string errorMessage;
                if (!contentChannelService.CanDelete(contentChannel, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Warning);
                    return;
                }

                contentChannel.ParentContentChannels.Clear();
                contentChannel.ChildContentChannels.Clear();

                contentChannelService.Delete(contentChannel);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        public SlidesResponse GetContentChannel(string id)
        {
            var rockContext           = new RockContext();
            var contentChannelService = new ContentChannelService(rockContext);
            var response = new SlidesResponse();

            var contentChannel = contentChannelService.Get(id.AsInteger());

            if (contentChannel != null)
            {
                response.Contents = GetContentChannelItems(new List <int>(), contentChannel, rockContext);
            }

            response.GenerateHash();

            return(response);
        }
        /// <summary>
        /// Handles the SaveClick event of the mdContentComponentConfig control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void mdContentComponentConfig_SaveClick(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            var dataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

            if (dataViewFilter != null)
            {
                // update Guids since we are creating a new dataFilter and children and deleting the old one
                SetNewDataFilterGuids(dataViewFilter);

                if (!Page.IsValid)
                {
                    return;
                }

                if (!dataViewFilter.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);

                int?dataViewFilterId = hfDataFilterId.Value.AsIntegerOrNull();
                if (dataViewFilterId.HasValue)
                {
                    var oldDataViewFilter = dataViewFilterService.Get(dataViewFilterId.Value);
                    DeleteDataViewFilter(oldDataViewFilter, dataViewFilterService);
                }

                dataViewFilterService.Add(dataViewFilter);
            }

            rockContext.SaveChanges();

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);
            Guid?          contentChannelGuid           = this.GetAttributeValue("ContentChannel").AsGuidOrNull();
            ContentChannel contentChannel = null;

            if (contentChannelGuid.HasValue)
            {
                contentChannel = contentChannelService.Get(contentChannelGuid.Value);
            }

            if (contentChannel == null)
            {
                contentChannel = new ContentChannel();
                contentChannel.ContentChannelTypeId = this.ContentChannelTypeId;
                contentChannelService.Add(contentChannel);
            }

            contentChannel.LoadAttributes(rockContext);
            avcContentChannelAttributes.GetEditValues(contentChannel);

            contentChannel.Name = tbComponentName.Text;
            rockContext.SaveChanges();
            contentChannel.SaveAttributeValues(rockContext);

            this.SetAttributeValue("ContentChannel", contentChannel.Guid.ToString());

            this.SetAttributeValue("ItemCacheDuration", nbItemCacheDuration.Text);

            int? contentComponentTemplateValueId   = dvpContentComponentTemplate.SelectedValue.AsInteger();
            Guid?contentComponentTemplateValueGuid = null;

            if (contentComponentTemplateValueId.HasValue)
            {
                var contentComponentTemplate = DefinedValueCache.Get(contentComponentTemplateValueId.Value);
                if (contentComponentTemplate != null)
                {
                    contentComponentTemplateValueGuid = contentComponentTemplate.Guid;
                }
            }

            this.SetAttributeValue("ContentComponentTemplate", contentComponentTemplateValueGuid.ToString());
            this.SetAttributeValue("AllowMultipleContentItems", cbAllowMultipleContentItems.Checked.ToString());
            this.SetAttributeValue("OutputCacheDuration", nbOutputCacheDuration.Text);
            this.SetAttributeValue("CacheTags", cblCacheTags.SelectedValues.AsDelimited(","));
            if (dataViewFilter != null)
            {
                this.SetAttributeValue("FilterId", dataViewFilter.Id.ToString());
            }
            else
            {
                this.SetAttributeValue("FilterId", null);
            }

            this.SaveAttributeValues();

            var block = new BlockService(rockContext).Get(this.BlockId);

            block.PreHtml  = cePreHtml.Text;
            block.PostHtml = cePostHtml.Text;
            rockContext.SaveChanges();

            mdContentComponentConfig.Hide();
            pnlContentComponentConfig.Visible = false;

            RemoveCacheItem(OUTPUT_CACHE_KEY);
            RemoveCacheItem(ITEM_CACHE_KEY);

            // reload the page to make sure we have a clean load
            NavigateToCurrentPageReference();
        }
예제 #4
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var            rockContext = new RockContext();
            ContentChannel contentChannel;

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);
            CategoryService       categoryService       = new CategoryService(rockContext);

            int contentChannelId = hfId.Value.AsInteger();

            if (contentChannelId == 0)
            {
                contentChannel = new ContentChannel {
                    Id = 0
                };
                contentChannelService.Add(contentChannel);
            }
            else
            {
                contentChannel = contentChannelService.Get(contentChannelId);
            }

            if (contentChannel != null)
            {
                contentChannel.Name                         = tbName.Text;
                contentChannel.Description                  = tbDescription.Text;
                contentChannel.ContentChannelTypeId         = ddlChannelType.SelectedValueAsInt() ?? 0;
                contentChannel.IsStructuredContent          = cbIsStructuredContent.Checked;
                contentChannel.StructuredContentToolValueId = dvEditorTool.SelectedDefinedValueId;
                contentChannel.ContentControlType           = ddlContentControlType.SelectedValueAsEnum <ContentControlType>();
                contentChannel.RootImageDirectory           = tbRootImageDirectory.Visible ? tbRootImageDirectory.Text : string.Empty;
                contentChannel.IconCssClass                 = tbIconCssClass.Text;

                // the cbRequireApproval will be hidden if contentChannelType.DisableStatus == True
                contentChannel.RequiresApproval          = cbRequireApproval.Visible && cbRequireApproval.Checked;
                contentChannel.IsIndexEnabled            = cbIndexChannel.Checked;
                contentChannel.ItemsManuallyOrdered      = cbItemsManuallyOrdered.Checked;
                contentChannel.ChildItemsManuallyOrdered = cbChildItemsManuallyOrdered.Checked;
                contentChannel.EnableRss         = cbEnableRss.Checked;
                contentChannel.ChannelUrl        = tbChannelUrl.Text;
                contentChannel.TimeToLive        = nbTimetoLive.Text.AsIntegerOrNull();
                contentChannel.ItemUrl           = tbContentChannelItemPublishingPoint.Text;
                contentChannel.IsTaggingEnabled  = cbEnableTag.Checked;
                contentChannel.ItemTagCategoryId = cbEnableTag.Checked ? cpCategory.SelectedValueAsInt() : ( int? )null;

                // Add any categories
                contentChannel.Categories.Clear();
                foreach (var categoryId in cpCategories.SelectedValuesAsInt())
                {
                    contentChannel.Categories.Add(categoryService.Get(categoryId));
                }

                // Since changes to Categories isn't tracked by ChangeTracker, set the ModifiedDateTime just in case Categories changed
                contentChannel.ModifiedDateTime = RockDateTime.Now;

                contentChannel.ChildContentChannels = new List <ContentChannel>();
                contentChannel.ChildContentChannels.Clear();
                foreach (var item in ChildContentChannelsList)
                {
                    var childContentChannel = contentChannelService.Get(item);
                    if (childContentChannel != null)
                    {
                        contentChannel.ChildContentChannels.Add(childContentChannel);
                    }
                }

                contentChannel.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentChannel);

                if (!Page.IsValid || !contentChannel.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentChannel.SaveAttributeValues(rockContext);

                    foreach (var item in new ContentChannelItemService(rockContext)
                             .Queryable()
                             .Where(i =>
                                    i.ContentChannelId == contentChannel.Id &&
                                    i.ContentChannelTypeId != contentChannel.ContentChannelTypeId
                                    ))
                    {
                        item.ContentChannelTypeId = contentChannel.ContentChannelTypeId;
                    }

                    rockContext.SaveChanges();

                    // Save the Item Attributes
                    int entityTypeId = EntityTypeCache.Get(typeof(ContentChannelItem)).Id;
                    SaveAttributes(contentChannel.Id, entityTypeId, ItemAttributesState, rockContext);
                });

                var pageReference = RockPage.PageReference;
                pageReference.Parameters.AddOrReplace("ContentChannelId", contentChannel.Id.ToString());
                Response.Redirect(pageReference.BuildUrl(), false);
            }
        }
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                if (contextEntity is Person)
                {
                    var personService = new PersonService(rockContext);
                    var changes       = new History.HistoryChangeList();
                    var _person       = personService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _person.ForeignKey, tbForeignKey.Text);
                    _person.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _person.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _person.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _person.ForeignId.ToString(), tbForeignId.Text);
                    _person.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(Person),
                                Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
                                _person.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is FinancialAccount)
                {
                    var accountService = new FinancialAccountService(rockContext);
                    var _account       = accountService.Get(contextEntity.Id);

                    _account.ForeignKey  = tbForeignKey.Text;
                    _account.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _account.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is FinancialBatch)
                {
                    var batchService = new FinancialBatchService(rockContext);
                    var changes      = new History.HistoryChangeList();
                    var _batch       = batchService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _batch.ForeignKey, tbForeignKey.Text);
                    _batch.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _batch.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _batch.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _batch.ForeignId.ToString(), tbForeignId.Text);
                    _batch.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(FinancialBatch),
                                Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(),
                                _batch.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is FinancialPledge)
                {
                    var pledgeService = new FinancialPledgeService(rockContext);
                    var _pledge       = pledgeService.Get(contextEntity.Id);

                    _pledge.ForeignKey  = tbForeignKey.Text;
                    _pledge.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _pledge.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is FinancialTransaction)
                {
                    var transactionService = new FinancialTransactionService(rockContext);
                    var changes            = new History.HistoryChangeList();
                    var _transaction       = transactionService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _transaction.ForeignKey, tbForeignKey.Text);
                    _transaction.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _transaction.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _transaction.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _transaction.ForeignId.ToString(), tbForeignId.Text);
                    _transaction.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(FinancialTransaction),
                                Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(),
                                _transaction.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is FinancialScheduledTransaction)
                {
                    var transactionScheduledService = new FinancialScheduledTransactionService(rockContext);
                    var _scheduledTransaction       = transactionScheduledService.Get(contextEntity.Id);

                    _scheduledTransaction.ForeignKey  = tbForeignKey.Text;
                    _scheduledTransaction.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _scheduledTransaction.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is Group)
                {
                    var groupService = new GroupService(rockContext);
                    var _group       = groupService.Get(contextEntity.Id);

                    _group.ForeignKey  = tbForeignKey.Text;
                    _group.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _group.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is GroupMember)
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var changes            = new History.HistoryChangeList();
                    var _groupMember       = groupMemberService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _groupMember.ForeignKey, tbForeignKey.Text);
                    _groupMember.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _groupMember.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _groupMember.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _groupMember.ForeignId.ToString(), tbForeignId.Text);
                    _groupMember.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(GroupMember),
                                Rock.SystemGuid.Category.HISTORY_PERSON_GROUP_MEMBERSHIP.AsGuid(),
                                _groupMember.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is Metric)
                {
                    var metricService = new MetricService(rockContext);
                    var _metric       = metricService.Get(contextEntity.Id);

                    _metric.ForeignKey  = tbForeignKey.Text;
                    _metric.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _metric.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is Location)
                {
                    var locationService = new LocationService(rockContext);
                    var _location       = locationService.Get(contextEntity.Id);

                    _location.ForeignKey  = tbForeignKey.Text;
                    _location.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _location.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is PrayerRequest)
                {
                    var prayerRequestService = new PrayerRequestService(rockContext);
                    var _request             = prayerRequestService.Get(contextEntity.Id);

                    _request.ForeignKey  = tbForeignKey.Text;
                    _request.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _request.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is ContentChannel)
                {
                    var contentChannelService = new ContentChannelService(rockContext);
                    var _channel = contentChannelService.Get(contextEntity.Id);

                    _channel.ForeignKey  = tbForeignKey.Text;
                    _channel.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _channel.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is ContentChannelItem)
                {
                    var contentChannelItemService = new ContentChannelItemService(rockContext);
                    var _item = contentChannelItemService.Get(contextEntity.Id);

                    _item.ForeignKey  = tbForeignKey.Text;
                    _item.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _item.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
            });

            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }
예제 #6
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var            rockContext = new RockContext();
            ContentChannel contentChannel;

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);

            int contentChannelId = hfId.Value.AsInteger();

            if (contentChannelId == 0)
            {
                contentChannel = new ContentChannel {
                    Id = 0
                };
                contentChannelService.Add(contentChannel);
            }
            else
            {
                contentChannel = contentChannelService.Get(contentChannelId);
            }

            if (contentChannel != null)
            {
                contentChannel.Name                      = tbName.Text;
                contentChannel.Description               = tbDescription.Text;
                contentChannel.ContentChannelTypeId      = ddlChannelType.SelectedValueAsInt() ?? 0;
                contentChannel.ContentControlType        = ddlContentControlType.SelectedValueAsEnum <ContentControlType>();
                contentChannel.RootImageDirectory        = tbRootImageDirectory.Visible ? tbRootImageDirectory.Text : string.Empty;
                contentChannel.IconCssClass              = tbIconCssClass.Text;
                contentChannel.RequiresApproval          = cbRequireApproval.Checked;
                contentChannel.ItemsManuallyOrdered      = cbItemsManuallyOrdered.Checked;
                contentChannel.ChildItemsManuallyOrdered = cbChildItemsManuallyOrdered.Checked;
                contentChannel.EnableRss                 = cbEnableRss.Checked;
                contentChannel.ChannelUrl                = tbChannelUrl.Text;
                contentChannel.ItemUrl                   = tbItemUrl.Text;
                contentChannel.TimeToLive                = nbTimetoLive.Text.AsIntegerOrNull();

                contentChannel.ChildContentChannels = new List <ContentChannel>();
                contentChannel.ChildContentChannels.Clear();
                foreach (var item in ChildContentChannelsList)
                {
                    var childContentChannel = contentChannelService.Get(item);
                    if (childContentChannel != null)
                    {
                        contentChannel.ChildContentChannels.Add(childContentChannel);
                    }
                }

                contentChannel.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentChannel);

                if (!Page.IsValid || !contentChannel.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentChannel.SaveAttributeValues(rockContext);

                    foreach (var item in new ContentChannelItemService(rockContext)
                             .Queryable()
                             .Where(i =>
                                    i.ContentChannelId == contentChannel.Id &&
                                    i.ContentChannelTypeId != contentChannel.ContentChannelTypeId
                                    ))
                    {
                        item.ContentChannelTypeId = contentChannel.ContentChannelTypeId;
                    }

                    rockContext.SaveChanges();

                    // Save the Item Attributes
                    int entityTypeId = EntityTypeCache.Read(typeof(ContentChannelItem)).Id;
                    SaveAttributes(contentChannel.Id, entityTypeId, ItemAttributesState, rockContext);
                });

                var pageReference = RockPage.PageReference;
                pageReference.Parameters.AddOrReplace("contentChannelId", contentChannel.Id.ToString());
                Response.Redirect(pageReference.BuildUrl(), false);
            }
        }
예제 #7
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var output = RockCache.Get("TimedContentChannel_" + this.BlockId.ToString());
                if (output != null)
                {
                    ltOutput.Text = output as string;
                    return;
                }

                RockContext           rockContext           = new RockContext();
                ContentChannelService contentChannelService = new ContentChannelService(rockContext);
                ScheduleService       scheduleService       = new ScheduleService(rockContext);

                var cacheLength = GetAttributeValue("MaximumCache").AsDouble();

                var contentChannelGuid = GetAttributeValue("ContentChannel").AsGuid();
                var contentChannel     = contentChannelService.Get(contentChannelGuid);
                if (contentChannel == null)
                {
                    return;
                }
                var contentChannelItems = contentChannel.Items.OrderBy(i => i.Order).ToList();
                List <ContentChannelItem> mergeItems = new List <ContentChannelItem>();
                var scheduleKey = GetAttributeValue("TimerAttributeKey");
                foreach (var item in contentChannelItems)
                {
                    item.LoadAttributes();
                    var scheduleValue = item.GetAttributeValue(scheduleKey);
                    if (scheduleValue.IsNotNullOrWhiteSpace())
                    {
                        var schedule = scheduleService.Get(scheduleValue.AsGuid());
                        if (schedule == null)
                        {
                            continue;
                        }

                        if (schedule.WasScheduleActive(Rock.RockDateTime.Now))
                        {
                            mergeItems.Add(item);
                            var end        = schedule.GetCalendarEvent().DTEnd.TimeOfDay;
                            var endMinutes = (end - Rock.RockDateTime.Now.TimeOfDay).TotalSeconds;
                            cacheLength = Math.Min(cacheLength, endMinutes);
                        }
                        else
                        {
                            var nextTime = schedule.GetNextStartDateTime(Rock.RockDateTime.Now);
                            if (nextTime.HasValue)
                            {
                                var time    = nextTime.Value - Rock.RockDateTime.Now;
                                var minutes = time.TotalSeconds;
                                cacheLength = Math.Min(cacheLength, minutes);
                            }
                        }
                    }
                    else
                    {
                        mergeItems.Add(item);
                    }
                }
                var lava        = GetAttributeValue("Lava");
                var mergefields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, CurrentPerson);
                mergefields.Add("ContentChannelItems", mergeItems);
                lava          = lava.ResolveMergeFields(mergefields, CurrentPerson, GetAttributeValue("EnabledLavaCommands"));
                ltOutput.Text = lava;
                if (cacheLength > 5)   //the time could be low enough to throw an error
                {
                    RockCache.AddOrUpdate("TimedContentChannel_" + this.BlockId.ToString(), "", lava, Rock.RockDateTime.Now.AddSeconds(cacheLength));
                }
            }
        }
        public SlidesResponse GetSlides(string id)
        {
            var rockContext           = new RockContext();
            var deviceService         = new DeviceService(rockContext);
            var scheduleService       = new ScheduleService(rockContext);
            var contentChannelService = new ContentChannelService(rockContext);
            var response = new SlidesResponse();

            Device device = deviceService.Get(id.AsInteger());

            if (device != null)
            {
                var campuses = device.Locations.Select(l => l.CampusId).Where(c => c.HasValue && c.Value != 0).Select(c => c.Value).ToList();

                device.LoadAttributes(rockContext);
                var definedValueGuids = device.GetAttributeValue("com_shepherdchurch_ContentSchedules").SplitDelimitedValues().AsGuidList();
                List <DefinedValueCache> definedValues = new List <DefinedValueCache>();

                //
                // Build a list of the cached defined values so we can then sort by Order.
                //
                foreach (var definedValueGuid in definedValueGuids)
                {
                    var definedValue = DefinedValueCache.Get(definedValueGuid);

                    if (definedValue != null)
                    {
                        definedValues.Add(definedValue);
                    }
                }

                //
                // Check each defined value they have selected on this device and look for the
                // first one that is active.
                //
                foreach (var definedValue in definedValues.OrderBy(d => d.Order))
                {
                    var contentChannel = contentChannelService.Get(definedValue.GetAttributeValue("com_shepherdchurch_ContentChannel").AsGuid());

                    if (contentChannel != null)
                    {
                        var  schedules      = definedValue.GetAttributeValues("com_shepherdchurch_Schedules").AsGuidList();
                        bool scheduleActive = false;

                        //
                        // Check if either no schedules (match by default) or any single schedule
                        // is currently active.
                        //
                        if (!schedules.Any())
                        {
                            scheduleActive = true;
                        }
                        else
                        {
                            foreach (var guid in schedules)
                            {
                                var schedule = scheduleService.Get(guid);

                                if (schedule.WasScheduleActive(RockDateTime.Now))
                                {
                                    scheduleActive = true;
                                    break;
                                }
                            }
                        }

                        //
                        // If the schedule is active, then this is the content channel we are going
                        // to work with. Build our list of image URLs and audio URLs.
                        //
                        if (scheduleActive)
                        {
                            response.Contents = GetContentChannelItems(campuses, contentChannel, rockContext);

                            break;
                        }
                    }
                }

                response.GenerateHash();
            }

            return(response);
        }
예제 #9
0
        public void Execute(IJobExecutionContext context)
        {
            int storyCount    = 0;
            int newStoryCount = 0;

            JobDataMap dataMap = context.JobDetail.JobDataMap;

            List <Story>              stories                   = new List <Story>();
            RockContext               rockContext               = new RockContext();
            ContentChannelService     contentChannelService     = new ContentChannelService(rockContext);
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);
            BinaryFileService         binaryFileService         = new BinaryFileService(rockContext);
            BinaryFileType            binaryFileType            = new BinaryFileTypeService(rockContext).Get(Rock.SystemGuid.BinaryFiletype.MEDIA_FILE.AsGuid());
            var storiesSeriesChannel = contentChannelService.Get(dataMap.GetString("StoriesContentChannel").AsGuid());

            var dbCon = DBConnection.Instance();

            dbCon.DatabaseName = "secccp_main";
            if (dbCon.IsConnect())
            {
                stories = GetStories(dbCon);

                foreach (var story in stories)
                {
                    storyCount++;
                    var item = contentChannelItemService.Queryable().Where(i => i.ForeignId == story.id && i.ContentChannelId == storiesSeriesChannel.Id).FirstOrDefault();
                    if (item == null)
                    {
                        newStoryCount++;
                        item = new ContentChannelItem()
                        {
                            ContentChannelId     = storiesSeriesChannel.Id,
                            ForeignId            = story.id,
                            ContentChannelTypeId = storiesSeriesChannel.ContentChannelTypeId
                        };
                        contentChannelItemService.Add(item);
                    }
                    item.Title         = story.title;
                    item.Content       = story.description;
                    item.StartDateTime = Helpers.FromUnixTime(story.datecreated);
                    rockContext.SaveChanges();

                    item.LoadAttributes();
                    item.SetAttributeValue("Slug", story.slug);
                    item.SetAttributeValue("VimeoId", story.vimeo_id);
                    item.SetAttributeValue("VimeoStreamingUrl", story.vimeo_live_url);
                    item.SetAttributeValue("VimeoDownloadUrl", story.vimeo_sd_url);
                    item.SetAttributeValue("Tags", story.tags);
                    item.SetAttributeValue("Duration", story.duration);

                    if (string.IsNullOrWhiteSpace(item.GetAttributeValue("Image")))
                    {
                        WebClient client = new WebClient();
                        try
                        {
                            using (MemoryStream stream = new MemoryStream(client.DownloadData(string.Format("http://panel.secc.org/upload/stories/cover-images/story-{0}.jpg", story.id))))
                            {
                                BinaryFile binaryFile = new BinaryFile();
                                binaryFileService.Add(binaryFile);
                                binaryFile.IsTemporary      = false;
                                binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                binaryFile.MimeType         = "image/jpg";
                                binaryFile.FileName         = string.Format("Story-{0}.jpg", story.id);
                                binaryFile.ContentStream    = stream;
                                rockContext.SaveChanges();
                                item.SetAttributeValue("Image", binaryFile.Guid.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            var a = ex;
                        }
                    }

                    item.SaveAttributeValues();
                }
            }
            context.Result = string.Format("Synced {0} sermons ({1} New Sermon)", storyCount, newStoryCount);
        }
        public IHttpActionResult ChannelItems(int contentChannelId, string tag = "", int take = 20, int page = 0, bool hideInactive = false,
                                              string orderby = "StartDateTime", bool reverse  = false)
        {
            var cacheKey = Request.RequestUri.ToString();

            RockContext rockContext = new RockContext();
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);
            ContentChannelService     contentChannelService     = new ContentChannelService(rockContext);
            var contentChannel = contentChannelService.Get(contentChannelId);

            if (!contentChannel.IsAuthorized(Rock.Security.Authorization.VIEW, GetPerson()))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var contentItems = contentChannelItemService.Queryable().Where(c => c.ContentChannelId == contentChannelId);

            if (hideInactive)
            {
                contentItems = contentItems.Where(i => i.Status == ContentChannelItemStatus.Approved);
            }

            if (tag.IsNotNullOrWhiteSpace())
            {
                TagService tagService      = new TagService(rockContext);
                var        taggedItemGuids = tagService.Queryable().Where(i => i.EntityTypeId == contentChanelItemEntityTypeId && i.Name == tag)
                                             .SelectMany(t => t.TaggedItems).Select(ti => ti.EntityGuid);
                contentItems = contentItems.Where(c => taggedItemGuids.Contains(c.Guid));
            }

            if (reverse)
            {
                contentItems = contentItems.OrderByDescending(orderby);
            }
            else
            {
                contentItems = contentItems.OrderBy(orderby);
            }

            var contentChannelTypeId  = contentChannel.ContentChannelTypeId.ToString();
            var contentChanelIdString = contentChannel.Id.ToString();

            var attributeQry = new AttributeService(rockContext).Queryable()
                               .Where(a => a.EntityTypeId == contentChanelItemEntityTypeId &&
                                      ((a.EntityTypeQualifierColumn == "ContentChannelTypeId" && a.EntityTypeQualifierValue == contentChannelTypeId) ||
                                       (a.EntityTypeQualifierColumn == "ContentChannelId" && a.EntityTypeQualifierValue == contentChanelIdString)))
            ;

            var attributeValueQry = new AttributeValueService(rockContext).Queryable()
                                    .Where(av => attributeQry.Select(a => a.Id).Contains(av.AttributeId));

            //AttributeFiltering
            var ignoreKeys = new List <string> {
                "contentchannelid", "tag", "take", "page", "hideInactive", "orderby", "reverse"
            };

            var urlKeyValues = ControllerContext.Request.GetQueryNameValuePairs();

            foreach (var pair in urlKeyValues)
            {
                if (!ignoreKeys.Contains(pair.Key.ToLower()))
                {
                    var filterQry = new AttributeValueService(rockContext).Queryable()
                                    .Where(av => attributeQry.Where(a => a.Key == pair.Key).Select(a => a.Id).Contains(av.AttributeId))
                                    .Where(av => av.Value == pair.Value);

                    contentItems = contentItems.Where(i => filterQry.Select(av => av.EntityId).Contains(i.Id));
                }
            }

            //Pagination
            if (page > 0)
            {
                var skip = (page - 1) * take;
                contentItems = contentItems.Skip(skip);
                contentItems = contentItems.Take(take);
            }

            //Join attributes and other content channel items
            var complex = contentItems
                          .GroupJoin(attributeValueQry,
                                     i => i.Id,
                                     av => av.EntityId,
                                     (i, av) => new
            {
                ContentChanelItem = i,
                Children          = i.ChildItems.OrderBy(ci => ci.Order).Select(ci => ci.ChildContentChannelItemId),
                ParentItems       = i.ParentItems.Select(ci => ci.ContentChannelItemId),
                AttributeValues   = av
            });

            var items = complex.ToList()
                        .Select(i => new ChannelItem
            {
                Id          = i.ContentChanelItem.Id,
                DateTime    = i.ContentChanelItem.StartDateTime,
                Title       = i.ContentChanelItem.Title,
                Content     = i.ContentChanelItem.Content,
                Priority    = i.ContentChanelItem.Priority,
                Order       = i.ContentChanelItem.Order,
                Attributes  = i.AttributeValues.ToDictionary(a => a.AttributeKey, a => a.Value),
                Tags        = GetTags(i.ContentChanelItem, rockContext),
                Slug        = i.ContentChanelItem.PrimarySlug,
                CreatedBy   = i.ContentChanelItem.CreatedByPersonName,
                ChildItems  = i.Children.ToList(),
                ParentItems = i.ParentItems.ToList()
            }).ToList();

            return(Json(items));
        }
예제 #11
0
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            int sermonCount    = 0;
            int newSermonCount = 0;

            List <SermonSeries>       sermonSeries              = new List <SermonSeries>();
            RockContext               rockContext               = new RockContext();
            ContentChannelService     contentChannelService     = new ContentChannelService(rockContext);
            ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext);
            BinaryFileService         binaryFileService         = new BinaryFileService(rockContext);
            BinaryFileType            binaryFileType            = new BinaryFileTypeService(rockContext).Get(Rock.SystemGuid.BinaryFiletype.MEDIA_FILE.AsGuid());
            var sermonSeriesChannel = contentChannelService.Get(dataMap.GetString("SermonSeriesContentChannel").AsGuid());
            var sermonChannel       = contentChannelService.Get(dataMap.GetString("SermonContentChannel").AsGuid());

            var dbCon = DBConnection.Instance();

            dbCon.DatabaseName = "secccp_main";
            if (dbCon.IsConnect())
            {
                sermonSeries = GetSermonSeries(dbCon);

                foreach (var series in sermonSeries.Where(s => s.deleted == false))
                {
                    AddSermons(dbCon, series);
                    var item = contentChannelItemService.Queryable().Where(i => i.ForeignId == series.id && i.ContentChannelId == sermonSeriesChannel.Id).FirstOrDefault();
                    if (item == null)
                    {
                        item = new ContentChannelItem()
                        {
                            ContentChannelId     = sermonSeriesChannel.Id,
                            ForeignId            = series.id,
                            ContentChannelTypeId = sermonSeriesChannel.ContentChannelTypeId
                        };
                        contentChannelItemService.Add(item);
                    }
                    item.Title   = series.title;
                    item.Content = series.description.Replace("\n", "").Replace("\r", "");
                    if (series.sermons.Any())
                    {
                        item.StartDateTime = Helpers.FromUnixTime(series.sermons.FirstOrDefault().date);
                    }
                    else
                    {
                        item.StartDateTime = Rock.RockDateTime.Now;
                    }

                    rockContext.SaveChanges();
                    item.LoadAttributes();
                    item.SetAttributeValue("Slug", series.slug);

                    if (string.IsNullOrWhiteSpace(item.GetAttributeValue("Image")))
                    {
                        WebClient client = new WebClient();
                        try
                        {
                            using (MemoryStream stream = new MemoryStream(client.DownloadData(string.Format("http://files.secc.org/sermons/series/series-{0}.jpg", series.id))))
                            {
                                BinaryFile binaryFile = new BinaryFile();
                                binaryFileService.Add(binaryFile);
                                binaryFile.IsTemporary      = false;
                                binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                binaryFile.MimeType         = "image/jpg";
                                binaryFile.FileName         = string.Format("Series-{0}.jpg", series.id);
                                binaryFile.ContentStream    = stream;
                                rockContext.SaveChanges();
                                item.SetAttributeValue("Image", binaryFile.Guid.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            var a = ex;
                        }
                    }

                    item.SaveAttributeValues();
                }
                foreach (var series in sermonSeries.Where(ss => !ss.deleted))
                {
                    //add in sermons
                    foreach (var sermon in series.sermons.Where(s => !s.deleted))
                    {
                        sermonCount++;
                        var child = contentChannelItemService.Queryable().Where(i => i.ForeignId == sermon.id && i.ContentChannelId == sermonChannel.Id).FirstOrDefault();
                        if (child == null)
                        {
                            newSermonCount++;
                            child = new ContentChannelItem()
                            {
                                ContentChannelId     = sermonChannel.Id,
                                ForeignId            = sermon.id,
                                ContentChannelTypeId = sermonChannel.ContentChannelTypeId,
                                StartDateTime        = Helpers.FromUnixTime(sermon.date)
                            };
                            contentChannelItemService.Add(child);
                            rockContext.SaveChanges();
                            var item = contentChannelItemService.Queryable().Where(i => i.ForeignId == series.id).FirstOrDefault();
                            item.ChildItems.Add(new ContentChannelItemAssociation
                            {
                                ContentChannelItemId      = item.Id,
                                ChildContentChannelItemId = child.Id,
                            });
                            rockContext.SaveChanges();
                        }
                        child.Title         = sermon.title;
                        child.Content       = sermon.description.Replace("\n", "").Replace("\r", "");
                        child.StartDateTime = Helpers.FromUnixTime(sermon.date);
                        rockContext.SaveChanges();
                        child.LoadAttributes();
                        child.SetAttributeValue("Slug", sermon.slug);
                        child.SetAttributeValue("Speaker", sermon.speaker);
                        child.SetAttributeValue("Duration", sermon.duration);
                        child.SetAttributeValue("VimeoId", sermon.vimeo_id);
                        child.SetAttributeValue("VimeoDownloadUrl", sermon.vimeo_sd_url);
                        child.SetAttributeValue("VimeoStreamingUrl", sermon.vimeo_live_url);

                        if (string.IsNullOrWhiteSpace(child.GetAttributeValue("Image")))
                        {
                            WebClient client = new WebClient();
                            try
                            {
                                using (MemoryStream stream = new MemoryStream(client.DownloadData(string.Format("http://panel.secc.org/upload/sermon/images/images-{0}.jpg", sermon.id))))
                                {
                                    BinaryFile binaryFile = new BinaryFile();
                                    binaryFileService.Add(binaryFile);
                                    binaryFile.IsTemporary      = false;
                                    binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                    binaryFile.MimeType         = "image/jpg";
                                    binaryFile.FileName         = string.Format("Sermon-{0}.jpg", series.id);
                                    binaryFile.ContentStream    = stream;
                                    rockContext.SaveChanges();
                                    child.SetAttributeValue("Image", binaryFile.Guid.ToString());
                                }
                            }
                            catch (Exception ex)
                            {
                                var a = ex;
                            }
                        }

                        if (string.IsNullOrWhiteSpace(child.GetAttributeValue("Audio")))
                        {
                            try
                            {
                                using (WebClient client = new WebClient())
                                {
                                    using (MemoryStream stream = new MemoryStream(client.DownloadData(sermon.audio_link)))
                                    {
                                        BinaryFile binaryFile = new BinaryFile();
                                        binaryFileService.Add(binaryFile);
                                        binaryFile.IsTemporary      = false;
                                        binaryFile.BinaryFileTypeId = binaryFileType.Id;
                                        binaryFile.MimeType         = "audio/mpeg";
                                        binaryFile.FileName         = string.Format("Sermon-{0}.mp3", sermon.id);
                                        binaryFile.ContentStream    = stream;
                                        rockContext.SaveChanges();
                                        child.SetAttributeValue("Audio", binaryFile.Guid.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                var a = ex;
                            }
                        }


                        child.SaveAttributeValues();
                    }
                }
            }
            context.Result = string.Format("Synced {0} sermons ({1} New Sermon)", sermonCount, newSermonCount);
        }