socialforge/lib/tasks/homework_publishtime.rake

35 lines
1.3 KiB
Ruby
Raw Normal View History

2015-10-30 13:58:54 +08:00
#coding=utf-8
namespace :homework_publishtime do
desc "start publish homework and end homework"
2015-10-30 13:58:54 +08:00
task :publish => :environment do
homework_commons = HomeworkCommon.where("publish_time = '#{Date.today}'")
homework_commons.each do |homework|
homework_detail_manual = homework.homework_detail_manual
if homework_detail_manual.comment_status == 0
homework_detail_manual.update_column('comment_status', 1)
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 => nil)
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
task :end => :environment do
homework_commons = HomeworkCommon.where("end_time < '#{Date.today}'")
homework_commons.each do |homework|
if homework.anonymous_comment == 1
homework_detail_manual = homework.homework_detail_manual
if homework_detail_manual.comment_status == 1
homework_detail_manual.update_column('comment_status', 3)
end
end
end
end
2015-10-30 13:58:54 +08:00
end