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

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,26 +734,35 @@ class StudentWorkController < ApplicationController
end
def destroy
if @homework.homework_type == 3
if @work.destroy
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
if @homework.homework_detail_group.base_on_project == 1
pros = @work.student_work_projects.where("is_leader = 0")
pros.each do |pro|
pro.destroy
end
project = @work.student_work_projects.where("is_leader = 1").first
project.update_attributes(:student_work_id => nil)
elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0
elsif @homework.homework_detail_group.base_on_project == 0
@work.student_work_projects.each do |pro2|
pro2.destroy
end
end
end
else
@work.attachments.destroy_all
@work.student_works_scores.destroy_all
@work.course_messages.destroy_all
@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
def delete_work
@work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first
@ -794,6 +803,7 @@ class StudentWorkController < ApplicationController
elsif @homework.homework_type == 1
@work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil)
@work.attachments.destroy_all
@work.course_messages.destroy_all
end
@student_work = StudentWork.new
respond_to do |format|

View File

@ -1,6 +1,6 @@
#学生提交作品表
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 :user