1、匿评关闭/开启发送对象为所有成员

2、匿评方法封装
3、匿评开启/关闭邮件通知发送对象为课程所有成员
This commit is contained in:
huang 2015-09-28 15:35:08 +08:00
parent 2873412d1a
commit ba569403c3
4 changed files with 12 additions and 15 deletions

View File

@ -148,9 +148,9 @@ class HomeworkCommonController < ApplicationController
# 开启/关闭匿评消息通知
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.student_id, :course_id => course.id, :viewed => false, :status => m_status)
course = homework.course
course.members.each do |m|
@homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status)
end
end
#提示

View File

@ -1,4 +1,7 @@
class CourseMessage < ActiveRecord::Base
# status说明 status在课程不同的类型区分不同的功能
# HomeworkCommonstatus
# nil发布了作业 1作业截止时间到了提醒2:开启匿评; 3关闭匿评 4匿评开始失败
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status
# 多态 虚拟关联

View File

@ -51,8 +51,8 @@ class Mailer < ActionMailer::Base
def send_mail_anonymous_comment_open(homework_common)
course = homework_common.course
recipients ||= []
course.student.each do |student|
user = User.find(student.student_id)
course.members.each do |member|
user = User.find(member.user_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))
@ -69,8 +69,8 @@ class Mailer < ActionMailer::Base
def send_mail_anonymous_comment_close(homework_common)
course = homework_common.course
recipients ||= []
course.student.each do |student|
user = User.find(student.student_id)
course.members.each do |member|
user = User.find(member.user_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))

View File

@ -26,10 +26,7 @@ namespace :homework_evaluation do
end
homework_detail_manual.update_column('comment_status', 2)
# 匿评开启消息邮件通知,# 所有人
course = homework_common.course
course.members.each do |m|
homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
end
send_message_anonymous_comment(homework_common, 2)
# 邮件通知
Mailer.send_mail_anonymous_comment_close(homework_common).deliver
else
@ -64,10 +61,7 @@ namespace :homework_evaluation do
end
homework_detail_manual.update_column('comment_status', 3)
# 匿评关闭消息通知 给所有人发
course = homework_common.course
course.members.each do |m|
homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3)
end
send_message_anonymous_comment(homework_common, 3)
# 邮件通知
Mailer.send_mail_anonymous_comment_close(homework_common).deliver
end