学生删除作品时将作品还原为初始状态

This commit is contained in:
cxt 2016-08-26 16:20:14 +08:00
parent cdffaed1ea
commit 0ce61bfee8
2 changed files with 27 additions and 17 deletions

View File

@ -734,24 +734,33 @@ class StudentWorkController < ApplicationController
end end
def destroy def destroy
if @work.destroy if @homework.homework_type == 3
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 if @work.destroy
pros = @work.student_work_projects.where("is_leader = 0") if @homework.homework_detail_group.base_on_project == 1
pros.each do |pro| pros = @work.student_work_projects.where("is_leader = 0")
pro.destroy pros.each do |pro|
end pro.destroy
project = @work.student_work_projects.where("is_leader = 1").first end
project.update_attributes(:student_work_id => nil) project = @work.student_work_projects.where("is_leader = 1").first
elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 project.update_attributes(:student_work_id => nil)
@work.student_work_projects.each do |pro2| elsif @homework.homework_detail_group.base_on_project == 0
pro2.destroy @work.student_work_projects.each do |pro2|
pro2.destroy
end
end end
end end
respond_to do |format| else
format.html { @work.attachments.destroy_all
redirect_to student_work_index_url(:homework => @homework.id) @work.student_works_scores.destroy_all
} @work.course_messages.destroy_all
end @work.student_work_tests.destroy_all
@work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil)
@work.update_column("work_score",nil)
end
respond_to do |format|
format.html {
redirect_to student_work_index_url(:homework => @homework.id)
}
end end
end end
@ -794,6 +803,7 @@ class StudentWorkController < ApplicationController
elsif @homework.homework_type == 1 elsif @homework.homework_type == 1
@work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil)
@work.attachments.destroy_all @work.attachments.destroy_all
@work.course_messages.destroy_all
end end
@student_work = StudentWork.new @student_work = StudentWork.new
respond_to do |format| respond_to do |format|

View File

@ -1,6 +1,6 @@
#学生提交作品表 #学生提交作品表
class StudentWork < ActiveRecord::Base class StudentWork < ActiveRecord::Base
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time
belongs_to :homework_common belongs_to :homework_common
belongs_to :user belongs_to :user