2013-08-01 10:33:49 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
module WelcomeHelper
|
2013-11-22 08:19:40 +08:00
|
|
|
|
|
|
|
def newbieTopiclist
|
|
|
|
find_all_topic_by_board_id
|
|
|
|
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_all_hot_project
|
|
|
|
sort_project_by_hot
|
|
|
|
end
|
2013-11-28 08:34:20 +08:00
|
|
|
|
|
|
|
def find_all_hot_course
|
2013-11-28 09:29:59 +08:00
|
|
|
sort_course_by_hot
|
2013-11-28 08:34:20 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_all_hot_bid
|
2013-11-28 09:29:59 +08:00
|
|
|
sort_bid_by_hot
|
2013-11-28 08:34:20 +08:00
|
|
|
end
|
2013-11-28 09:29:59 +08:00
|
|
|
|
|
|
|
def find_all_hot_contest
|
|
|
|
sort_contest_by_hot
|
|
|
|
end
|
|
|
|
|
2013-11-22 08:19:40 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
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_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
|
2013-11-28 08:34:20 +08:00
|
|
|
|
|
|
|
def sort_project_by_hot
|
2013-11-28 11:29:21 +08:00
|
|
|
sort_project_by_hot_rails 0, 'grade DESC'
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sort_course_by_hot
|
2013-11-28 11:29:21 +08:00
|
|
|
sort_project_by_hot_rails 1, 'course_ac_para DESC'
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sort_bid_by_hot
|
2013-11-28 11:29:21 +08:00
|
|
|
sort_bid_by_hot_rails 1
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sort_contest_by_hot
|
2013-11-28 11:29:21 +08:00
|
|
|
sort_bid_by_hot_rails 2
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
|
|
|
#取得所有活动
|
|
|
|
def find_all_activities limit=10
|
2013-11-28 11:29:21 +08:00
|
|
|
# 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)
|
2013-11-28 09:29:59 +08:00
|
|
|
|
|
|
|
activity.events_welcome(nil, nil, {:limit => limit})
|
|
|
|
end
|
|
|
|
|
|
|
|
#取得论坛数据
|
2013-11-28 09:34:51 +08:00
|
|
|
def find_hot_forum_topics limit=10
|
2013-11-28 09:49:20 +08:00
|
|
|
Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit)
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
2013-11-28 09:34:51 +08:00
|
|
|
|
2013-11-28 11:29:21 +08:00
|
|
|
def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=10
|
|
|
|
Project.find_by_sql("
|
2013-11-28 09:29:59 +08:00
|
|
|
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
|
2013-11-28 11:29:21 +08:00
|
|
|
WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ")
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
|
|
|
|
2013-11-28 11:29:21 +08:00
|
|
|
def sort_bid_by_hot_rails reward_type, limit = 10
|
|
|
|
Bid.visible.where('reward_type = ?', reward_type).reorder('bids.commit desc').limit(limit)
|
2013-11-28 09:29:59 +08:00
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|