Exemple #1
0
        /// <summary>
        /// 分页获取非主流排序方式的ContentItem
        /// </summary>
        public PagingDataSet <ContentItem> GetContentItemsSortBy(ContentItemSortBy sortBy, int?contentTypeId = null, int?contentFolderId = null, bool includeFolderDescendants = true, string tagName = null, int pageSize = 15, int pageIndex = 1)
        {
            ContentItemQuery query;

            if (contentFolderId.HasValue)
            {
                query = new ContentItemQuery(CacheVersionType.AreaVersion);
                query.AreaCachePropertyName  = "ContentFolderId";
                query.AreaCachePropertyValue = contentFolderId.Value;
                query.ContentFolderId        = contentFolderId;
            }
            else
            {
                query = new ContentItemQuery(CacheVersionType.GlobalVersion);
            }
            query.IncludeFolderDescendants = includeFolderDescendants;
            query.SortBy = sortBy;
            query.PubliclyAuditStatus = new AuditService().GetPubliclyAuditStatus(ApplicationIds.Instance().CMS());
            query.TagName             = tagName;
            if (contentTypeId.HasValue && contentTypeId.Value > 0)
            {
                query.ContentTypeId = contentTypeId;
            }

            return(contentItemRepository.GetContentItems(true, query, pageSize, pageIndex));
        }
Exemple #2
0
        /// <summary>
        /// 删除contentFolderId下的所有ContentItem
        /// </summary>
        /// <param name="contentFolderId"></param>
        public void DeleteByFolder(int contentFolderId)
        {
            ContentItemQuery query = new ContentItemQuery(CacheVersionType.None)
            {
                ContentFolderId = contentFolderId
            };

            PagingDataSet <ContentItem> items = contentItemRepository.GetContentItems(false, query, int.MaxValue, 1);

            foreach (var item in items)
            {
                Delete(item);
            }
        }
Exemple #3
0
        /// <summary>
        /// 分页获取非主流排序方式的ContentItem
        /// </summary>
        public PagingDataSet <ContentItem> GetUserContentItems(long userId, int?contentFolderId = null, PubliclyAuditStatus?publiclyAuditStatus = null, int pageSize = 20, int pageIndex = 1)
        {
            ContentItemQuery query = new ContentItemQuery(CacheVersionType.AreaVersion);

            query.AreaCachePropertyName  = "UserId";
            query.AreaCachePropertyValue = userId;
            query.UserId = userId;
            if (contentFolderId.HasValue && contentFolderId.Value > 0)
            {
                query.ContentFolderId = contentFolderId.Value;
            }
            query.IncludeFolderDescendants = true;
            query.PubliclyAuditStatus      = publiclyAuditStatus;
            return(contentItemRepository.GetContentItems(true, query, pageSize, pageIndex));
        }
