socialforge/lib/tasks/homework_publishtime.rake

51 lines
2.0 KiB
Ruby

#coding=utf-8
namespace :homework_publishtime do
desc "start publish homework and end homework"
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)
if homework.homework_type != 3
students = homework.course.student
if !homework.course.nil? && !students.empty?
name = homework.name
name_str = name + "的作品提交"
str = ""
students.each do |student|
if str != ""
str += ","
end
str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')"
end
sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end
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
end