diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c00f223c9..6d3574309 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -19,8 +19,8 @@ class WelcomeController < ApplicationController caches_action :robots def index - @news = News.latest User.current - @projects = Project.latest User.current + # @news = News.latest User.current + # @projects = Project.latest User.current #by young (redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration] if request.get? @@ -60,10 +60,10 @@ class WelcomeController < ApplicationController end #add by huang - @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) + # @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) - events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) - @events_by_day = events.group_by(&:event_date) + # events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) + # @events_by_day = events.group_by(&:event_date) # end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 0856a26ac..ea34c8aad 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -19,18 +19,18 @@ module WelcomeHelper - def newbieTopiclist - find_all_topic_by_board_id - end + # def newbieTopiclist + # find_all_topic_by_board_id + # end - def newbieTopicStickyList - find_all_topic_by_board_id 1 - end + # def newbieTopicStickyList + # find_all_topic_by_board_id 1 + # end - def find_project_by_topic topic - board = find_board_by_topic(topic) - find_project_by_board board - end + # def find_project_by_topic topic + # board = find_board_by_topic(topic) + # find_project_by_board board + # end def find_all_hot_project sort_project_by_hot @@ -47,78 +47,95 @@ module WelcomeHelper def find_all_hot_contest sort_contest_by_hot end + + def find_all_event_type event + case event.event_type + when 'news' + '新闻' + when 'issue' + '缺陷' + when 'attachment' + '附件' + when 'message' + '主题' + when 'reply' + '回复' + when 'bid' + '众包' + else + event.event_type + end + end + + def time_tag_welcome(time) + text = distance_of_time_in_words(Time.now, time) + content_tag('span', text, :title => format_time(time)) + end private - def search_project - Project.find_by_identifier "newbie_faq" - end + # def search_project + # Project.find_by_identifier "newbie_faq" + # end - def find_all_topic_by_board_id sticky = 0, limit = 30 - project = search_project - return [] if(project.nil? or project.boards.nil?) - board_id = project.boards.first.id - logger.debug "[WelcomeHelper] ===> find_all_topic_by_board_id=> project.id:#{project.id}, board_id:#{board_id}, sticky:#{sticky}" - Message.where("board_id = :board_id and sticky=:sticky", :board_id => board_id, :sticky => sticky ).limit(limit) - end + # def find_all_topic_by_board_id sticky = 0, limit = 30 + # project = search_project + # return [] if(project.nil? or project.boards.nil?) + # board_id = project.boards.first.id + # logger.debug "[WelcomeHelper] ===> find_all_topic_by_board_id=> project.id:#{project.id}, board_id:#{board_id}, sticky:#{sticky}" + # Message.where("board_id = :board_id and sticky=:sticky", :board_id => board_id, :sticky => sticky ).limit(limit) + # end - def find_board_by_topic topic - Board.find_by_id(topic.board_id) - end - def find_project_by_board board - Project.find_by_id(board.project_id) - end + # def find_board_by_topic topic + # Board.find_by_id(topic.board_id) + # end + # def find_project_by_board board + # Project.find_by_id(board.project_id) + # end def sort_project_by_hot - return sort_project_by_hot_rails 0 + sort_project_by_hot_rails 0, 'grade DESC' end def sort_course_by_hot - return sort_project_by_hot_rails 1 + sort_project_by_hot_rails 1, 'course_ac_para DESC' end def sort_bid_by_hot - return sort_bid_by_hot_rails 1 + sort_bid_by_hot_rails 1 end def sort_contest_by_hot - return sort_bid_by_hot_rails 2 + sort_bid_by_hot_rails 2 end #取得所有活动 - def find_all_activities limit=10 - users = [] - activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" ) - activities.each { |activity| - users << activity.user_id - } - user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") - activity = Redmine::Activity::Fetcher.new(user_objs) + def find_all_activities limit=5 + # users = [] + # activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" ) + # activities.each { |activity| + # users << activity.user_id + # } + # user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") + activity = Redmine::Activity::Fetcher.new(nil) activity.events_welcome(nil, nil, {:limit => limit}) end #取得论坛数据 def find_hot_forum_topics limit=10 - Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit) + Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit) end - def sort_project_by_hot_rails project_type - limit = 10 - project_type == 0 ? Project.find_by_sql(" + def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=15 + Project.find_by_sql(" SELECT p.id, p.name, p.description, p.identifier, t.project_id FROM projects AS p RIGHT OUTER JOIN ( SELECT project_id,grade FROM project_statuses - WHERE project_type = #{project_type} ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") - : Project.find_by_sql(" - SELECT p.id, p.name, p.description, p.identifier, t.project_id - FROM projects AS p RIGHT OUTER JOIN ( - SELECT project_id,grade FROM project_statuses - WHERE project_type = #{project_type} ORDER BY course_ac_para DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") + WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ") end - def sort_bid_by_hot_rails reward_type - limit = 10 - Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit).all + def sort_bid_by_hot_rails reward_type, limit = 10 + Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit) end end diff --git a/app/models/forum.rb b/app/models/forum.rb index 993c00b23..277b55dce 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -4,11 +4,11 @@ class Forum < ActiveRecord::Base has_many :memos, :dependent => :destroy belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' safe_attributes 'name', - 'description', - 'topic_count', - 'memo_count', - 'last_memo_id', - 'creator_id' + 'description', + 'topic_count', + 'memo_count', + 'last_memo_id', + 'creator_id' validates_presence_of :name, :creator_id validates_length_of :name, maximum: 50 validates_length_of :description, maximum: 255 @@ -16,5 +16,17 @@ class Forum < ActiveRecord::Base acts_as_taggable 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} AND parent_id IS NOT NULL)," + + " last_memo_id = (SELECT MAX(id) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})", + ["id = ?", forum_id]) + end end diff --git a/app/models/memo.rb b/app/models/memo.rb index 9a87009ec..b494064be 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,6 +1,6 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes - belongs_to :forums + belongs_to :forum belongs_to :author, :class_name => "User", :foreign_key => 'author_id' validates_presence_of :author_id, :forum_id, :subject @@ -13,10 +13,10 @@ class Memo < ActiveRecord::Base acts_as_attachable belongs_to :last_reply_id, :class_name => 'Memo', :foreign_key => 'last_reply_id' # acts_as_searchable :column => ['subject', 'content'], - # #:include => { :forums => :p} + # #:include => { :forum => :p} # #:project_key => "#{Forum.table_name}.project_id" # :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, # :group => :parent, # :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, @@ -29,7 +29,7 @@ class Memo < ActiveRecord::Base "subject", "content", "forum_id", - "last_reply_id", + "last_memo_id", "lock", "parent_id", "replies_count", @@ -39,8 +39,8 @@ class Memo < ActiveRecord::Base # after_update :update_memos_forum after_destroy :reset_counters! # after_create :send_notification - after_save :plusParentAndForum - after_destroy :minusParentAndForum + # after_save :plusParentAndForum + # after_destroy :minusParentAndForum # scope :visible, lambda { |*args| # includes(:forum => ).where() @@ -62,7 +62,7 @@ class Memo < ActiveRecord::Base if parent && parent.id Memo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) end - # forums.reset_counters! + forum.reset_counters! end def sticky=(arg) diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 80c379ed0..f79c44ae9 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -32,16 +32,16 @@