Class: ForumComment
- Inherits:
-
Comment
- Object
- Comment
- ForumComment
- Defined in:
- app/models/forum_comment.rb
Class Method Summary collapse
-
.create_comment(forum_topic, body, user, parent_comment = nil) ⇒ Object
For a forum topic, we have one root comment, which is the body of the topic.
-
.search(query, options = {}) ⇒ Object
——————————————————————————.
-
.search_monitored(user_id, query, options = {}) ⇒ Object
——————————————————————————.
Instance Method Summary collapse
-
#forum_name ⇒ Object
——————————————————————————.
Class Method Details
.create_comment(forum_topic, body, user, parent_comment = nil) ⇒ Object
For a forum topic, we have one root comment, which is the body of the topic. All other comments are either children or siblings
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/forum_comment.rb', line 24 def self.create_comment(forum_topic, body, user, parent_comment = nil) unless parent_comment #--- if it's the first comment, make it the root, otherwise it's a child parent_comment = (forum_topic.forum_comments.empty? ? nil : forum_topic.forum_comments[0].root) end forum_topic.forum_comments.build(:body => body).tap do |comment| comment.user = user comment.parent = parent_comment comment.save end end |
.search(query, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/forum_comment.rb', line 37 def self.search(query, = {}) #--- (Beast) had to change the other join string since it conflicts when we bring parents in [:conditions] ||= ["LOWER(#{ForumComment.table_name}.body) LIKE ?", "%#{query}%"] unless query.blank? [:select] ||= "#{ForumComment.table_name}.*, #{ForumTopic.table_name}.title as topic_title, f.name as forum_name" [:joins] ||= "inner join #{ForumTopic.table_name} on #{ForumComment.table_name}.topic_id = #{ForumTopic.table_name}.id " + "inner join #{Forum.table_name} as f on #{ForumTopic.table_name}.forum_id = f.id" [:order] ||= "#{ForumComment.table_name}.created_at DESC" [:count] ||= {:select => "#{ForumComment.table_name}.id"} paginate end |
.search_monitored(user_id, query, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/forum_comment.rb', line 49 def self.search_monitored(user_id, query, = {}) #--- (Beast) Same as above, but select only posts in topics monitored by the given user # [todo] # options[:conditions] ||= ["LOWER(#{ForumComment.table_name}.body) LIKE ?", "%#{query}%"] unless query.blank? # options[:select] ||= "#{ForumComment.table_name}.*, #{ForumTopic.table_name}.title as topic_title, f.name as forum_name" # options[:joins] ||= "inner join #{ForumTopic.table_name} on #{ForumComment.table_name}.topic_id = #{ForumTopic.table_name}.id " + # "inner join #{Forum.table_name} as f on #{ForumTopic.table_name}.forum_id = f.id " + # "inner join #{Monitorship.table_name} as m on #{ForumComment.table_name}.topic_id = m.topic_id AND " + # "m.user_id = #{user_id} AND m.active != 0" # options[:order] ||= "#{ForumComment.table_name}.created_at DESC" # options[:count] ||= {:select => "#{ForumComment.table_name}.id"} # paginate options end |
Instance Method Details
#forum_name ⇒ Object
64 65 66 |
# File 'app/models/forum_comment.rb', line 64 def forum_name forum_topic.forum.name end |