socialforge/lib/tasks/exercise_close_to_deadline_...

22 lines
1.0 KiB
Ruby
Raw Normal View History

2015-12-04 10:56:16 +08:00
#coding=utf-8
namespace :exercise_deadline_warn do
desc "exercise deadline warn"
task :deadline_warn => :environment do
exercises = Exercise.where("date_format(end_time,'%Y-%m-%d')= '#{Date.today}'") #截止日期都是当天 23.59分,所以年月日相等的一定是今晚会截止的测验
exercises.each do |exercise|
if exercise.exercise_status == 2 #发布的作业才能告给学生发截止消息
course = exercise.course
course.members.each do |m|
#CourseMessage status 1 未发布 status 2 已发布 status 3 已发布快截止了
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) unless m.user.allowed_to?(:as_teacher,m)
end
# if homework.course_acts.size == 0
# homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
# end
# 邮件通知
#Mailer.run.homework_added(homework)
end
end
end
end