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 @@ +
<%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @homework_endtime_name, @homework_endtime_url%> 截止时间快到了!
+如果您还未交作业,请赶紧提交作业!
+ +