public IQueryable <ContentChannelItem> ContentChannelItemsByAttributeValue(int campusId) { RockContext rockContext = new RockContext(); string campusGuid = new CampusService(rockContext).Get(campusId).Guid.ToString(); // Get the Id of the Rock.Model.ContentChannelItem Entity. int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id; // Get the Field Type (Attribute Type) Id of the Data View Field Type. int fieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.CAMPUSES.AsGuid()).Id; // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type // and that are of the Campus field type. List <int> campusAttributeIdList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.FieldTypeId == fieldTypeId) .Select(a => a.Id) .ToList(); List <string> campusAttributeIdKeyList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.FieldTypeId == fieldTypeId) .Select(a => a.Key) .ToList(); var avsWithCampus = new AttributeValueService(rockContext).Queryable() .Where(a => campusAttributeIdList.Contains(a.AttributeId)) .Where(a => a.Attribute.EntityTypeId == contentChannelItemEntityTypeId) .Where(a => a.Value.Contains(campusGuid)) .Select(a => a.EntityId); // I want a list of content channel items whose ids match up to attribute values that represent entity ids IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext) .Queryable() .AsNoTracking() .Where(c => avsWithCampus.Contains(c.Id) || c.Attributes.Keys.Contains(campusAttributeIdKeyList.FirstOrDefault())); // Return this list return(contentChannelItemList); }
public IQueryable <ContentChannelItem> GetFromPersonDataView(string guids) { RockContext rockContext = new RockContext(); // Turn the comma separated list of guids into a list of strings. List <string> guidList = (guids ?? "").Split(',').ToList(); // Get the Id of the Rock.Model.ContentChannelItem Entity. int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id; // Get the Field Type (Attribute Type) Id of the Data View Field Type. int fieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.DATAVIEWS.AsGuid()).Id; // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type // and that are of the Data View field type. List <int> attributeIdList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.FieldTypeId == fieldTypeId) .Select(a => a.Id) .ToList(); // I want a list of content channel items whose ids match up to attribute values that represent entity ids IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext) .Queryable() .WhereAttributeValue(rockContext, av => attributeIdList.Contains(av.AttributeId) && guidList.Contains(av.Value)); // Return this list return(contentChannelItemList); }
public List <RockEventbriteEvent> Events(bool loadEventbriteEvent = false) { var retVar = new List <RockEventbriteEvent>(); var ebFieldType = FieldTypeCache.Get(EBGuid.FieldType.EVENTBRITE_EVENT.AsGuid()); if (ebFieldType != null) { using (RockContext rockContext = new RockContext()) { var attributes = new AttributeService(rockContext).GetByFieldTypeId(ebFieldType.Id).Select(a => a.Id); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(av => attributes.Contains(av.AttributeId) && av.EntityId.HasValue && av.Value != "").Select(av => av.EntityId.Value); var groups = new GroupService(rockContext).GetListByIds(attributeValues.ToList()); foreach (var group in groups) { retVar.Add(new RockEventbriteEvent(group, loadEventbriteEvent)); } } } return(retVar); }
public IQueryable <ContentChannelItem> ContentChannelItemsByAttributeValue(string attributeValues, string attributeKey) { RockContext rockContext = new RockContext(); // Turn the comma separated list of guids into a list of strings. List <string> attributeValueList = (attributeValues ?? "").Split(',').ToList(); // Get the Id of the Rock.Model.ContentChannelItem Entity. int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id; // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type // and that are named the the same as the incoming attributeName List <int> attributeIdList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.Key == attributeKey) .Select(a => a.Id) .ToList(); // I want a list of content channel items whose ids match up to attribute values that represent entity ids IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext) .Queryable() .AsNoTracking() .WhereAttributeValue(rockContext, av => attributeIdList.Contains(av.AttributeId) && attributeValueList.Any(value => av.Value.Contains(value))); // Return this list return(contentChannelItemList); }
public IQueryable <ContentChannelItem> ContentChannelItemsByCampusIdAndAttributeValue(string attributeValues, string attributeKey, int campusId) { var rockContext = new RockContext(); rockContext.Configuration.ProxyCreationEnabled = false; // Turn the comma separated list of guids into a list of strings. List <string> attributeValueList = (attributeValues ?? "").Split(',').ToList(); string campusGuid = new CampusService(rockContext).Get(campusId).Guid.ToString(); // Get the Id of the Rock.Model.ContentChannelItem Entity. int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id; // Get the Field Type (Attribute Type) Id of the Data View Field Type. int fieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.CAMPUSES.AsGuid()).Id; // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type // and that are of the Campus field type. List <int> campusAttributeIdList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.FieldTypeId == fieldTypeId) .Select(a => a.Id) .ToList(); // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type // and that are named the the same as the incoming attributeName List <int> attributeIdList = new AttributeService(rockContext) .GetByEntityTypeId(contentChannelItemEntityTypeId) .Where(item => item.Key == attributeKey) .Select(a => a.Id) .ToList(); // I want a list of content channel items whose ids match up to attribute values that represent entity ids IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext) .Queryable() .AsNoTracking() .WhereAttributeValue(rockContext, av => campusAttributeIdList.Contains(av.AttributeId) && av.Value.Contains(campusGuid)) .WhereAttributeValue(rockContext, av => attributeIdList.Contains(av.AttributeId) && attributeValueList.Any(value => av.Value.Contains(value))); // Return this list return(contentChannelItemList); }
public IHttpActionResult ChannelItem(string identifier) { RockContext rockContext = new RockContext(); ContentChannelItemService contentChannelItemService = new ContentChannelItemService(rockContext); IQueryable <ContentChannelItem> contentChannelItem; var itemId = identifier.AsInteger(); if (itemId != 0) { contentChannelItem = contentChannelItemService.Queryable().Where(i => i.Id == itemId); } else { //Get by slug ContentChannelItemSlugService contentChannelItemSlugService = new ContentChannelItemSlugService(rockContext); contentChannelItem = contentChannelItemSlugService.Queryable() .Where(s => s.Slug == identifier) .Select(s => s.ContentChannelItem); } var contentChannel = contentChannelItem.Select(i => i.ContentChannel).FirstOrDefault(); if (contentChannel == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (!contentChannel.IsAuthorized(Rock.Security.Authorization.VIEW, GetPerson())) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } 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))) .Select(a => a.Id); var attributeValueQry = new AttributeValueService(rockContext).Queryable().Where(av => attributeQry.Contains(av.AttributeId)); var complex = contentChannelItem .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 }) .ToList(); var items = complex .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.FirstOrDefault())); }