Class: TopicThread
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from KitIndexed
do_indexing, indexed_columns, paginate
Instance Attribute Details
#kit_session_id ⇒ Object
Returns the value of attribute kit_session_id.
31
32
33
|
# File 'app/models/topic_thread.rb', line 31
def kit_session_id
@kit_session_id
end
|
Class Method Details
.im_on(current_user, count, is_mod = false, page = 1) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'app/models/topic_thread.rb', line 124
def self.im_on(current_user, count, is_mod=false, page=1)
thread_ids = TopicThread.limit(100).order("last_post_at desc").select("distinct topic_threads.id, topic_threads.last_post_at")
thread_ids = thread_ids.where("topic_posts.is_visible = 1") unless is_mod
thread_ids = thread_ids.joins(:topic).where("topics.is_visible = 1") unless is_mod
thread_ids = thread_ids.joins(:topic_posts).where("topic_posts.created_by_user_id = #{current_user.id}").all
if thread_ids.size>0
tthreads = TopicThread.where("id in (#{thread_ids.map {|ti| ti.id}.join(",")})")
tthreads = tthreads.page(page).per(count)
else
tthreads = nil
end
return tthreads
end
|
.most_recent(current_user, count, is_mod = false, page = 1) ⇒ Object
118
119
120
121
122
|
# File 'app/models/topic_thread.rb', line 118
def self.most_recent(current_user, count, is_mod=false, page=1)
read_level = current_user ? current_user.forum_level : 0
TopicThread.limit(count).order("topic_threads.last_post_at desc").where("topic_threads.is_visible = 1").includes(:topic).where("topics.read_access_level <= #{read_level}").page(page).per(count)
end
|
.threads(count, is_mod = false, page = 1) ⇒ Object
140
141
142
143
144
145
|
# File 'app/models/topic_thread.rb', line 140
def self.threads(count, is_mod = false, page = 1)
tthreads = TopicThread.limit(1000).order("last_post_at desc")
tthreads = tthreads.where(:is_visible=>1) unless is_mod
tthreads = tthreads.page(page).per(count)
return tthreads
end
|
Instance Method Details
#create_engagement ⇒ Object
99
100
101
|
# File 'app/models/topic_thread.rb', line 99
def create_engagement
KitEngagement.create(:kit_session_id=>self.kit_session_id, :system_id=>self.system_id, :engage_type=>"Forum Thread", :value=>self.link) if self.kit_session_id
end
|
#first_post ⇒ Object
114
115
116
|
# File 'app/models/topic_thread.rb', line 114
def first_post
self.topic_posts_rev.first
end
|
#is_favourited_by(user) ⇒ Object
108
109
110
111
112
|
# File 'app/models/topic_thread.rb', line 108
def is_favourited_by(user)
return false unless user
return self.topic_thread_users.where(:user_id=>user.id).count > 0
end
|
#latest_unread(user, forum_user, is_moderator) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/models/topic_thread.rb', line 33
def latest_unread(user, forum_user, is_moderator)
previous_last_post_id = 0
if user
tv = self.thread_views.where(:user_id=>user.id).first
previous_last_post_id = tv.topic_post_id if tv
end
next_post = self.simple_topic_posts
next_post = next_post.where(:is_visible=>1) unless is_moderator
next_post = next_post.where("topic_posts.id > #{previous_last_post_id}")
next_post = next_post.order(:id).first
if next_post
next_post_id = next_post.id
else
next_post_id = previous_last_post_id
end
page = page_for_post(previous_last_post_id, forum_user, is_moderator)
return next_post_id, page
end
|
#link(latest = false) ⇒ Object
104
105
106
|
# File 'app/models/topic_thread.rb', line 104
def link(latest=false)
"#{topic.link}#{'/latest' if latest}/#{self.id}-#{self.title.urlise}"
end
|
#link_for_post(post_id, forum_user, is_moderator) ⇒ Object
69
70
71
72
|
# File 'app/models/topic_thread.rb', line 69
def link_for_post(post_id, forum_user, is_moderator)
page = page_for_post(post_id, forum_user, is_moderator)
return self.link + "?page=#{page}##{post_id}"
end
|
#link_latest_unread(user, forum_user, is_moderator) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'app/models/topic_thread.rb', line 74
def link_latest_unread(user, forum_user, is_moderator)
if user
next_post_id, page = latest_unread(user, forum_user, is_moderator)
return self.link + "?page=#{page}##{next_post_id}"
else
return self.link
end
end
|
#page_for_post(post_id, forum_user, is_moderator) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/models/topic_thread.rb', line 56
def page_for_post(post_id, forum_user, is_moderator)
posts = self.simple_topic_posts
posts = posts.where(:is_visible=>1) unless is_moderator
if forum_user.post_order=='asc'
posts = posts.where("topic_posts.id <= #{post_id}")
else
posts = posts.where("topic_posts.id >= #{post_id}")
end
page = ((((posts.count-1) / forum_user.posts_per_page).truncate) + 1) rescue 1
page = 1 if page<1
return page
end
|
#update_post_numbers ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/models/topic_thread.rb', line 84
def update_post_numbers
n = 0
self.topic_posts.each do |post|
if post.is_visible==1
n += 1
l = n
else
l = 0
end
post.update_attributes(:post_number=>l)
end
end
|