Exemple #4
0
        /// <summary>
        /// 依据查询条件获取ContentItem(后台管理员使用)
        /// </summary>
        /// <param name="auditStatus"></param>
        /// <param name="subjectKeyword"></param>
        /// <param name="contentFolderId"></param>
        /// <param name="includeFolderDescendants"></param>
        /// <param name="tagNameKeyword"></param>
        /// <param name="contentTypeId"></param>
        /// <param name="userId"></param>
        /// <param name="isContributed"></param>
        /// <param name="isEssential"></param>
        /// <param name="isSticky"></param>
        /// <param name="minDate"></param>
        /// <param name="maxDate"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public PagingDataSet <ContentItem> GetContentItemsForAdmin(AuditStatus?auditStatus, string subjectKeyword, int?contentFolderId, bool?includeFolderDescendants = true, string tagNameKeyword = null, int?contentTypeId = null, long?userId = null, long?moderatorUserId = null, bool?isContributed = null, bool?isEssential = null, bool?isSticky = null, DateTime?minDate = null, DateTime?maxDate = null, int pageSize = 15, int pageIndex = 1)
        {
            PubliclyAuditStatus?publiclyAuditStatus = null;

            if (auditStatus.HasValue)
            {
                switch (auditStatus.Value)
                {
                case AuditStatus.Again:
                    publiclyAuditStatus = PubliclyAuditStatus.Again;
                    break;

                case AuditStatus.Fail:
                    publiclyAuditStatus = PubliclyAuditStatus.Fail;
                    break;

                case AuditStatus.Success:
                    publiclyAuditStatus = PubliclyAuditStatus.Success;
                    break;

                case AuditStatus.Pending:
                default:
                    publiclyAuditStatus = PubliclyAuditStatus.Pending;
                    break;
                }
            }
            ContentItemQuery query = new ContentItemQuery(CacheVersionType.None)
            {
                ContentFolderId          = contentFolderId,
                IncludeFolderDescendants = includeFolderDescendants,
                ContentTypeId            = contentTypeId,
                UserId              = userId,
                ModeratorUserId     = moderatorUserId,
                IsContributed       = isContributed,
                IsEssential         = isEssential,
                IsSticky            = isSticky,
                SubjectKeyword      = subjectKeyword,
                TagNameKeyword      = tagNameKeyword,
                PubliclyAuditStatus = publiclyAuditStatus,
                SortBy              = ContentItemSortBy.ReleaseDate_Desc,
                MinDate             = minDate,
                MaxDate             = maxDate,
            };

            return(contentItemRepository.GetContentItems(false, query, pageSize, pageIndex));
        }
        /// <summary>
        /// 依据查询条件获取ContentItem列表
        /// </summary>
        public PagingDataSet <ContentItem> GetContentItems(bool enableCaching, ContentItemQuery query, int pageSize, int pageIndex)
        {
            var sql      = Sql.Builder.Select("spb_cms_ContentItems.*").From("spb_cms_ContentItems");
            var whereSql = Sql.Builder;
            var orderSql = Sql.Builder;

            if (query.ContentFolderId.HasValue && query.ContentFolderId.Value > 0)
            {
                if (query.IncludeFolderDescendants.HasValue && query.IncludeFolderDescendants.Value)
                {
                    ContentFolderService        contentFolderService = new ContentFolderService();
                    IEnumerable <ContentFolder> contentFolders       = contentFolderService.GetDescendants(query.ContentFolderId.Value);

                    IEnumerable <int> descendantFolderIds = contentFolders == null ? new List <int>() : contentFolders.Select(f => f.ContentFolderId);

                    List <int> folderIds = new List <int>(descendantFolderIds);
                    folderIds.Add(query.ContentFolderId.Value);

                    whereSql.Where("spb_cms_ContentItems.ContentFolderId in (@ContentFolderIds)", new { ContentFolderIds = folderIds });
                }
                else
                {
                    whereSql.Where("spb_cms_ContentItems.ContentFolderId=@0", query.ContentFolderId.Value);
                }
            }
            else if (query.ModeratorUserId.HasValue && query.ModeratorUserId.Value > 0)
            {
                ContentFolderService          contentFolderService          = new ContentFolderService();
                ContentFolderModeratorService contentFolderModeratorService = new ContentFolderModeratorService();
                IEnumerable <int>             moderatedFolderIds            = contentFolderModeratorService.GetModeratedFolderIds(query.ModeratorUserId.Value);
                List <int> folderIds = new List <int>(moderatedFolderIds);
                if (query.IncludeFolderDescendants.HasValue && query.IncludeFolderDescendants.Value)
                {
                    foreach (var folderId in moderatedFolderIds)
                    {
                        IEnumerable <ContentFolder> contentFolders      = contentFolderService.GetDescendants(folderId);
                        IEnumerable <int>           descendantFolderIds = contentFolders == null ? new List <int>() : contentFolders.Select(f => f.ContentFolderId);
                        folderIds.AddRange(descendantFolderIds);
                    }
                }
                if (folderIds.Count > 0)
                {
                    whereSql.Where("spb_cms_ContentItems.ContentFolderId in (@ContentFolderIds)", new { ContentFolderIds = folderIds });
                }
            }

            if (query.ContentTypeId.HasValue && query.ContentTypeId.Value > 0)
            {
                whereSql.Where("spb_cms_ContentItems.ContentTypeId=@0", query.ContentTypeId.Value);
            }

            if (query.UserId.HasValue && query.UserId.Value > 0)
            {
                whereSql.Where("spb_cms_ContentItems.UserId=@0", query.UserId.Value);
            }

            if (query.IsContributed.HasValue)
            {
                whereSql.Where("spb_cms_ContentItems.IsContributed=@0", query.IsContributed.Value);
            }

            if (query.IsEssential.HasValue)
            {
                whereSql.Where("spb_cms_ContentItems.IsContributed=@0", query.IsEssential.Value);
            }

            if (query.IsSticky.HasValue)
            {
                whereSql.Where("spb_cms_ContentItems.IsGlobalSticky=@0", query.IsSticky.Value);
            }

            query.SubjectKeyword = StringUtility.StripSQLInjection(query.SubjectKeyword);
            if (!string.IsNullOrWhiteSpace(query.SubjectKeyword))
            {
                whereSql.Where("spb_cms_ContentItems.Title like @0", "%" + query.SubjectKeyword + "%");
            }

            query.TagNameKeyword = StringUtility.StripSQLInjection(query.TagNameKeyword);


            if (!string.IsNullOrWhiteSpace(query.TagName) || !string.IsNullOrWhiteSpace(query.TagNameKeyword))
            {
                sql.InnerJoin("tn_ItemsInTags").On("spb_cms_ContentItems.ContentItemId = tn_ItemsInTags.ItemId");
                if (!string.IsNullOrWhiteSpace(query.TagName))
                {
                    whereSql.Where("tn_ItemsInTags.TenantTypeId = @0", TenantTypeIds.Instance().ContentItem())
                    .Where("tn_ItemsInTags.TagName = @0", query.TagName);
                }
                else if (!string.IsNullOrWhiteSpace(query.TagNameKeyword))
                {
                    whereSql.Where("tn_ItemsInTags.TenantTypeId = @0", TenantTypeIds.Instance().ContentItem())
                    .Where("tn_ItemsInTags.TagName like @0", "%" + query.TagNameKeyword + "%");
                }
            }

            if (query.PubliclyAuditStatus.HasValue)
            {
                switch (query.PubliclyAuditStatus)
                {
                case PubliclyAuditStatus.Fail:
                case PubliclyAuditStatus.Pending:
                case PubliclyAuditStatus.Again:
                case PubliclyAuditStatus.Success:
                    whereSql.Where("spb_cms_ContentItems.AuditStatus=@0", (int)query.PubliclyAuditStatus.Value);
                    break;

                case PubliclyAuditStatus.Pending_GreaterThanOrEqual:
                case PubliclyAuditStatus.Again_GreaterThanOrEqual:
                    whereSql.Where("spb_cms_ContentItems.AuditStatus>@0", (int)query.PubliclyAuditStatus.Value);
                    break;

                default:
                    break;
                }
            }

            if (query.MinDate != null)
            {
                whereSql.Where("spb_cms_ContentItems.ReleaseDate >= @0", query.MinDate);
            }
            DateTime maxDate = DateTime.UtcNow;

            if (query.MaxDate != null)
            {
                maxDate = query.MaxDate.Value.AddDays(1);
            }
            whereSql.Where("spb_cms_ContentItems.ReleaseDate < @0", maxDate);

            CountService          countService          = new CountService(TenantTypeIds.Instance().ContentItem());
            string                countTableName        = countService.GetTableName_Counts();
            StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().ContentItem());
            int    stageCountDays = 0;
            string stageCountType = string.Empty;

            switch (query.SortBy)
            {
            case ContentItemSortBy.ReleaseDate_Desc:
                orderSql.OrderBy("spb_cms_ContentItems.IsGlobalSticky desc");
                if (query.ContentFolderId.HasValue && query.ContentFolderId.Value > 0)
                {
                    orderSql.OrderBy("spb_cms_ContentItems.IsFolderSticky desc");
                }
                orderSql.OrderBy("spb_cms_ContentItems.ReleaseDate desc");
                break;

            case ContentItemSortBy.HitTimes:
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes()))
                .On("ContentItemId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case ContentItemSortBy.StageHitTimes:
                stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes());
                stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays);
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType))
                .On("ContentItemId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case ContentItemSortBy.CommentCount:
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().CommentCount()))
                .On("ContentItemId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case ContentItemSortBy.StageCommentCount:
                stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().CommentCount());
                stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().CommentCount(), stageCountDays);
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType))
                .On("ContentItemId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case ContentItemSortBy.DisplayOrder:
                orderSql.OrderBy("spb_cms_ContentItems.DisplayOrder, spb_cms_ContentItems.ContentItemId desc");
                break;

            default:
                orderSql.OrderBy("spb_cms_ContentItems.ReleaseDate desc");
                break;
            }
            sql.Append(whereSql).Append(orderSql);
            PagingDataSet <ContentItem> pds = null;

            if (enableCaching && string.IsNullOrEmpty(query.SubjectKeyword) && string.IsNullOrEmpty(query.TagNameKeyword) && query.MinDate == null && query.MaxDate == null)
            {
                pds = GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                        () =>
                {
                    StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(query));
                    cacheKey.AppendFormat("contentFolderId-{0}:includeFolderDescendants-{1}:contentTypeId-{2}:userId-{3}:isContributed-{4}:isEssential-{5}:isSticky-{6}:PubliclyAuditStatus-{7}:TagName-{8}:ModeratorUserId-{9}",
                                          query.ContentFolderId.ToString(), query.IncludeFolderDescendants.ToString(), query.ContentTypeId.ToString(), query.UserId.ToString(),
                                          query.IsContributed.ToString(), query.IsEssential.ToString(), query.IsSticky.ToString(), query.PubliclyAuditStatus.ToString(), query.TagName, query.ModeratorUserId);

                    return(cacheKey.ToString());
                },
                                        () =>
                {
                    return(sql);
                });
            }
            else
            {
                pds = GetPagingEntities(pageSize, pageIndex, sql);
            }

            return(pds);
        }
