Exemplo n.º 1
0
        /// <summary>
        /// 是否具有前台管理资讯的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <returns></returns>
        public static bool CMS_ManageContentItemsForChannel(this Authorizer authorizer)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId))
            {
                return(true);
            }
            ContentFolderModeratorService contentFolderModeratorService = new ContentFolderModeratorService();
            var folderIds = contentFolderModeratorService.GetModeratedFolderIds(currentUser.UserId);

            if (folderIds.Count() > 0)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 是否具有前台管理资讯的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <returns></returns>
        public static bool CMS_ManageContentItemsForChannel(this Authorizer authorizer)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
                return false;

            if (authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId))
                return true;
            ContentFolderModeratorService contentFolderModeratorService = new ContentFolderModeratorService();
            var folderIds = contentFolderModeratorService.GetModeratedFolderIds(currentUser.UserId);
            if (folderIds.Count() > 0)
                return true;
            return false;
        }