From 0fead3b80199395c5f320dabb771ca5474fec65d Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 18 Sep 2015 10:05:26 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=AF=BE=E7=A8=8B=E7=95=99=E8=A8=80?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=AF=B9=E8=B1=A1=E4=B8=BA=E8=80=81=E5=B8=88?= =?UTF-8?q?=202=E3=80=81=E4=BD=9C=E4=B8=9A=E6=88=AA=E6=AD=A2=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5=E4=B8=8D=E9=80=82?= =?UTF-8?q?=E7=94=A8delay=5Fjob=203=E3=80=81=E6=B7=BB=E5=8A=A0=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=88=AA=E6=AD=A2=E6=97=B6=E9=97=B4=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journals_for_message.rb | 17 ++++--- app/models/mailer.rb | 51 +++++-------------- .../mailer/homework_endtime__added.html.erb | 13 +++++ .../mailer/homework_endtime__added.text.erb | 0 config/locales/mailers/zh.yml | 2 + lib/tasks/homework_endtime.rake | 3 +- 6 files changed, 38 insertions(+), 48 deletions(-) create mode 100644 app/views/mailer/homework_endtime__added.html.erb create mode 100644 app/views/mailer/homework_endtime__added.text.erb diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index bdc1615c6..c7165dfe7 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -190,20 +190,21 @@ class JournalsForMessage < ActiveRecord::Base end end - # 课程留言消息通知 + # 课程/作品回复 留言消息通知 def act_as_course_message if self.jour_type == 'StudentWorksScore' if self.user_id != self.jour.user_id self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.student_work.homework_common.course.id, :viewed => false) end end - else if jour_type == 'Course' - self.jour.members.each do |m| - if m.user_id != self.user_id - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.jour.id, :viewed => false) - end - end - end + # 课程留言 + if jour_type == 'Course' + self.jour.members.each do |m| + if m.user.allowed_to?(:as_teacher, self.jour) && m.user_id != self.user_id # 仅仅留言则给该课程的老师发消息 + self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.jour.id, :viewed => false) + end + end + end end # 用户留言消息通知 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 931e2dbf0..2b343e9ac 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -50,7 +50,7 @@ class Mailer < ActionMailer::Base # author: alan # 邀请未注册用户加入项目 # 功能: 在加入项目的同时自动注册用户 - def send_invite_in_project(email, project, invitor) + def send_invite_in_project(email, project, invitor) @email = email @subject = "#{invitor.name} #{l(:label_invite_project)} #{project.name} " @password = newpass(6) @@ -208,44 +208,17 @@ class Mailer < ActionMailer::Base end # 作业截止时间邮件提醒 - def homework_endtime__added(homework_common, course) - # modify by nwb - #如果是直接留言并且留言对象是课程 - if !journals_for_message.at_user && journals_for_message.jour.class.to_s.to_sym == :Course - - @author = journals_for_message.user - #课程的教师 - @members = course_all_member journals_for_message.jour - - - #收件人邮箱 - students = course.student - recipients ||= [] - students.each do |students| - recipients << recipients.user.mail - end - mail :to => @recipients, - :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} ", - :filter => true - # elsif journals_for_message.jour.class.to_s.to_sym == :Bid - # if !journals_for_message.jour.author.notify_about? journals_for_message - # return -1 - # end - # - # mail :to => recipients, :subject => @title,:filter => true - elsif journals_for_message.jour.class.to_s.to_sym == :Contest - if !journals_for_message.jour.author.notify_about? journals_for_message - return -1 - end - mail :to => recipients, :subject => @title,:filter => true - else - mail :to => recipients1, :subject => @title,:filter => true - end - recipients ||= [] - # 将帖子创建者邮箱地址加入数组 - recipients << course.student - # 回复人邮箱地址加入数组 - recipients << @author.mail + def homework_endtime__added(homework_common, user_id) + user = User.find(user_id) + @subject = "#{l(:mail_homework)}#{homework_common.name}#{l(:mail_homework_endtime)} " + @token = Token.get_token_from_user(user, 'autologin') + @homework_endtime_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @homework_endtime_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipient = user.mail + mail :to => recipient, + :subject => "#{l(:mail_homework)}#{homework_common.name}#{l(:mail_homework_endtime)} " end # 公共讨论区发帖、回帖添加邮件发送信息 diff --git a/app/views/mailer/homework_endtime__added.html.erb b/app/views/mailer/homework_endtime__added.html.erb new file mode 100644 index 000000000..ce832d362 --- /dev/null +++ b/app/views/mailer/homework_endtime__added.html.erb @@ -0,0 +1,13 @@ +
+ +
+
+ + diff --git a/app/views/mailer/homework_endtime__added.text.erb b/app/views/mailer/homework_endtime__added.text.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/locales/mailers/zh.yml b/config/locales/mailers/zh.yml index 211f2e62d..fea392421 100644 --- a/config/locales/mailers/zh.yml +++ b/config/locales/mailers/zh.yml @@ -24,3 +24,5 @@ zh: mail_course_title_userin: "在课程" mail_course_homework_active: "中发布了作业" mail_attention: "请您关注!" + mail_homework_endtime: "作业截止时间快到了!" + mail_homework: "作业:" \ No newline at end of file diff --git a/lib/tasks/homework_endtime.rake b/lib/tasks/homework_endtime.rake index fe92842e3..1a400dc32 100644 --- a/lib/tasks/homework_endtime.rake +++ b/lib/tasks/homework_endtime.rake @@ -10,7 +10,8 @@ namespace :homework_endtime do if homework_common.end_time.day - Date.today.day < 2 && homework_common.end_time.year == Date.today.year homework_common.course.student.each do |s| homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :status => true) - Mailer.run.homework_endtime__added(homework_common, homework_common.course) + # 发送邮件通知 + Mailer.homework_endtime__added(homework_common, s.student_id).deliver end end end