Class: ForumTopic

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Includes:
DmCore::Concerns::FriendlyId
Defined in:
app/models/forum_topic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'app/models/forum_topic.rb', line 5

def body
  @body
end

Instance Method Details

#comment_number(forum_comment) ⇒ Object




83
84
85
# File 'app/models/forum_topic.rb', line 83

def comment_number(forum_comment)
  self.forum_comments.where("id <= #{forum_comment.id}").count
end

#comment_page(forum_comment) ⇒ Object




88
89
90
# File 'app/models/forum_topic.rb', line 88

def comment_page(forum_comment)
  [(comment_number(forum_comment).to_f / ForumComment.per_page.to_f).ceil.to_i, 1].max
end

#hit!Object




68
69
70
# File 'app/models/forum_topic.rb', line 68

def hit!
  self.class.increment_counter :hits, id
end

#last_pageObject




78
79
80
# File 'app/models/forum_topic.rb', line 78

def last_page
  [(comments_count.to_f / ForumComment.per_page.to_f).ceil.to_i, 1].max
end

#model_slugObject

use babosa gem (to_slug) to allow better handling of multi-language slugs




47
48
49
# File 'app/models/forum_topic.rb', line 47

def model_slug
  title
end

#num_repliesObject

The first comment on a topic is the topic text. So the number of replies is the number of comments - 1




54
55
56
# File 'app/models/forum_topic.rb', line 54

def num_replies
  comments_count - 1
end

#paged?Boolean


Returns:

  • (Boolean)


73
74
75
# File 'app/models/forum_topic.rb', line 73

def paged?
  comments_count > ForumComment.per_page
end

#sticky?Boolean


Returns:

  • (Boolean)


63
64
65
# File 'app/models/forum_topic.rb', line 63

def sticky?
  sticky
end

#to_sObject




58
59
60
# File 'app/models/forum_topic.rb', line 58

def to_s
  title
end

#update_cached_comment_fields(forum_comment) ⇒ Object




93
94
95
96
97
98
99
100
101
# File 'app/models/forum_topic.rb', line 93

def update_cached_comment_fields(forum_comment)
  #--- these fields are not accessible to mass assignment
  if remaining_comment = forum_comment.frozen? ? recent_comment : forum_comment
    self.class.where(:id => id).update_all(:last_updated_at => remaining_comment.created_at, 
          :last_user_id => remaining_comment.user_id, :last_forum_comment_id => remaining_comment.id)
  else
    destroy
  end
end