diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index ea34c8aad..fc09041ec 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -18,124 +18,135 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module WelcomeHelper - - # def newbieTopiclist - # find_all_topic_by_board_id - # end - # def newbieTopicStickyList - # find_all_topic_by_board_id 1 - # end + # def newbieTopiclist + # find_all_topic_by_board_id + # end - # def find_project_by_topic topic - # board = find_board_by_topic(topic) - # find_project_by_board board - # end + # def newbieTopicStickyList + # find_all_topic_by_board_id 1 + # end - def find_all_hot_project - sort_project_by_hot - end - - def find_all_hot_course - sort_course_by_hot - end - - def find_all_hot_bid - sort_bid_by_hot - 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 + end - 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 + def find_all_hot_course + sort_course_by_hot + end - private + def find_all_hot_bid + sort_bid_by_hot + end - # def search_project - # Project.find_by_identifier "newbie_faq" - # end + def find_all_hot_contest + sort_contest_by_hot + 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_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 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 - sort_project_by_hot_rails 0, 'grade DESC' - end + def time_tag_welcome time + text = distance_of_time_in_words(Time.now, time) + content_tag('span', text, :title => format_time(time)) + end - def sort_course_by_hot - sort_project_by_hot_rails 1, 'course_ac_para DESC' - end + def show_grade project + grade = 0 + begin + grade = project.project_status.grade if project && project.project_status + rescue Exception => e + logger.error "[WelcomeHelper] ===> #{e}" + end + grade + end - def sort_bid_by_hot - sort_bid_by_hot_rails 1 - end + private - def sort_contest_by_hot - sort_bid_by_hot_rails 2 - end - #取得所有活动 - 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) + # def search_project + # Project.find_by_identifier "newbie_faq" + # end - activity.events_welcome(nil, nil, {: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_hot_forum_topics limit=10 - Memo.order('replies_count DESC').where('replies_count <> 0').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 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 + def sort_project_by_hot + sort_project_by_hot_rails 0, 'grade DESC' + end + + def sort_course_by_hot + sort_project_by_hot_rails 1, 'course_ac_para DESC' + end + + def sort_bid_by_hot + sort_bid_by_hot_rails 1 + end + + def sort_contest_by_hot + sort_bid_by_hot_rails 2 + end + + #取得所有活动 + 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('parent_id IS NULL').limit(limit) + end + + 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 + SELECT project_id,grade FROM project_statuses WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ") - end + end - def sort_bid_by_hot_rails reward_type, limit = 10 - Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit) - end + 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/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 95ada11d1..56e63f0e2 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -120,7 +120,7 @@