public IQueryable <ContentChannelItem> GetByCurrentPerson(string contentChannelIds) { // Split the given string of Content Channel Ids into a list and query for // Content Channel Items inside of those Content Channels List <int> contentChannelIdList = contentChannelIds.Split(',').Select(int.Parse).ToList(); // If no Content Channel Ids were given, just return an empty result so make // life easier for Rock if (contentChannelIdList.Count < 1) { return(Enumerable.Empty <ContentChannelItem>().AsQueryable()); } // Get current person and set up the proxy for querying var person = GetPerson(); RockContext rockContext = new RockContext(); rockContext.Configuration.ProxyCreationEnabled = false; // Get all Content Channel Items for the given Content Channels IQueryable <ContentChannelItem> contentChannelItemlist = new ContentChannelItemService(rockContext) .Queryable() .AsNoTracking() .Where(item => contentChannelIdList.Contains(item.ContentChannelId)); // Filter results by the current person's permission return(contentChannelItemlist .ToList() .Where(item => item.IsAuthorized(Rock.Security.Authorization.VIEW, person)) .AsQueryable()); }
private List <ContentChannelItem> GetItems(RockContext rockContext, ContentChannel selectedChannel, out bool isFiltered) { isFiltered = false; var items = new List <ContentChannelItem>(); var itemQry = new ContentChannelItemService(rockContext).Queryable() .Where(i => i.ContentChannelId == selectedChannel.Id); var drp = new DateRangePicker(); drp.DelimitedValues = gfFilter.GetUserPreference("Date Range"); if (drp.LowerValue.HasValue) { isFiltered = true; if (selectedChannel.ContentChannelType.DateRangeType == ContentChannelDateType.SingleDate) { itemQry = itemQry.Where(i => i.StartDateTime >= drp.LowerValue.Value); } else { itemQry = itemQry.Where(i => i.ExpireDateTime.HasValue && i.ExpireDateTime.Value >= drp.LowerValue.Value); } } if (drp.UpperValue.HasValue) { isFiltered = true; DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1); itemQry = itemQry.Where(i => i.StartDateTime <= upperDate); } var status = gfFilter.GetUserPreference("Status").ConvertToEnumOrNull <ContentChannelItemStatus>(); if (status.HasValue) { isFiltered = true; itemQry = itemQry.Where(i => i.Status == status); } string title = gfFilter.GetUserPreference("Title"); if (!string.IsNullOrWhiteSpace(title)) { isFiltered = true; itemQry = itemQry.Where(i => i.Title.Contains(title)); } int?personId = gfFilter.GetUserPreference("Created By").AsIntegerOrNull(); if (personId.HasValue && personId.Value != 0) { isFiltered = true; itemQry = itemQry.Where(i => i.CreatedByPersonAlias.PersonId == personId); } // Filter query by any configured attribute filters if (AvailableAttributes != null && AvailableAttributes.Any()) { var attributeValueService = new AttributeValueService(rockContext); var parameterExpression = attributeValueService.ParameterExpression; foreach (var attribute in AvailableAttributes) { var filterControl = phAttributeFilters.FindControl("filter_" + attribute.Id.ToString()); if (filterControl == null) { continue; } var filterValues = attribute.FieldType.Field.GetFilterValues(filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter); var filterIsDefault = attribute.FieldType.Field.IsEqualToValue(filterValues, attribute.DefaultValue); var expression = attribute.FieldType.Field.AttributeFilterExpression(attribute.QualifierValues, filterValues, parameterExpression); if (expression == null) { continue; } var attributeValues = attributeValueService .Queryable() .Where(v => v.Attribute.Id == attribute.Id); var filteredAttributeValues = attributeValues.Where(parameterExpression, expression, null); isFiltered = true; if (filterIsDefault) { itemQry = itemQry.Where(w => !attributeValues.Any(v => v.EntityId == w.Id) || filteredAttributeValues.Select(v => v.EntityId).Contains(w.Id)); } else { itemQry = itemQry.Where(w => filteredAttributeValues.Select(v => v.EntityId).Contains(w.Id)); } } } foreach (var item in itemQry.ToList()) { if (item.IsAuthorized(Rock.Security.Authorization.VIEW, CurrentPerson)) { items.Add(item); } else { isFiltered = true; } } if (selectedChannel.ItemsManuallyOrdered && !isFiltered) { return(items.OrderBy(i => i.Order).ToList()); } else { return(items); } }
private List<ContentChannelItem> GetItems( RockContext rockContext, ContentChannel selectedChannel, out bool isFiltered ) { isFiltered = false; var items = new List<ContentChannelItem>(); var itemQry = new ContentChannelItemService( rockContext ).Queryable() .Where( i => i.ContentChannelId == selectedChannel.Id ); var drp = new DateRangePicker(); drp.DelimitedValues = gfFilter.GetUserPreference( "Date Range" ); if ( drp.LowerValue.HasValue ) { isFiltered = true; if ( selectedChannel.ContentChannelType.DateRangeType == ContentChannelDateType.SingleDate ) { itemQry = itemQry.Where( i => i.StartDateTime >= drp.LowerValue.Value ); } else { itemQry = itemQry.Where( i => i.ExpireDateTime.HasValue && i.ExpireDateTime.Value >= drp.LowerValue.Value ); } } if ( drp.UpperValue.HasValue ) { isFiltered = true; DateTime upperDate = drp.UpperValue.Value.Date.AddDays( 1 ); itemQry = itemQry.Where( i => i.StartDateTime <= upperDate ); } var status = gfFilter.GetUserPreference( "Status" ).ConvertToEnumOrNull<ContentChannelItemStatus>(); if ( status.HasValue ) { isFiltered = true; itemQry = itemQry.Where( i => i.Status == status ); } string title = gfFilter.GetUserPreference( "Title" ); if ( !string.IsNullOrWhiteSpace( title ) ) { isFiltered = true; itemQry = itemQry.Where( i => i.Title.Contains( title ) ); } int? personId = gfFilter.GetUserPreference( "Created By" ).AsIntegerOrNull(); if ( personId.HasValue && personId.Value != 0 ) { isFiltered = true; itemQry = itemQry.Where( i => i.CreatedByPersonAlias.PersonId == personId ); } // Filter query by any configured attribute filters if ( AvailableAttributes != null && AvailableAttributes.Any() ) { var attributeValueService = new AttributeValueService( rockContext ); var parameterExpression = attributeValueService.ParameterExpression; foreach ( var attribute in AvailableAttributes ) { var filterControl = phAttributeFilters.FindControl( "filter_" + attribute.Id.ToString() ); if ( filterControl != null ) { var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter ); var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression ); if ( expression != null ) { var attributeValues = attributeValueService .Queryable() .Where( v => v.Attribute.Id == attribute.Id ); attributeValues = attributeValues.Where( parameterExpression, expression, null ); isFiltered = true; itemQry = itemQry.Where( w => attributeValues.Select( v => v.EntityId ).Contains( w.Id ) ); } } } } foreach ( var item in itemQry.ToList() ) { if ( item.IsAuthorized( Rock.Security.Authorization.VIEW, CurrentPerson ) ) { items.Add( item ); } else { isFiltered = true; } } if ( selectedChannel.ItemsManuallyOrdered && !isFiltered ) { return items.OrderBy( i => i.Order ).ToList(); } else { return items; } }