Exemple #6
0
        /// <summary>
        /// 把fromFolderId合并到toFolderId
        /// </summary>
        /// <remarks>
        /// 例如:将栏目fromFolderId合并到栏目toFolderId,那么fromFolderId栏目下的所有子栏目和ContentItem全部归到toFolderID栏目,同时删除fromFolderID栏目
        /// </remarks>
        public void Merge(int fromFolderId, int toFolderId)
        {
            ContentFolder toFolder = Get(toFolderId);

            if (toFolder == null)
            {
                return;
            }

            ContentFolder fromFolder = Get(fromFolderId);

            if (fromFolder == null)
            {
                return;
            }

            ContentItemRepository contentItemRepository = new ContentItemRepository();

            foreach (var childSection in fromFolder.Children)
            {
                childSection.ParentId = toFolderId;
                childSection.Depth    = toFolder.Depth + 1;

                if (childSection.Depth == 1)
                {
                    childSection.ParentIdList = childSection.ParentId.ToString();
                }
                else
                {
                    childSection.ParentIdList = toFolder.ParentIdList + "," + childSection.ParentId;
                }

                RecursiveUpdateDepthAndParentIdList(childSection);

                ContentItemQuery contentItemQuery = new ContentItemQuery(CacheVersionType.None)
                {
                    ContentFolderId = childSection.ContentFolderId
                };

                PagingDataSet <ContentItem> contentItems = contentItemRepository.GetContentItems(false, contentItemQuery, int.MaxValue, 1);

                foreach (var contentItem in contentItems)
                {
                    contentItem.ContentFolderId = toFolderId;
                    contentItemRepository.Update(contentItem);
                }
            }

            ContentItemQuery currentContentItemQuery = new ContentItemQuery(CacheVersionType.None)
            {
                ContentFolderId = fromFolderId
            };
            PagingDataSet <ContentItem> currentContentItems = contentItemRepository.GetContentItems(false, currentContentItemQuery, int.MaxValue, 1);

            foreach (var item in currentContentItems)
            {
                item.ContentFolderId = toFolderId;
                contentItemRepository.Update(item);
            }

            if (fromFolder.ParentId > 0)
            {
                ContentFolder fromParentFolder = Get(fromFolder.ParentId);
                if (fromParentFolder != null)
                {
                    fromParentFolder.ChildCount -= 1;
                }
            }

            toFolder.ChildCount += fromFolder.ChildCount;
            contentFolderRepository.Update(toFolder);
            contentFolderRepository.Delete(fromFolder);
            EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", 0);
        }