From caaff241125777353556320db02047c6d79a090a Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 23 Jan 2017 20:42:48 -0600 Subject: [PATCH] /comments?group_by=comment: add is_sticky/is_deleted/do_not_bump_post/order params. --- app/controllers/comments_controller.rb | 2 +- app/models/comment.rb | 38 +++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 3a8b1f8b8..96933d631 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -90,7 +90,7 @@ private end def index_by_comment - @comments = Comment.search(params[:search]).order("comments.id DESC").paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) + @comments = Comment.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) respond_with(@comments) do |format| format.html {render :action => "index_by_comment"} format.xml do diff --git a/app/models/comment.rb b/app/models/comment.rb index 472326064..ca6d7777a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -56,6 +56,22 @@ class Comment < ActiveRecord::Base where("comments.is_deleted = false") end + def sticky + where("comments.is_sticky = true") + end + + def unsticky + where("comments.is_sticky = false") + end + + def bumping + where("comments.do_not_bump_post = false") + end + + def nonbumping + where("comments.do_not_bump_post = true") + end + def post_tags_match(query) PostQueryBuilder.new(query).build(self.joins(:post)).reorder("") end @@ -96,10 +112,24 @@ class Comment < ActiveRecord::Base q = q.for_creator(params[:creator_id].to_i) end - if params[:is_deleted] == "true" - q = q.deleted - elsif params[:is_deleted] == "false" - q = q.undeleted + q = q.deleted if params[:is_deleted] == "true" + q = q.undeleted if params[:is_deleted] == "false" + + q = q.sticky if params[:is_sticky] == "true" + q = q.unsticky if params[:is_sticky] == "false" + + q = q.nonbumping if params[:do_no_bump_post] == "true" + q = q.bumping if params[:do_not_bump_post] == "false" + + case params[:order] + when "post_id", "post_id_desc" + q = q.order("comments.post_id DESC") + when "score", "score_desc" + q = q.order("comments.score DESC") + when "updated_at", "updated_at_desc" + q = q.order("comments.updated_at DESC") + else + q = q.order("comments.id DESC") end q