修复帖子统计问题
This commit is contained in:
parent
49327905f8
commit
8f707f3987
|
@ -4,11 +4,11 @@ class Forum < ActiveRecord::Base
|
||||||
has_many :memos, :dependent => :destroy
|
has_many :memos, :dependent => :destroy
|
||||||
belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id'
|
belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id'
|
||||||
safe_attributes 'name',
|
safe_attributes 'name',
|
||||||
'description',
|
'description',
|
||||||
'topic_count',
|
'topic_count',
|
||||||
'memo_count',
|
'memo_count',
|
||||||
'last_memo_id',
|
'last_memo_id',
|
||||||
'creator_id'
|
'creator_id'
|
||||||
validates_presence_of :name, :creator_id
|
validates_presence_of :name, :creator_id
|
||||||
validates_length_of :name, maximum: 50
|
validates_length_of :name, maximum: 50
|
||||||
validates_length_of :description, maximum: 255
|
validates_length_of :description, maximum: 255
|
||||||
|
@ -16,5 +16,17 @@ class Forum < ActiveRecord::Base
|
||||||
|
|
||||||
acts_as_taggable
|
acts_as_taggable
|
||||||
scope :by_join_date, order("created_at DESC")
|
scope :by_join_date, order("created_at DESC")
|
||||||
|
|
||||||
|
def reset_counters!
|
||||||
|
self.class.reset_counters!(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates topic_count, memo_count and last_memo_id attributes for +board_id+
|
||||||
|
def self.reset_counters!(forum_id)
|
||||||
|
forum_id = forum_id.to_i
|
||||||
|
update_all("topic_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id} AND parent_id IS NULL)," +
|
||||||
|
" memo_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})," +
|
||||||
|
" last_memo_id = (SELECT MAX(id) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})",
|
||||||
|
["id = ?", forum_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Memo < ActiveRecord::Base
|
class Memo < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
belongs_to :forums
|
belongs_to :forum
|
||||||
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
|
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
|
||||||
|
|
||||||
validates_presence_of :author_id, :forum_id, :subject
|
validates_presence_of :author_id, :forum_id, :subject
|
||||||
|
@ -13,10 +13,10 @@ class Memo < ActiveRecord::Base
|
||||||
acts_as_attachable
|
acts_as_attachable
|
||||||
belongs_to :last_reply_id, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
belongs_to :last_reply_id, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
||||||
# acts_as_searchable :column => ['subject', 'content'],
|
# acts_as_searchable :column => ['subject', 'content'],
|
||||||
# #:include => { :forums => :p}
|
# #:include => { :forum => :p}
|
||||||
# #:project_key => "#{Forum.table_name}.project_id"
|
# #:project_key => "#{Forum.table_name}.project_id"
|
||||||
# :date_column => "#{table_name}.created_at"
|
# :date_column => "#{table_name}.created_at"
|
||||||
# acts_as_event :title => Proc.new {|o| "#{o.forums.name}: #{o.subject}"},
|
# acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
|
||||||
# :description => :content,
|
# :description => :content,
|
||||||
# :group => :parent,
|
# :group => :parent,
|
||||||
# :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
# :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
||||||
|
@ -29,7 +29,7 @@ class Memo < ActiveRecord::Base
|
||||||
"subject",
|
"subject",
|
||||||
"content",
|
"content",
|
||||||
"forum_id",
|
"forum_id",
|
||||||
"last_reply_id",
|
"last_memo_id",
|
||||||
"lock",
|
"lock",
|
||||||
"parent_id",
|
"parent_id",
|
||||||
"replies_count",
|
"replies_count",
|
||||||
|
@ -39,8 +39,8 @@ class Memo < ActiveRecord::Base
|
||||||
# after_update :update_memos_forum
|
# after_update :update_memos_forum
|
||||||
after_destroy :reset_counters!
|
after_destroy :reset_counters!
|
||||||
# after_create :send_notification
|
# after_create :send_notification
|
||||||
after_save :plusParentAndForum
|
# after_save :plusParentAndForum
|
||||||
after_destroy :minusParentAndForum
|
# after_destroy :minusParentAndForum
|
||||||
|
|
||||||
# scope :visible, lambda { |*args|
|
# scope :visible, lambda { |*args|
|
||||||
# includes(:forum => ).where()
|
# includes(:forum => ).where()
|
||||||
|
@ -62,7 +62,7 @@ class Memo < ActiveRecord::Base
|
||||||
if parent && parent.id
|
if parent && parent.id
|
||||||
Memo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})
|
Memo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})
|
||||||
end
|
end
|
||||||
# forums.reset_counters!
|
forum.reset_counters!
|
||||||
end
|
end
|
||||||
|
|
||||||
def sticky=(arg)
|
def sticky=(arg)
|
||||||
|
|
|
@ -34,12 +34,12 @@
|
||||||
|
|
||||||
<% @forums.each do |forum| %>
|
<% @forums.each do |forum| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= forum.name %></td>
|
<td>< %= forum.name %></td>
|
||||||
<td><%= forum.description %></td>
|
<td>< %= forum.description %></td>
|
||||||
<td><%= forum.creator.show_name %></td>
|
<td>< %= forum.creator.show_name %></td>
|
||||||
<td><%= link_to 'Show', forum %></td>
|
<td>< %= link_to 'Show', forum %></td>
|
||||||
<td><%= link_to 'Edit', edit_forum_path(forum) %></td>
|
<td>< %= link_to 'Edit', edit_forum_path(forum) %></td>
|
||||||
<td><%= link_to 'Destroy', forum, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
<td>< %= link_to 'Destroy', forum, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -203,7 +203,7 @@ Redmine::MenuManager.map :top_menu do |menu|
|
||||||
menu.push :software_user, {:controller => 'users', :action => 'index'}
|
menu.push :software_user, {:controller => 'users', :action => 'index'}
|
||||||
menu.push :contest_innovate, {:controller => 'bids', :action => 'contest', :project_type => 1}
|
menu.push :contest_innovate, {:controller => 'bids', :action => 'contest', :project_type => 1}
|
||||||
menu.push :requirement_enterprise, {:controller => 'bids', :action => 'index'}
|
menu.push :requirement_enterprise, {:controller => 'bids', :action => 'index'}
|
||||||
menu.push :project_module_forums, {:controller => 'forums', :action => 'index'}
|
menu.push :project_module_forums, forums_path
|
||||||
|
|
||||||
|
|
||||||
# menu.push :investor, :home_path
|
# menu.push :investor, :home_path
|
||||||
|
|
Loading…
Reference in New Issue