@ -16,7 +16,7 @@ class HomeworkCommonController < ApplicationController
before_filter :teacher_of_course , :only = > [ :new , :create , :edit , :update , :destroy , :start_anonymous_comment , :stop_anonymous_comment , :alert_anonymous_comment ,
before_filter :teacher_of_course , :only = > [ :new , :create , :edit , :update , :destroy , :start_anonymous_comment , :stop_anonymous_comment , :alert_anonymous_comment ,
:start_evaluation_set , :set_evaluation_attr , :score_rule_set , :alert_forbidden_anonymous_comment , :alert_open_student_works ,
:start_evaluation_set , :set_evaluation_attr , :score_rule_set , :alert_forbidden_anonymous_comment , :alert_open_student_works ,
:open_student_works , :add_to_homework_bank , :publish_notice , :end_notice , :publish_homework , :end_homework , :update_explanation ,
:open_student_works , :add_to_homework_bank , :publish_notice , :end_notice , :publish_homework , :end_homework , :update_explanation ,
:cancel_publish , :move_to_category ]
:cancel_publish , :move_to_category , :homework_setting ]
# before_filter :member_of_course, :only => [:index,:setting]
# before_filter :member_of_course, :only => [:index,:setting]
@ -282,93 +282,94 @@ class HomeworkCommonController < ApplicationController
end
end
def homework_setting
def homework_setting
if @homework . homework_detail_manual . try ( :comment_status ) == 0 && @course . course_groups . count > 1
ActiveRecord :: Base . transaction do
@homework . unified_setting = params [ :unified_setting ] ? true :false
if @homework . homework_detail_manual . try ( :comment_status ) == 0 && @course . course_groups . count > 1
end
@homework . unified_setting = params [ :unified_setting ] ? true :false
end
if @homework . unified_setting
if @homework . unified_setting
params_publish_time = params [ :homework_publish_time ]
params_publish_time = params [ :homework_publish_time ]
params_end_time = params [ :homework_end_time ]
params_end_time = params [ :homework_end_time ]
# params_archive_time = params[:homework_archive_time]
# params_archive_time = params[:homework_archive_time]
min_publish_time = params_publish_time
min_publish_time = params_publish_time
max_end_time = params_end_time
max_end_time = params_end_time
else
else
# 获取最小发布时间和最大截止时间, 赋值给homework
# 获取最小发布时间和最大截止时间, 赋值给homework
params_publish_time = params [ :homework_publish_time_group ]
params_publish_time = params [ :homework_publish_time_group ]
params_end_time = params [ :homework_end_time_group ]
params_end_time = params [ :homework_end_time_group ]
# params_archive_time = params[:homework_archive_time_group]
# params_archive_time = params[:homework_archive_time_group]
min_publish_time = @homework . publish_time ? ( format_time @homework . publish_time ) . to_s : " "
min_publish_time = @homework . publish_time ? ( format_time @homework . publish_time ) . to_s : " "
max_end_time = @homework . end_time ? ( format_time @homework . end_time ) . to_s : " "
max_end_time = @homework . end_time ? ( format_time @homework . end_time ) . to_s : " "
if params [ :homework_end_time_group ]
if params [ :homework_end_time_group ]
max_end_time = " "
max_end_time = " "
params [ :homework_end_time_group ] . each_with_index do | end_time , index |
params [ :homework_end_time_group ] . each_with_index do | end_time , index |
if end_time != " "
if end_time != " "
if max_end_time == " " || end_time > max_end_time
if max_end_time == " " || end_time > max_end_time
max_end_time = end_time
max_end_time = end_time
end
end
end
end
end
end
end
end
if params [ :homework_publish_time_group ]
if params [ :homework_publish_time_group ]
params [ :homework_publish_time_group ] . each_with_index do | publish_time , index |
params [ :homework_publish_time_group ] . each_with_index do | publish_time , index |
if publish_time != " "
if publish_time != " "
if min_publish_time == " " || publish_time < min_publish_time
if min_publish_time == " " || publish_time < min_publish_time
min_publish_time = publish_time
min_publish_time = publish_time
end
end
end
end
end
end
end
end
end
end
# 不统一设置且分班数大于一则更新分组设置
# 不统一设置且分班数大于一则更新分组设置
if ! @homework . unified_setting && @course . course_groups . count > 1
if ! @homework . unified_setting && @course . course_groups . count > 1
@course . course_groups . each_with_index do | group , index |
@course . course_groups . each_with_index do | group , index |
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
unless homework_group_setting
unless homework_group_setting
homework_group_setting = HomeworkGroupSetting . create ( :homework_common_id = > @homework . id , :course_group_id = > group . id , :course_id = > @course . id )
homework_group_setting = HomeworkGroupSetting . create ( :homework_common_id = > @homework . id , :course_group_id = > group . id , :course_id = > @course . id )
end
end
end
end
group_id = [ ]
group_id = [ ]
@homework . homework_group_settings . where ( " publish_time is null or publish_time > ' #{ Time . now } ' " ) . joins ( :course_group ) . reorder ( " CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC " ) . each_with_index do | setting , index |
@homework . homework_group_settings . where ( " publish_time is null or publish_time > ' #{ Time . now } ' " ) . joins ( :course_group ) . reorder ( " CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC " ) . each_with_index do | setting , index |
if params [ :homework_publish_time_group ] && min_publish_time != " "
if params [ :homework_publish_time_group ] && min_publish_time != " "
if params [ :homework_publish_time_group ] [ index ] && params [ :homework_publish_time_group ] [ index ] != " "
if params [ :homework_publish_time_group ] [ index ] && params [ :homework_publish_time_group ] [ index ] != " "
setting . update_column ( :publish_time , params [ :homework_publish_time_group ] [ index ] )
setting . update_column ( :publish_time , params [ :homework_publish_time_group ] [ index ] )
end
elsif params [ :homework_publish_time_group ] && min_publish_time == " "
setting . update_column ( :publish_time , Time . now )
group_id << setting . course_group_id
end
end
elsif params [ :homework_publish_time_group ] && min_publish_time == " "
setting . update_column ( :publish_time , Time . now )
group_id << setting . course_group_id
end
end
end
@homework . homework_group_settings . where ( " end_time is null or end_time > ' #{ Time . now } ' " ) . joins ( :course_group ) . reorder ( " CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC " ) . each_with_index do | setting , index |
@homework . homework_group_settings . where ( " end_time is null or end_time > ' #{ Time . now } ' " ) . joins ( :course_group ) . reorder ( " CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC " ) . each_with_index do | setting , index |
if params [ :homework_end_time_group ] && max_end_time != " "
if params [ :homework_end_time_group ] && max_end_time != " "
if params [ :homework_end_time_group ] [ index ] && params [ :homework_end_time_group ] [ index ] != " "
if params [ :homework_end_time_group ] [ index ] && params [ :homework_end_time_group ] [ index ] != " "
setting . update_column ( :end_time , params [ :homework_end_time_group ] [ index ] )
setting . update_column ( :end_time , params [ :homework_end_time_group ] [ index ] )
end
elsif params [ :homework_end_time_group ] && max_end_time == " "
setting . update_column ( :end_time , Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
end
end
elsif params [ :homework_end_time_group ] && max_end_time == " "
setting . update_column ( :end_time , Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
end
end
# 统一设置则删除分组设置
elsif @homework . unified_setting
@homework . homework_group_settings . destroy_all
end
end
# 统一设置则删除分组设置
elsif @homework . unified_setting
@homework . homework_group_settings . destroy_all
end
# homework 的记录更新
# homework 的记录更新
# 发布时间不为空
# 发布时间不为空
if params_publish_time && min_publish_time != " "
if params_publish_time && min_publish_time != " "
@homework . publish_time = min_publish_time
@homework . publish_time = min_publish_time
@homework . end_time = max_end_time
@homework . end_time = max_end_time
# @homework.archive_time = params_archive_time if params_archive_time
# @homework.archive_time = params_archive_time if params_archive_time
if @homework . publish_time < Time . now and @homework_detail_manual . comment_status == 0
if @homework . publish_time < Time . now and @homework_detail_manual . comment_status == 0
@homework_detail_manual . comment_status = 1
@homework_detail_manual . comment_status = 1
create_homework_user = 1
create_homework_user = 1
if @homework . course_acts . size == 0
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
end
end
end
end
= begin
= begin
if @homework . archive_time < Time . now && @homework_detail_manual . comment_status < 6
if @homework . archive_time < Time . now && @homework_detail_manual . comment_status < 6
@homework_detail_manual . comment_status = 6
@homework_detail_manual . comment_status = 6
@ -376,22 +377,22 @@ class HomeworkCommonController < ApplicationController
@homework_detail_manual . comment_status = 5
@homework_detail_manual . comment_status = 5
end
end
= end
= end
# 发布时间未设置 则按当前时间立即发布
# 发布时间未设置 则按当前时间立即发布
elsif params_publish_time && min_publish_time == " "
elsif params_publish_time && min_publish_time == " "
@homework_detail_manual . comment_status = 1
@homework_detail_manual . comment_status = 1
@homework . publish_time = Time . now
@homework . publish_time = Time . now
@homework . unified_setting = 1
@homework . unified_setting = 1
@homework . end_time = Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 )
@homework . end_time = Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 )
# @homework.archive_time = Time.at(((2.months.since.to_i)/3600.0).ceil * 3600)
# @homework.archive_time = Time.at(((2.months.since.to_i)/3600.0).ceil * 3600)
create_homework_user = 1
create_homework_user = 1
if @homework . course_acts . size == 0
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
end
end
# 已发布的作业,只更新截止时间和结束时间
# 已发布的作业,只更新截止时间和结束时间
else
else
@homework . end_time = max_end_time if params_end_time
@homework . end_time = max_end_time if params_end_time
# @homework.archive_time = params_archive_time if params_archive_time
# @homework.archive_time = params_archive_time if params_archive_time
= begin
= begin
if @homework . archive_time < Time . now && @homework_detail_manual . comment_status < 6
if @homework . archive_time < Time . now && @homework_detail_manual . comment_status < 6
@ -400,189 +401,190 @@ class HomeworkCommonController < ApplicationController
@homework_detail_manual . comment_status = 5
@homework_detail_manual . comment_status = 5
end
end
= end
= end
end
end
if params [ :homework_allow_late ] == '1'
if params [ :homework_allow_late ] == '1'
@homework . allow_late = true
@homework . allow_late = true
if @homework . late_penalty != params [ :homework_late_penalty ] . to_i
if @homework . late_penalty != params [ :homework_late_penalty ] . to_i
@homework . student_works . where ( :work_status = > 2 ) . each do | work |
@homework . student_works . where ( :work_status = > 2 ) . each do | work |
work . late_penalty = params [ :homework_late_penalty ] . to_i
work . late_penalty = params [ :homework_late_penalty ] . to_i
work . save
work . save
end
end
end
@homework . late_penalty = params [ :homework_late_penalty ] . to_i
else
@homework . allow_late = false
@homework . late_penalty = 0
end
end
@homework . late_penalty = params [ :homework_late_penalty ] . to_i
else
@homework . allow_late = false
@homework . late_penalty = 0
end
anonymous_comment = @homework . anonymous_comment
anonymous_comment = @homework . anonymous_comment
absence_penalty = @homework_detail_manual . absence_penalty
absence_penalty = @homework_detail_manual . absence_penalty
appeal_penalty = @homework_detail_manual . appeal_penalty
appeal_penalty = @homework_detail_manual . appeal_penalty
if @homework_detail_manual . comment_status < 3
if @homework_detail_manual . comment_status < 3
if params [ :homework_anonymous_comment ]
if params [ :homework_anonymous_comment ]
@homework . anonymous_comment = 0
@homework . anonymous_comment = 0
@homework_detail_manual . evaluation_start = params [ :homework_evaluation_start ] if params [ :homework_evaluation_start ]
@homework_detail_manual . evaluation_start = params [ :homework_evaluation_start ] if params [ :homework_evaluation_start ]
@homework_detail_manual . evaluation_end = params [ :homework_evaluation_end ] if params [ :homework_evaluation_end ]
@homework_detail_manual . evaluation_num = params [ :homework_evaluation_num ] if params [ :homework_evaluation_num ]
@homework_detail_manual . absence_penalty = params [ :homework_absence_penalty ] if params [ :homework_absence_penalty ]
else
@homework . anonymous_comment = 1
@homework_detail_manual . evaluation_start = nil
@homework_detail_manual . evaluation_end = nil
@homework_detail_manual . evaluation_num = 0
@homework_detail_manual . absence_penalty = 0
end
else
@homework_detail_manual . evaluation_end = params [ :homework_evaluation_end ] if params [ :homework_evaluation_end ]
@homework_detail_manual . evaluation_end = params [ :homework_evaluation_end ] if params [ :homework_evaluation_end ]
@homework_detail_manual . evaluation_num = params [ :homework_evaluation_num ] if params [ :homework_evaluation_num ]
@homework_detail_manual . evaluation_num = params [ :homework_evaluation_num ] if params [ :homework_evaluation_num ]
@homework_detail_manual . absence_penalty = params [ :homework_absence_penalty ] if params [ :homework_absence_penalty ]
@homework_detail_manual . absence_penalty = params [ :homework_absence_penalty ] if params [ :homework_absence_penalty ]
end
if anonymous_comment != @homework . anonymous_comment
@homework_detail_manual . te_proportion = 1
@homework_detail_manual . ta_proportion = 0
@homework_detail_programing . ta_proportion = 0 if @homework_detail_programing
end
if @homework_detail_manual . comment_status < 4
if @homework . anonymous_comment == 0 && params [ :homework_anonymous_appeal ]
@homework . anonymous_appeal = 1
@homework_detail_manual . appeal_time = params [ :homework_appeal_time ] if params [ :homework_appeal_time ]
@homework_detail_manual . appeal_penalty = params [ :homework_appeal_penalty ] if params [ :homework_appeal_penalty ]
else
@homework . anonymous_appeal = 0
@homework_detail_manual . appeal_time = nil
@homework_detail_manual . appeal_penalty = 0
end
else
else
@homework . anonymous_comment = 1
@homework_detail_manual . evaluation_start = nil
@homework_detail_manual . evaluation_end = nil
@homework_detail_manual . evaluation_num = 0
@homework_detail_manual . absence_penalty = 0
end
else
@homework_detail_manual . evaluation_end = params [ :homework_evaluation_end ] if params [ :homework_evaluation_end ]
@homework_detail_manual . evaluation_num = params [ :homework_evaluation_num ] if params [ :homework_evaluation_num ]
@homework_detail_manual . absence_penalty = params [ :homework_absence_penalty ] if params [ :homework_absence_penalty ]
end
if anonymous_comment != @homework . anonymous_comment
@homework_detail_manual . te_proportion = 1
@homework_detail_manual . ta_proportion = 0
@homework_detail_programing . ta_proportion = 0 if @homework_detail_programing
end
if @homework_detail_manual . comment_status < 4
if @homework . anonymous_comment == 0 && params [ :homework_anonymous_appeal ]
@homework . anonymous_appeal = 1
@homework_detail_manual . appeal_time = params [ :homework_appeal_time ] if params [ :homework_appeal_time ]
@homework_detail_manual . appeal_time = params [ :homework_appeal_time ] if params [ :homework_appeal_time ]
@homework_detail_manual . appeal_penalty = params [ :homework_appeal_penalty ] if params [ :homework_appeal_penalty ]
@homework_detail_manual . appeal_penalty = params [ :homework_appeal_penalty ] if params [ :homework_appeal_penalty ]
else
@homework . anonymous_appeal = 0
@homework_detail_manual . appeal_time = nil
@homework_detail_manual . appeal_penalty = 0
end
else
@homework_detail_manual . appeal_time = params [ :homework_appeal_time ] if params [ :homework_appeal_time ]
@homework_detail_manual . appeal_penalty = params [ :homework_appeal_penalty ] if params [ :homework_appeal_penalty ]
end
if absence_penalty != @homework_detail_manual . absence_penalty && @homework_detail_manual . comment_status > = 4
all_dis_eva = StudentWorksEvaluationDistribution . where ( :student_work_id = > @homework . student_works . map ( & :id ) )
has_sw_count = all_dis_eva . select ( " distinct user_id " ) . count
anon_count = all_dis_eva . count / has_sw_count
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
absence_penalty_count = student_work . user . student_works_evaluation_distributions . where ( :student_work_id = > @homework . student_works . map ( & :id ) ) . count - student_work . user . student_works_scores . where ( :student_work_id = > @homework . student_works . map ( & :id ) , :reviewer_role = > 3 ) . count
student_work . absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual . absence_penalty : 0
student_work . save
end
end
end
if absence_penalty != @homework_detail_manual . absence_penalty && @homework_detail_manual . comment_status > = 4
if appeal_penalty != @homework_detail_manual . appeal_penalty && @homework_detail_manual . comment_status > = 4
all_dis_eva = StudentWorksEvaluationDistribution . where ( :student_work_id = > @homework . student_works . map ( & :id ) )
@homework . student_works . each do | student_work |
has_sw_count = all_dis_eva . select ( " distinct user_id " ) . count
appeal_penalty_count = student_work . user . student_works_scores . where ( :student_work_id = > @homework . student_works . map ( & :id ) , :appeal_status = > 3 ) . count
anon_count = all_dis_eva . count / has_sw_count
student_work . appeal_penalty = appeal_penalty_count > 0 ? appeal_penalty_count * @homework_detail_manual . absence_penalty : 0
student_work . save
end
end
# 助教评分模式有变更 则更新学生分数
if params [ :homework_ta_mode ] && @homework_detail_manual . ta_mode . to_i != params [ :homework_ta_mode ] . to_i
@homework_detail_manual . ta_mode = params [ :ta_mode ] . to_i
@homework_detail_manual . save
if @homework_detail_manual . ta_mode == 1
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
ts_score = StudentWorksScore . find_by_sql ( " SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{ student_work . id } AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a " )
absence_penalty_count = student_work . user . student_works_evaluation_distributions . where ( :student_work_id = > @homework . student_works . map ( & :id ) ) . count - student_work . user . student_works_scores . where ( :student_work_id = > @homework . student_works . map ( & :id ) , :reviewer_role = > 3 ) . count
student_work . teaching_asistant_score = ts_score . first . score . nil? ? nil : ts_score . first . score . try ( :round , 2 ) . to_f
student_work . absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual . absence_penalty : 0
student_work . save
student_work . save
end
end
else
end
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
if appeal_penalty != @homework_detail_manual . appeal_penalty && @homework_detail_manual . comment_status > = 4
ts_score = StudentWorksScore . where ( " student_work_id = #{ student_work . id } AND reviewer_role = 2 AND score IS NOT NULL " ) . order ( " created_at DESC " )
@homework . student_works . each do | student_work |
student_work . teaching_asistant_score = ts_score . first . nil? ? nil : ts_score . first . score
appeal_penalty_count = student_work . user . student_works_scores . where ( :student_work_id = > @homework . student_works . map ( & :id ) , :appeal_status = > 3 ) . count
student_work . appeal_penalty = appeal_penalty_count > 0 ? appeal_penalty_count * @homework_detail_manual . absence_penalty : 0
student_work . save
student_work . save
end
end
end
end
end
# 最终成绩组成
# 助教评分模式有变更 则更新学生分数
if params [ :homework_final_mode ] && params [ :homework_final_mode ] . to_i != @homework_detail_manual . final_mode
if params [ :homework_ta_mode ] && @homework_detail_manual . ta_mode . to_i != params [ :homework_ta_mode ] . to_i
@homework_detail_manual . final_mode = params [ :homework_final_mode ] . to_i
@homework_detail_manual . ta_mode = params [ :ta_mode ] . to_i
if params [ :homework_final_mode ] . to_i == 0
@homework_detail_manual . save
@homework_detail_manual . te_proportion = params [ :te_proportion ]
if @homework_detail_manual . ta_mode == 1
@homework_detail_manual . ta_proportion = params [ :ta_proportion ]
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
@homework_detail_programing . ta_proportion = params [ :sy_proportion ] if @homework_detail_programing
ts_score = StudentWorksScore . find_by_sql ( " SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{ student_work . id } AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a " )
@homework_detail_programing . save if @homework_detail_programing
student_work . teaching_asistant_score = ts_score . first . score . nil? ? nil : ts_score . first . score . try ( :round , 2 ) . to_f
end
student_work . save
@homework_detail_manual . save if @homework_detail_manual
end
@homework . save
else
@homework = HomeworkCommon . find @homework . id
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
ts_score = StudentWorksScore . where ( " student_work_id = #{ student_work . id } AND reviewer_role = 2 AND score IS NOT NULL " ) . order ( " created_at DESC " )
# set_final_score @homework,student_work
student_work . teaching_asistant_score = ts_score . first . nil? ? nil : ts_score . first . score
student_work . save
student_work . save
end
end
end
end
elsif params [ :homework_final_mode ] && @homework_detail_manual . final_mode == 0
if ( params [ :te_proportion ] && params [ :te_proportion ] . to_s != @homework_detail_manual . te_proportion . to_s ) || ( params [ :ta_proportion ] && params [ :ta_proportion ] . to_s != @homework_detail_manual . ta_proportion . to_s ) || ( @homework_detail_programing && @homework_detail_programing . ta_proportion . to_s != params [ :sy_proportion ] . to_s )
@homework_detail_manual . te_proportion = params [ :te_proportion ]
@homework_detail_manual . ta_proportion = params [ :ta_proportion ]
@homework_detail_programing . ta_proportion = params [ :sy_proportion ] if @homework_detail_programing
# 最终成绩组成
if params [ :homework_final_mode ] && params [ :homework_final_mode ] . to_i != @homework_detail_manual . final_mode
@homework_detail_manual . final_mode = params [ :homework_final_mode ] . to_i
if params [ :homework_final_mode ] . to_i == 0
@homework_detail_manual . te_proportion = params [ :te_proportion ]
@homework_detail_manual . ta_proportion = params [ :ta_proportion ]
@homework_detail_programing . ta_proportion = params [ :sy_proportion ] if @homework_detail_programing
@homework_detail_programing . save if @homework_detail_programing
end
@homework_detail_manual . save if @homework_detail_manual
@homework_detail_manual . save if @homework_detail_manual
@homework_detail_programing . save if @homework_detail_programing
@homework . save
@homework . save
@homework = HomeworkCommon . find @homework . id
@homework = HomeworkCommon . find @homework . id
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
# set_final_score @homework,student_work
# set_final_score @homework,student_work
student_work . save
student_work . save
end
end
elsif params [ :homework_final_mode ] && @homework_detail_manual . final_mode == 0
if ( params [ :te_proportion ] && params [ :te_proportion ] . to_s != @homework_detail_manual . te_proportion . to_s ) || ( params [ :ta_proportion ] && params [ :ta_proportion ] . to_s != @homework_detail_manual . ta_proportion . to_s ) || ( @homework_detail_programing && @homework_detail_programing . ta_proportion . to_s != params [ :sy_proportion ] . to_s )
@homework_detail_manual . te_proportion = params [ :te_proportion ]
@homework_detail_manual . ta_proportion = params [ :ta_proportion ]
@homework_detail_programing . ta_proportion = params [ :sy_proportion ] if @homework_detail_programing
@homework_detail_manual . save if @homework_detail_manual
@homework_detail_programing . save if @homework_detail_programing
@homework . save
@homework = HomeworkCommon . find @homework . id
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
# set_final_score @homework,student_work
student_work . save
end
end
end
end
end
if @homework . homework_type == 4
if @homework . homework_type == 4
@homework . work_efficiency = params [ :work_efficiency ] ? 1 : 0
@homework . work_efficiency = params [ :work_efficiency ] ? 1 : 0
if params [ :eff_score ] != @homework . eff_score
if params [ :eff_score ] != @homework . eff_score
@homework . eff_score = params [ :eff_score ]
@homework . eff_score = params [ :eff_score ]
score_change = true
score_change = true
end
end
if @homework_detail_manual . answer_open_evaluation != params [ :answer_open_evaluation ] . to_i
if @homework_detail_manual . answer_open_evaluation != params [ :answer_open_evaluation ] . to_i
@homework_detail_manual . answer_open_evaluation = params [ :answer_open_evaluation ] . to_i
@homework_detail_manual . answer_open_evaluation = params [ :answer_open_evaluation ] . to_i
score_change = true
score_change = true
end
end
if @homework_detail_manual . shixun_evaluation != params [ :shixun_evaluation ] . to_i
if @homework_detail_manual . shixun_evaluation != params [ :shixun_evaluation ] . to_i
@homework_detail_manual . shixun_evaluation = params [ :shixun_evaluation ] . to_i
@homework_detail_manual . shixun_evaluation = params [ :shixun_evaluation ] . to_i
score_change = true
score_change = true
end
end
if params [ :challenge ]
if params [ :challenge ]
score_change = true
score_change = true
params [ :challenge ] . each_with_index do | challenge_id , index |
params [ :challenge ] . each_with_index do | challenge_id , index |
setting = @homework . homework_challenge_settings . where ( :challenge_id = > challenge_id ) . first
setting = @homework . homework_challenge_settings . where ( :challenge_id = > challenge_id ) . first
if setting
if setting
setting . update_attributes ( :score = > params [ :score ] [ index ] )
setting . update_attributes ( :score = > params [ :score ] [ index ] )
else
else
HomeworkChallengeSetting . create ( :homework_common_id = > @homework . id , :challenge_id = > challenge_id , :shixun_id = > @homework . homework_commons_shixuns . shixun_id , :score = > params [ :score ] [ index ] )
HomeworkChallengeSetting . create ( :homework_common_id = > @homework . id , :challenge_id = > challenge_id , :shixun_id = > @homework . homework_commons_shixuns . shixun_id , :score = > params [ :score ] [ index ] )
end
end
end
@homework . homework_challenge_settings . where ( " challenge_id not in ( #{ params [ :challenge ] . join ( ',' ) } ) " ) . destroy_all
end
end
@homework . homework_challenge_settings . where ( " challenge_id not in ( #{ params [ :challenge ] . join ( ',' ) } ) " ) . destroy_all
@homework . score_open = params [ :homework_score_open ] ? 1 : 0
end
@homework . save!
@homework . score_open = params [ :homework_score_open ] ? 1 : 0
if score_change
@homework . save!
homework_challenge_settings = HomeworkChallengeSetting . where ( :homework_common_id = > @homework . id )
if score_change
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
homework_challenge_settings = HomeworkChallengeSetting . where ( :homework_common_id = > @homework . id )
set_shixun_final_score student_work , @homework_detail_manual . answer_open_evaluation , homework_challenge_settings
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
end
set_shixun_final_score student_work , @homework_detail_manual . answer_open_evaluation , homework_challenge_settings
# 更新所有学生的效率分
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
end
end
# 更新所有学生的效率分
else
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
@homework . work_public = params [ :homework_work_public ] ? 1 : 0
@homework . score_open = params [ :homework_score_open ] ? 1 : 0
@homework . answer_public = params [ :homework_answer_public ] ? 1 : 0
@homework . comment_public = params [ :homework_comment_public ] ? 1 : 0
@homework . save!
end
end
else
@homework_detail_manual . save
@homework . work_public = params [ :homework_work_public ] ? 1 : 0
if create_homework_user . present?
@homework . score_open = params [ :homework_score_open ] ? 1 : 0
if group_id . present? && group_id . size != 0
@homework . answer_public = params [ :homework_answer_public ] ? 1 : 0
if group_id . size == @course . course_groups . count
@homework . comment_public = params [ :homework_comment_public ] ? 1 : 0
create_works_tiding @homework , @course . student
@homework . save!
else
end
members = @course . members . where ( :course_group_id = > group_id )
@homework_detail_manual . save
create_works_tiding @homework , members
if create_homework_user . present?
end
if group_id . present? && group_id . size != 0
if group_id . size == @course . course_groups . count
create_works_tiding @homework , @course . student
else
else
members = @course . members . where ( :course_group_id = > group_id )
create_works_tiding @homework , @course . student
create_works_tiding @homework , members
end
end
else
create_works_tiding @homework , @course . student
end
end
end
end
redirect_to student_work_index_path ( :homework = > @homework . id )
redirect_to student_work_index_path ( :homework = > @homework . id )
@ -929,60 +931,62 @@ class HomeworkCommonController < ApplicationController
end
end
def publish_homework
def publish_homework
if @homework . homework_detail_manual . try ( :comment_status ) == 0
ActiveRecord :: Base . transaction do
if params [ :group_ids ]
if @homework . homework_detail_manual . try ( :comment_status ) == 0
if @course . course_groups . where ( :id = > params [ :group_ids ] . split ( " , " ) ) . count == @course . course_groups . count
if params [ :group_ids ]
@homework . homework_group_settings . destroy_all
if @course . course_groups . where ( :id = > params [ :group_ids ] . split ( " , " ) ) . count == @course . course_groups . count
@homework . update_attribute ( " unified_setting " , true )
@homework . homework_group_settings . destroy_all
# 发消息
@homework . update_attribute ( " unified_setting " , true )
create_works_tiding @homework , @course . student
# 发消息
else
create_works_tiding @homework , @course . student
@homework . update_attribute ( " unified_setting " , false )
else
@course . course_groups . each do | group |
@homework . update_attribute ( " unified_setting " , false )
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
@course . course_groups . each do | group |
unless homework_group_setting
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
HomeworkGroupSetting . create ( :homework_common_id = > @homework . id , :course_group_id = > group . id , :course_id = > @course . id , :publish_time = > @homework . publish_time , :end_time = > @homework . end_time )
unless homework_group_setting
HomeworkGroupSetting . create ( :homework_common_id = > @homework . id , :course_group_id = > group . id , :course_id = > @course . id , :publish_time = > @homework . publish_time , :end_time = > @homework . end_time )
end
end
end
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) ) . update_all ( :publish_time = > Time . now )
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) , :end_time = > nil ) . update_all ( :end_time = > Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
# 发消息
members = @course . members . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) )
create_works_tiding @homework , members
end
end
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) ) . update_all ( :publish_time = > Time . now )
else
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) , :end_time = > nil ) . update_all ( :end_time = > Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
@homework . homework_group_settings . destroy_all
# 发消息
create_works_tiding @homework , @course . student
members = @course . members . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) )
create_works_tiding @homework , members
end
end
else
@homework . update_attribute ( " publish_time " , Time . now )
@homework . homework_group_settings . destroy_all
create_works_tiding @homework , @course . student
end
@homework . update_attribute ( " publish_time " , Time . now )
if @homework . end_time . nil?
if @homework . end_time . nil?
@homework . update_attribute ( " end_time " , Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
@homework . update_attribute ( " end_time " , Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
elsif HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . count > 0
elsif HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . count > 0
@homework . update_attribute ( " end_time " , HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . map ( & :end_time ) . max )
@homework . update_attribute ( " end_time " , HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . map ( & :end_time ) . max )
end
end
= begin
= begin
if @homework . archive_time . nil?
if @homework . archive_time . nil?
@homework . update_attribute ( " archive_time " , Time . at ( ( ( 2 . months . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
@homework . update_attribute ( " archive_time " , Time . at ( ( ( 2 . months . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
end
end
= end
= end
@homework . homework_detail_manual . update_attribute ( 'comment_status' , 1 )
@homework . homework_detail_manual . update_attribute ( 'comment_status' , 1 )
if @homework . course_acts . size == 0
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
end
else
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) ) . update_all ( :publish_time = > Time . now )
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) , :end_time = > nil ) . update_all ( :end_time = > Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
if HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . count > 0
@homework . update_attribute ( " end_time " , HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . map ( & :end_time ) . max )
end
# 发消息
members = @course . members . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) )
create_works_tiding @homework , members
end
end
else
if @homework . end_time > Time . now && @homework . homework_detail_manual . try ( :comment_status ) > 1
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) ) . update_all ( :publish_time = > Time . now )
@homework . homework_detail_manual . update_attribute ( " comment_status " , 1 )
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) , :end_time = > nil ) . update_all ( :end_time = > Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
if HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . count > 0
@homework . update_attribute ( " end_time " , HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . map ( & :end_time ) . max )
end
end
# 发消息
members = @course . members . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) )
create_works_tiding @homework , members
end
if @homework . end_time > Time . now && @homework . homework_detail_manual . try ( :comment_status ) > 1
@homework . homework_detail_manual . update_attribute ( " comment_status " , 1 )
end
end
redirect_to student_work_index_path ( :homework = > @homework . id )
redirect_to student_work_index_path ( :homework = > @homework . id )
end
end
@ -1032,7 +1036,8 @@ class HomeworkCommonController < ApplicationController
def end_homework
def end_homework
time = Time . now
time = Time . now
student_works = @homework . student_works . where ( " 0=1 " )
student_works = @homework . student_works . where ( " 0=1 " )
# if @homework.homework_detail_manual.try(:comment_status) == 1 && @homework.end_time > time
ActiveRecord :: Base . transaction do
# if @homework.homework_detail_manual.try(:comment_status) == 1 && @homework.end_time > time
if params [ :group_ids ]
if params [ :group_ids ]
# @homework.homework_group_settings.where(:course_group_id => params[:group_id]).where("publish_time > '#{Time.now}' or publish_time is null").update_all(:publish_time => time)
# @homework.homework_group_settings.where(:course_group_id => params[:group_id]).where("publish_time > '#{Time.now}' or publish_time is null").update_all(:publish_time => time)
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) ) . update_all ( :end_time = > time )
@homework . homework_group_settings . where ( :course_group_id = > params [ :group_ids ] . split ( " , " ) ) . update_all ( :end_time = > time )
@ -1069,7 +1074,9 @@ class HomeworkCommonController < ApplicationController
# 更新所有学生的效率分
# 更新所有学生的效率分
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
end
end
# end
# end
end
redirect_to student_work_index_path ( :homework = > @homework . id )
redirect_to student_work_index_path ( :homework = > @homework . id )
end
end