为班级新添加的学生创建已发布作业的作品,状态为未提交
This commit is contained in:
parent
cd23ba37b5
commit
5251ab9ca2
|
@ -1,3 +1,4 @@
|
|||
#encoding: utf-8
|
||||
class StudentsForCourse < ActiveRecord::Base
|
||||
attr_accessible :course_id, :student_id
|
||||
|
||||
|
@ -9,7 +10,7 @@ class StudentsForCourse < ActiveRecord::Base
|
|||
validates_uniqueness_of :student_id, :scope => :course_id
|
||||
|
||||
after_destroy :delete_student_works
|
||||
after_create :recovery_student_works
|
||||
after_create :recovery_student_works, :create_student_works
|
||||
|
||||
#退出班级或删除学生时隐藏学生的作品
|
||||
def delete_student_works
|
||||
|
@ -26,4 +27,14 @@ class StudentsForCourse < ActiveRecord::Base
|
|||
student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}")
|
||||
student_works.update_all(:is_delete => 0)
|
||||
end
|
||||
|
||||
#加入班级时创建已发布作业的作品
|
||||
def create_student_works
|
||||
course = self.course
|
||||
course.homework_commons.each do |hw|
|
||||
if hw.homework_type != 3 && hw.student_works.where("user_id = #{self.student_id}").count == 0
|
||||
hw.student_works << StudentWork.new(:user_id => self.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#encoding: utf-8
|
||||
class AddStudentWorkData < ActiveRecord::Migration
|
||||
def up
|
||||
count = Course.all.count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 .. count do i
|
||||
Course.page(i).per(30).each do |course|
|
||||
begin
|
||||
course.student.each do |student|
|
||||
course.homework_commons.each do |hw|
|
||||
if hw.homework_type != 3 && hw.student_works.where("user_id = #{student.student_id}").count == 0
|
||||
hw.student_works << StudentWork.new(:user_id => student.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
logger.error "[AddStudentWorkData] ===> #{e}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue