Class: TopicPost
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from KitIndexed
do_indexing, indexed_columns, paginate
Instance Attribute Details
#already_voted ⇒ Object
an indicator that the current user has already voted on this topic
22
23
24
|
# File 'app/models/topic_post.rb', line 22
def already_voted
@already_voted
end
|
#kit_session_id ⇒ Object
Returns the value of attribute kit_session_id.
23
24
25
|
# File 'app/models/topic_post.rb', line 23
def kit_session_id
@kit_session_id
end
|
#title ⇒ Object
a pseudo field for when the post is the opening post of a new thread (because a thread has a title)
21
22
23
|
# File 'app/models/topic_post.rb', line 21
def title
@title
end
|
Class Method Details
.delete_all_by_user(sid, user_id, by_user) ⇒ Object
64
65
66
67
68
|
# File 'app/models/topic_post.rb', line 64
def TopicPost.delete_all_by_user(sid, user_id, by_user)
TopicPost.sys(sid).where(:created_by_user_id=>user_id).find_each do |topic|
topic.mark_as_deleted(by_user, true)
end
end
|
Instance Method Details
#create_engagement ⇒ Object
44
45
46
|
# File 'app/models/topic_post.rb', line 44
def create_engagement
KitEngagement.create(:kit_session_id=>self.kit_session_id, :system_id=>self.system_id, :engage_type=>"Forum Post", :value=>self.link) if self.kit_session_id
end
|
#display_body ⇒ Object
56
57
58
|
# File 'app/models/topic_post.rb', line 56
def display_body
self.body
end
|
#edit_log(separator = "<br/>") ⇒ Object
34
35
36
|
# File 'app/models/topic_post.rb', line 34
def edit_log(separator = "<br/>")
self.topic_post_edits.map { |edit| "Edited by #{edit.user.display_name} #{edit.created_at.to_s(:short)}" }.join(separator)
end
|
#edited(user) ⇒ Object
48
49
50
|
# File 'app/models/topic_post.rb', line 48
def edited(user)
TopicPostEdit.create(:raw_body=>self.raw_body, :topic_post_id=>self.id, :user_id=>user.id)
end
|
#host_link ⇒ Object
83
84
85
|
# File 'app/models/topic_post.rb', line 83
def host_link
"#{Preference.get_cached(self.system_id, "host")}#{self.link}"
end
|
#link ⇒ Object
87
88
89
|
# File 'app/models/topic_post.rb', line 87
def link "#{self.topic_thread.link}##{self.id}"
end
|
#mark_as_deleted(by_user, del) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/models/topic_post.rb', line 70
def mark_as_deleted(by_user, del)
self.is_visible = del ? 0 : 1
self. ||= ''
self. += (self.is_visible? ? "Undeleted" : "Deleted") + " by #{by_user.email} at #{Time.now}<br/>"
self.save
if self.topic_thread.topic_posts.where("is_visible=#{del ? 1 : 0}").count==0
self.topic_thread.update_attributes(:is_visible=>del ? 0 : 1, :post_count=>self.topic_thread.topic_posts.where("is_visible=1").count)
else
self.topic_thread.update_attributes(:post_count => self.topic_thread.post_count - (self.is_visible==0 ? 1 : -1))
end
end
|
#notify_watchers ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'app/models/topic_post.rb', line 25
def notify_watchers
self.topic_thread.topic_thread_users.includes({:user=>:forum_user}).where(:email_sent=>nil).where("user_id<>#{self.created_by_user_id}").each do |ttu|
if ttu.user.forum_user.receive_watch_notifications==1
Notification.delay.new_post(self, ttu.user)
ttu.update_attributes(:email_sent=>Time.now)
end
end
end
|
#update_body ⇒ Object
52
53
54
|
# File 'app/models/topic_post.rb', line 52
def update_body
self.body = self.raw_body.sanitise.friendly_format(:smilies=>Preference.get_cached(self.system_id, "forum_use_smilies")=='true').html_safe
end
|
#update_postnumber ⇒ Object
38
39
40
41
42
|
# File 'app/models/topic_post.rb', line 38
def update_postnumber
last_post = self.topic_thread.topic_posts.where("topic_posts.id <> #{self.id}").order("post_number desc").first.post_number || 0
self.post_number = last_post + 1
self.save
end
|
#users_votes(user_id) ⇒ Object
60
61
62
|
# File 'app/models/topic_post.rb', line 60
def users_votes(user_id)
self.topic_post_votes.where(:user_id=>user_id).all
end
|