public PostCollection UpcomingEvents(string tag, int count) { CategoryController cc = new CategoryController(); Category eventCategory = cc.GetCachedCategory("Events", true); DataBuddy.Table table = new DataBuddy.Table("graffiti_posts", "PostCollection"); Query query = new Query(table); query.Top = "100 PERCENT *"; Column categoryColumn = new Column("CategoryId", DbType.Int32, typeof(Int32), "CategoryId", false, false); query.AndWhere(categoryColumn, eventCategory.Id, Comparison.Equals); PostCollection posts = PostCollection.FetchByQuery(query); List <Post> eventPosts = posts .Where(p => p.IsInFuture()) .Where(p => String.IsNullOrEmpty(tag) || p.TagList.Contains(tag)).ToList(); if (String.IsNullOrEmpty(tag)) { eventPosts.AddRange(Utility.LoadFeedEvents(DateTime.Today, DateTime.MaxValue).ToPosts()); } eventPosts = eventPosts.OrderBy(p => p.GetEffectiveDate()).ToList(); count = count > eventPosts.Count || count == -1 ? eventPosts.Count : count; eventPosts = eventPosts.GetRange(0, count); PostCollection ret = new PostCollection(); ret.AddRange(eventPosts); return(ret); }
public PostCollection GetNewsItems(int count) { CategoryController cc = new CategoryController(); // TODO: Need to get category name from plugin Category newsCategory = cc.GetCachedCategory("News", true); DataBuddy.Table table = new DataBuddy.Table("graffiti_posts", "PostCollection"); Query query = new Query(table); query.Top = "100 PERCENT *"; Column categoryColumn = new Column("CategoryId", DbType.Int32, typeof(Int32), "CategoryId", false, false); query.AndWhere(categoryColumn, newsCategory.Id, Comparison.Equals); PostCollection posts = PostCollection.FetchByQuery(query); List <Post> newsPosts = posts.Where(p => p.GetStartDate() <= DateTime.Today) .Where(p => p.GetEndDate() >= DateTime.Today) .Where(p => !p.IsDeleted) .OrderByDescending(p => p.GetPriority()) .ThenByDescending(p => p.Published).ToList(); count = count > newsPosts.Count ? newsPosts.Count : count; newsPosts = newsPosts.GetRange(0, count); PostCollection ret = new PostCollection(); ret.AddRange(newsPosts); return(ret); }
protected override void Establish_context() { _posts = new PostCollection(); _originalPosts = new PostCollection(); for (int i = 0; i < PostSetsToGenerate; i++) { // Create set of four posts on a given date (CreatedOn), two with the same event data, two without event dates at all. _posts.Add(CreatePost(String.Format("A (Has date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), DateTime.Now.Date.Add(TimeSpan.FromDays(i)))); _posts.Add(CreatePost(String.Format("B (Has date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), DateTime.Now.Date.Add(TimeSpan.FromDays(i)))); _posts.Add(CreatePost(String.Format("A (No date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), null)); _posts.Add(CreatePost(String.Format("B (No date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), null)); } _originalPosts.AddRange(_posts); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { Post the_Post = new Post(Request.QueryString["id"]); switch (the_Post.PostStatus) { case PostStatus.Publish: if (the_Post.Published > SiteSettings.CurrentUserTime) { PostUpdateStatus.Text = "The post, <em>"<a title=\"click to view the post\" href=\"" + the_Post.Url + "\">" + the_Post.Title + "</a>"</em>, was published. However, since this is a forward dated post, only site administrators can view it until " + the_Post.Published.ToLongDateString() + " " + the_Post.Published.ToShortTimeString(); } else { PostUpdateStatus.Text = "The post, <em>"<a title=\"click to view the post\" href=\"" + the_Post.Url + "\">" + the_Post.Title + "</a>"</em>, was published. If this was a revision, the new version is now live."; } PostUpdateStatus.Type = StatusType.Success; break; case PostStatus.Draft: PostUpdateStatus.Text = "The post, <em>"" + the_Post.Title + ""</em>, was saved as a draft."; PostUpdateStatus.Type = StatusType.Success; break; case PostStatus.PendingApproval: PostUpdateStatus.Text = "The post, <em>"" + the_Post.Title + ""</em>, was saved, but requires approval before it can be published. The site editors and publishers have been notified by email about this post. Once they publish it, you will be able to view it live."; PostUpdateStatus.Type = StatusType.Warning; break; case PostStatus.RequiresChanges: PostUpdateStatus.Text = "The post, <em>"" + the_Post.Title + ""</em>, was saved. An email has been sent to the original author with the change notification. You will receive an email once the author sets the post status to <em>Request Approval</em>."; PostUpdateStatus.Type = StatusType.Warning; break; } } if (!IsPostBack) { string page = Request.QueryString["status"] ?? "1"; string category = Request.QueryString["category"]; string author = Request.QueryString["author"]; Master.FindControl("SideBarRegion").Visible = true; List <AuthorCount> auts = null; switch (page) { case "1": // published PostsLinks.SetActiveView(Published); cats = Post.GetCategoryCountForStatus(PostStatus.Publish, author); auts = Post.GetAuthorCountForStatus(PostStatus.Publish, category); break; case "2": // draft PostsLinks.SetActiveView(Draft); cats = Post.GetCategoryCountForStatus(PostStatus.Draft, author); auts = Post.GetAuthorCountForStatus(PostStatus.Draft, category); break; case "3": // pending review PostsLinks.SetActiveView(PendingReview); cats = Post.GetCategoryCountForStatus(PostStatus.PendingApproval, author); auts = Post.GetAuthorCountForStatus(PostStatus.PendingApproval, category); break; case "4": // requires changes PostsLinks.SetActiveView(RequiresChanges); cats = Post.GetCategoryCountForStatus(PostStatus.RequiresChanges, author); auts = Post.GetAuthorCountForStatus(PostStatus.RequiresChanges, category); break; case "-1": // deleted PostsLinks.SetActiveView(Deleted); Master.FindControl("SideBarRegion").Visible = false; break; } if (auts != null) { rptAuthors.DataSource = auts; rptAuthors.DataBind(); } if (cats != null) { var temp = new List <CategoryCount>(); temp.AddRange(cats.FindAll( delegate(CategoryCount ca) { return(ca.ParentId <= 0); // only want the parents // the repeater below will handle the children })); temp.Sort( delegate(CategoryCount c, CategoryCount c1) { return(c.Name.CompareTo(c1.Name)); }); rptCategories.DataSource = temp; var toRemove = new List <CategoryCount>(); foreach (CategoryCount cc in temp) { if (!RolePermissionManager.GetPermissions(cc.ID, GraffitiUsers.Current).Read) { toRemove.Add(cc); } } foreach (CategoryCount cc in toRemove) { temp.Remove(cc); } rptCategories.DataBind(); } User user = null; if (!String.IsNullOrEmpty(author)) { user = new User(Convert.ToInt32(author)); author = user.Name; } Query q = Post.CreateQuery(); if (Request.QueryString["category"] != null && Request.QueryString["category"] != "-1") { q.AndWhere(Post.Columns.CategoryId, Request.QueryString["category"]); } if (!String.IsNullOrEmpty(author)) { q.AndWhere(Post.Columns.CreatedBy, author); } if (Request.QueryString["status"] == "-1") { q.AndWhere(Post.Columns.IsDeleted, true); } else { q.AndWhere(Post.Columns.IsDeleted, false); q.AndWhere(Post.Columns.Status, Request.QueryString["status"] ?? "1"); } q.OrderByDesc(Post.Columns.Published); PostCollection tempPC = new PostCollection(); tempPC.LoadAndCloseReader(q.ExecuteReader()); PostCollection permissionsFilteredCount = new PostCollection(); permissionsFilteredCount.AddRange(tempPC); foreach (Post p in tempPC) { if (!RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read) { permissionsFilteredCount.Remove(p); } } q.PageSize = 15; q.PageIndex = Int32.Parse(Request.QueryString["p"] ?? "1"); PostCollection pc = new PostCollection(); pc.LoadAndCloseReader(q.ExecuteReader()); PostList.NoneItemsDataBound += PostList_NoneItemsDataBound; PostCollection permissionsFiltered = new PostCollection(); permissionsFiltered.AddRange(pc); foreach (Post p in pc) { if (!RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read) { permissionsFiltered.Remove(p); } } PostList.DataSource = permissionsFiltered; PostList.DataBind(); string catID = Request.QueryString["category"] ?? "0"; string autID = Request.QueryString["author"] ?? "0"; if (pc.Count > 0) { string qs = "?status=" + page; if (catID != "0") { qs += "&category=" + catID; } if (autID != "0") { qs += "&author=" + autID; } Pager.Text = Util.Pager(q.PageIndex, q.PageSize, permissionsFilteredCount.Count, null, qs); } SetCounts(Int32.Parse(catID)); #region build the page title StringBuilder sb = new StringBuilder(); sb.Append("Posts "); switch (page) { case "1": sb.Append("Published "); break; case "2": sb.Append("Drafted "); break; case "3": sb.Append("Pending Review "); break; case "4": sb.Append("Requiring Changes "); break; case "5": sb.Append("Deleted "); break; } sb.Append("in "); if (Request.QueryString["category"] != null) { CategoryCollection categories = new CategoryController().GetAllCachedCategories(); Category temp = categories.Find( delegate(Category c) { return(c.Id == Int32.Parse(Request.QueryString["category"])); }); if (temp != null) { sb.Append(temp.Name); } } else { sb.Append("All Categories"); } if (!String.IsNullOrEmpty(author)) { sb.Append(" for " + user.ProperName); } lblPageTitle.Text = sb.ToString(); #endregion if (Request.QueryString["dstry"] != null) { PostUpdateStatus.Text = Server.UrlDecode(Request.QueryString["dstry"]) + " has been permanently deleted."; PostUpdateStatus.Type = StatusType.Success; } } }