From 961b2bd5644e0a5c1deb29dd2f091fa3cebc82d5 Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 19 Sep 2015 10:54:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=90=AF/=E5=85=B3=E9=97=AD=E5=8C=BF?= =?UTF-8?q?=E8=AF=84=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 10 +-- app/models/mailer.rb | 18 +++--- ...send_mail_anonymous_comment_close.html.erb | 2 +- .../send_mail_anonymous_comment_open.html.erb | 2 +- app/views/users/user_messages.html.erb | 61 ++++++++++++++++++- db/schema.rb | 5 +- 6 files changed, 80 insertions(+), 18 deletions(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 01a8a9010..3d026e8ca 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -206,7 +206,8 @@ class HomeworkCommonController < ApplicationController end @homework_detail_manual.update_column('comment_status', 2) @statue = 1 - send_message_anonymous_comment(@homework, open=true) + # 匿评开启消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 2) Mailer.send_mail_anonymous_comment_open(@homework).deliver else @statue = 2 @@ -226,7 +227,8 @@ class HomeworkCommonController < ApplicationController student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save end - send_message_anonymous_comment(@homework, open = false) + # 匿评关闭消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 3) Mailer.send_mail_anonymous_comment_close(@homework).deliver respond_to do |format| format.js @@ -234,11 +236,11 @@ class HomeworkCommonController < ApplicationController end # 开启/关闭匿评消息通知 - def send_message_anonymous_comment(homework, open) + def send_message_anonymous_comment(homework, m_status ) # status 标记匿评状态 1为关闭 0为开启 course = @homework.course course.student.each do |st| - @homework.course_messages << CourseMessage.new(:user_id => st.user_id, :course_id => course.id, :viewed => false, :status => open ? true : false) + @homework.course_messages << CourseMessage.new(:user_id => st.student_id, :course_id => course.id, :viewed => false, :status => m_status) end end #提示 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index fd57b7031..07b2a345c 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -50,35 +50,37 @@ class Mailer < ActionMailer::Base # 作业匿评开启 def send_mail_anonymous_comment_open(homework_common) course = homework_common.course + recipients ||= [] course.student.each do |student| - user = student.user + user = User.find(student.student_id) @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" @token = Token.get_token_from_user(user, 'autologin') @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) @anonymous_comment_close_name = homework_common.name @author = homework_common.user #收件人邮箱 - recipient = user.mail - mail :to => recipient, - :subject => @subject + recipients << user.mail end + mail :to => recipients, + :subject => @subject end # 作业匿评关闭 def send_mail_anonymous_comment_close(homework_common) course = homework_common.course + recipients ||= [] course.student.each do |student| - user = student.user + user = User.find(student.student_id) @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" @token = Token.get_token_from_user(user, 'autologin') @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) @anonymous_comment_close_name = homework_common.name @author = homework_common.user #收件人邮箱 - recipient = user.mail - mail :to => recipient, - :subject => @subject + recipients << user.mail end + mail :to => recipients, + :subject => @subject end # author: alan diff --git a/app/views/mailer/send_mail_anonymous_comment_close.html.erb b/app/views/mailer/send_mail_anonymous_comment_close.html.erb index 07bde8ebd..128f9fae8 100644 --- a/app/views/mailer/send_mail_anonymous_comment_close.html.erb +++ b/app/views/mailer/send_mail_anonymous_comment_close.html.erb @@ -2,7 +2,7 @@ diff --git a/app/views/mailer/send_mail_anonymous_comment_open.html.erb b/app/views/mailer/send_mail_anonymous_comment_open.html.erb index e791c86f9..5409ade55 100644 --- a/app/views/mailer/send_mail_anonymous_comment_open.html.erb +++ b/app/views/mailer/send_mail_anonymous_comment_open.html.erb @@ -2,7 +2,7 @@ diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index ab030f6c9..63b2fb80a 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -109,7 +109,7 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> - <% if ma.course_message_type == "HomeworkCommon" && ma.status != 1 %> + <% if ma.course_message_type == "HomeworkCommon" && ma.status.nil? %> <% end %> + + <% if ma.course_message_type == "HomeworkCommon" && ma.status == 2 %> + + <% end %> + + <% if ma.course_message_type == "HomeworkCommon" && ma.status == 3 %> + + <% end %> + <% if ma.course_message_type == "Poll" %>