@ -61,8 +61,8 @@ class Mailer < ActionMailer::Base
InviteList . create ( :user_id = > user . id , :project_id = > project . id )
User . current = user unless User . current . nil?
@user = user
@project_url = url_for ( :controller = > 'projects' , :action = > 'member' , :id = > project . id , : user_id = > user . id , :mail = > tr ue)
@token = Token . get_token_from_user ( user , 'autologin' )
@project_url = url_for ( :controller = > 'projects' , :action = > 'member' , :id = > project . id , : mail = > true , :token = > @token . val ue)
mail :to = > email , :subject = > @subject
end
@ -104,9 +104,14 @@ class Mailer < ActionMailer::Base
# 查询user的缺陷, 项目中成员都能收到
sql = " select DISTINCT * from members m, issues i where i.project_id = m.project_id and m.user_id=' #{ user . id } '
and ( i . cre ated_on between '#{date_from}' and '#{date_to}' ) order by i . cre ated_on desc "
and ( i . upd ated_on between '#{date_from}' and '#{date_to}' ) order by i . upd ated_on desc "
@issues = Issue . find_by_sql ( sql )
# issue回复
@issues_journals = Journal . find_by_sql ( " select j.* from journals j, members m, projects p, issues i
where m . user_id = '#{user.id}' and p . id = m . project_id and i . project_id = p . id and j . journalized_id = i . id
and j . journalized_type = 'Issue' and ( j . created_on between '#{date_from}' and '#{date_to}' ) order by created_on desc " )
# @bids 查询课程作业, 包括老师发布的作业, 以及user提交作业
# @attachments查询课程课件更新
@attachments || = [ ]
@ -122,6 +127,11 @@ class Mailer < ActionMailer::Base
end
end
# 项目附件
@project_attachments = Attachment . find_by_sql ( " select DISTINCT a.* from members m, attachments a
where a . container_id = m . project_id and m . user_id = '#{user.id}' and container_type = 'Project' and ( a . created_on between '#{date_from}' and '#{date_to}' ) order by a . created_on desc " )
# user 提交的作业
# @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc")
@ -155,13 +165,23 @@ class Mailer < ActionMailer::Base
end
# wiki
# 查询user在课程中发布的通知 ,项目中发的新闻
# 查询user在课程中发布的通知 和回复通知
@course_news = ( course_ids && ! course_ids . empty? ) ? News . find_by_sql ( " select DISTINCT n.* from news n
where n . course_id in ( #{course_ids})
and ( created_on between '#{date_from}' and '#{date_to}' ) order by created_on desc " ) : []
@course_news_comments = Comment . find_by_sql ( " select cm.* from comments cm, members m, courses c, news n
where m . user_id = '#{user.id}' and c . id = m . course_id and n . course_id = c . id and cm . commented_id = n . id
and cm . commented_type = 'News' and ( cm . created_on between '#{date_from}' and '#{date_to}' ) order by created_on desc " )
# 查询user在项目中添加新闻和回复新闻
@project_news = ( project_ids && ! project_ids . empty? ) ? News . find_by_sql ( " select DISTINCT n.* from news n where n.project_id in ( #{ project_ids } )
and ( created_on between '#{date_from}' and '#{date_to}' ) order by created_on desc " ) : []
@project_news_comments = Comment . find_by_sql ( " select c.* from comments c, members m, projects p, news n
where m . user_id = '#{user.id}' and p . id = m . project_id and n . project_id = p . id and c . commented_id = n . id
and c . commented_type = 'News' and ( c . created_on between '#{date_from}' and '#{date_to}' ) order by created_on desc " )
# 查询user在课程及个人中留言
@course_journal_messages = JournalsForMessage . find_by_sql ( " select DISTINCT jfm.* from journals_for_messages jfm, members m, courses c
where m . user_id = '#{user.id}' and c . id = m . course_id and jfm . jour_id = c . id
@ -179,7 +199,7 @@ class Mailer < ActionMailer::Base
@memos = Memo . find_by_sql ( " select DISTINCT m.* from memos m, forums f where (m.author_id = #{ user . id } or (m.forum_id = f.id and f.creator_id = #{ user . id } ))
and ( m . created_at between '#{date_from}' and '#{date_to}' ) order by m . created_at desc " )
has_content = [ @issues , @ course_messages, @project_messages , @course_news , @ project_news,
has_content = [ @issues , @ issues_journals, @ course_messages, @project_messages , @course_news , @ course_news_comments, @ project_news, @project_news_comments , @project_attachments ,
@course_journal_messages , @user_journal_messages , @project_journal_messages , @forums , @memos , @attachments , @bids , @wiki_contents ] . any? { | o | ! o . empty? }
mylogger . debug " Sent activity mail : #{ user . mail } - #{ has_content } "
#有内容才发,没有不发
@ -497,6 +517,26 @@ class Mailer < ActionMailer::Base
end
end
# Builds a Mail::Message object used to email recipients of a course when an homework are posted.
#
# Example:
# attachments_added(attachments) => Mail::Message object
# Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients
def homework_added ( homework_common )
@homework_common = homework_common
@author = homework_common . user
@homework_common_url = url_for ( :controller = > " homework_common " , :action = > " index " , :homework = > @homework_common . id )
@homework_author_url = url_for ( user_activities_url ( @author ) )
recipients || = [ ]
#将帖子创建者邮箱地址加入数组
@homework_common . course . members . each do | member |
recipients << member . user . mail
end
mail :to = > recipients ,
:subject = > " [ #{ l ( :label_user_homework ) } : #{ homework_common . name } #{ l ( :label_memo_create_succ ) } ] " ,
:filter = > true
end
# Builds a Mail::Message object used to email recipients of a news' project when a news item is added.
#
# Example: