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-29 10:48:16 +08:00
2013-12-16 14:39:02 +08:00
include CoursesHelper
2013-12-07 09:47:54 +08:00
2013-11-29 10:48:16 +08:00
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_all_hot_contest
sort_contest_by_hot
end
2013-12-04 16:46:16 +08:00
def cal_memos_count event
return nil if event . parent_id
event . replies_count
rescue NoMethodError
nil
end
def cal_issues_count event
event . journals . count
rescue NoMethodError
nil
end
2013-11-30 10:41:14 +08:00
2013-12-09 18:31:08 +08:00
def topic_last_time topic
2013-12-11 16:14:51 +08:00
return topic . event_datetime if ( ! ( topic . methods . to_s =~ %r[ last_reply ] ) || topic . last_reply . nil? )
2013-12-09 18:31:08 +08:00
topic . last_reply . event_datetime
end
2013-11-29 10:48:16 +08:00
def time_tag_welcome time
text = distance_of_time_in_words ( Time . now , time )
content_tag ( 'span' , text , :title = > format_time ( time ) )
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
2013-12-05 15:26:29 +08:00
" 项目评分: " . html_safe << grade . to_s
2013-11-29 10:48:16 +08:00
end
2013-11-30 10:41:14 +08:00
def show_user_content event
2013-12-12 09:19:31 +08:00
str = ' ' . html_safe
2013-11-30 10:41:14 +08:00
case event . event_type
2013-12-12 10:10:30 +08:00
when 'news' , 'issue' , 'message' , 'bid' , 'wiki-page' , 'document'
2013-12-12 09:19:31 +08:00
str << content_tag ( " span " , " 发表了 " ) << content_tag ( " span " , find_all_event_type ( event ) ) << ': ' . html_safe << link_to ( truncate ( event . event_title , length : 30 , omission : '...' ) , event . event_url )
2013-12-12 10:10:30 +08:00
when 'reply' , 'Reply' , 'Memo'
2013-12-12 09:19:31 +08:00
str << content_tag ( " span " , " 发表了 " ) << content_tag ( " span " , find_all_event_type ( event ) ) << ': ' . html_safe << link_to ( truncate ( strip_tags ( event . event_description ) , length : 30 , omission : '...' ) , event . event_url )
2013-12-12 10:10:30 +08:00
when 'attachment'
str << content_tag ( 'span' , '上传了' ) << content_tag ( 'span' , find_all_event_type ( event ) ) << ': ' . html_safe << link_to ( truncate ( event . event_title , length : 30 , omission : '...' ) , project_files_path ( event . container ) ) #<< link_to((' '.html_safe+l(:button_download)), event.event_url)
2013-11-30 10:41:14 +08:00
else
2013-12-12 09:19:31 +08:00
str << content_tag ( " span " , " 更新了 " ) << content_tag ( " span " , find_all_event_type ( event ) ) << ': ' . html_safe << link_to ( truncate ( event . event_title , length : 30 , omission : '...' ) , event . event_url )
2013-11-30 10:41:14 +08:00
end
str
2013-12-12 10:10:30 +08:00
rescue Exception = > e
str << content_tag ( " span " , '未知内容' )
2013-11-30 10:41:14 +08:00
end
2013-12-05 15:26:29 +08:00
def show_event_reply event
str = " 回复( "
case event . event_type
when " issue "
str << link_to ( cal_issues_count ( event ) , issue_path ( event ) ) << " ) "
when " Memo "
str << link_to ( cal_memos_count ( event ) , forum_memo_path ( event . forum_id , event . id ) ) << " ) "
else
str = " "
end
str . html_safe
end
2013-12-16 14:39:02 +08:00
2013-12-13 16:08:29 +08:00
def find_new_forum_topics limit = 7
2013-12-11 16:19:18 +08:00
Memo . where ( 'memos.parent_id IS NULL' ) . reorder ( 'memos.created_at DESC' ) . limit ( limit )
2013-12-11 16:15:10 +08:00
# activity = Redmine::Activity::Fetcher.new(nil)
# activity.scope=['memos']
# activity.events_welcome(nil, nil, {:limit => limit})
2013-12-10 19:45:38 +08:00
end
2013-12-09 18:31:08 +08:00
2013-11-29 10:48:16 +08:00
private
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
#取得所有活动
2013-11-30 09:29:02 +08:00
def find_all_activities limit = 6
2013-11-29 10:48:16 +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-12-14 11:41:53 +08:00
activity . scope_select { | t | [ 'changesets' ] . include? ( t ) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' }
2013-12-04 15:31:18 +08:00
activity . events_welcome ( nil , nil , { :limit = > limit , :types = > 'welcome' } )
2013-11-29 10:48:16 +08:00
end
#取得论坛数据
2013-12-05 15:26:29 +08:00
def find_hot_forum_topics limit = 9
2013-12-02 17:27:15 +08:00
## 以下语句会内链接自身查询出最后一条回复时间,没有回复的帖子不会显示
# Memo.find_by_sql("
# SELECT memos.*, reply.created_at AS last_reply_date FROM memos AS memos
# INNER JOIN memos
# AS reply ON memos.last_reply_id=reply.id
# WHERE memos.parent_id IS NULL
# ORDER BY memos.replies_count DESC, memos.created_at DESC
# LIMIT #{limit}")
2013-12-06 11:19:15 +08:00
#Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit)
resultSet = Memo . order ( 'replies_count DESC, created_at DESC' ) . where ( 'parent_id IS NULL' ) . limit ( limit )
resultSet += Message . order ( 'replies_count DESC, created_on DESC' ) . where ( 'parent_id IS NULL' ) . limit ( limit )
resultSet . sort! { | x , y | ( y . replies_count < = > x . replies_count ) . nonzero? || ( y . event_datetime < = > x . event_datetime ) }
resultSet . take ( limit )
2013-11-29 10:48:16 +08:00
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
2013-11-28 09:29:59 +08:00
FROM projects AS p RIGHT OUTER JOIN (
2013-11-29 10:48:16 +08:00
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-29 10:48:16 +08:00
end
2013-11-28 09:29:59 +08:00
2013-11-29 10:48:16 +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 )
end
2013-11-30 10:41:14 +08:00
def find_all_event_type event
case event . event_type
when 'news'
'新闻'
when 'issue'
'缺陷'
when 'attachment'
'附件'
when 'message'
'主题'
2013-12-12 08:40:18 +08:00
when 'Reply' , 'reply'
2013-11-30 10:41:14 +08:00
'回复'
when 'bid'
'作业'
2013-12-05 15:26:29 +08:00
when 'Memo'
'主题'
when 'document'
'文件'
2013-12-11 20:34:29 +08:00
when 'changeset'
'版本库'
2013-12-12 08:40:18 +08:00
when 'issue-note'
'问题说明'
2013-11-30 10:41:14 +08:00
else
event . event_type
end
end
2013-12-07 09:47:54 +08:00
2013-08-01 10:33:49 +08:00
end