@ -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 ,
: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 ,
:cancel_publish , :move_to_category ]
:cancel_publish , :move_to_category , :homework_setting ]
# before_filter :member_of_course, :only => [:index,:setting]
@ -282,93 +282,94 @@ class HomeworkCommonController < ApplicationController
end
def homework_setting
if @homework . homework_detail_manual . try ( :comment_status ) == 0 && @course . course_groups . count > 1
@homework . unified_setting = params [ :unified_setting ] ? true :false
end
ActiveRecord :: Base . transaction do
if @homework . homework_detail_manual . try ( :comment_status ) == 0 && @course . course_groups . count > 1
@homework . unified_setting = params [ :unified_setting ] ? true :false
end
if @homework . unified_setting
params_publish_time = params [ :homework_publish_time ]
params_end_time = params [ :homework_end_time ]
# params_archive_time = params[:homework_archive_time]
min_publish_time = params_publish_time
max_end_time = params_end_time
else
# 获取最小发布时间和最大截止时间, 赋值给homework
params_publish_time = params [ :homework_publish_time_group ]
params_end_time = params [ :homework_end_time_group ]
# params_archive_time = params[:homework_archive_time_group]
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 : " "
if params [ :homework_end_time_group ]
max_end_time = " "
params [ :homework_end_time_group ] . each_with_index do | end_time , index |
if end_time != " "
if max_end_time == " " || end_time > max_end_time
max_end_time = end_time
if @homework . unified_setting
params_publish_time = params [ :homework_publish_time ]
params_end_time = params [ :homework_end_time ]
# params_archive_time = params[:homework_archive_time]
min_publish_time = params_publish_time
max_end_time = params_end_time
else
# 获取最小发布时间和最大截止时间, 赋值给homework
params_publish_time = params [ :homework_publish_time_group ]
params_end_time = params [ :homework_end_time_group ]
# params_archive_time = params[:homework_archive_time_group]
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 : " "
if params [ :homework_end_time_group ]
max_end_time = " "
params [ :homework_end_time_group ] . each_with_index do | end_time , index |
if end_time != " "
if max_end_time == " " || end_time > max_end_time
max_end_time = end_time
end
end
end
end
end
if params [ :homework_publish_time_group ]
params [ :homework_publish_time_group ] . each_with_index do | publish_time , index |
if publish_time != " "
if min_publish_time == " " || publish_time < min_publish_time
min_publish_time = publish_time
if params [ :homework_publish_time_group ]
params [ :homework_publish_time_group ] . each_with_index do | publish_time , index |
if publish_time != " "
if min_publish_time == " " || publish_time < min_publish_time
min_publish_time = publish_time
end
end
end
end
end
end
# 不统一设置且分班数大于一则更新分组设置
if ! @homework . unified_setting && @course . course_groups . count > 1
@course . course_groups . each_with_index do | group , index |
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
unless homework_group_setting
homework_group_setting = HomeworkGroupSetting . create ( :homework_common_id = > @homework . id , :course_group_id = > group . id , :course_id = > @course . id )
# 不统一设置且分班数大于一则更新分组设置
if ! @homework . unified_setting && @course . course_groups . count > 1
@course . course_groups . each_with_index do | group , index |
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
unless homework_group_setting
homework_group_setting = HomeworkGroupSetting . create ( :homework_common_id = > @homework . id , :course_group_id = > group . id , :course_id = > @course . id )
end
end
end
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 |
if params [ :homework_publish_time_group ] && min_publish_time != " "
if params [ :homework_publish_time_group ] [ index ] && params [ :homework_publish_time_group ] [ index ] != " "
setting . update_column ( :publish_time , params [ :homework_publish_time_group ] [ index ] )
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 |
if params [ :homework_publish_time_group ] && min_publish_time != " "
if params [ :homework_publish_time_group ] [ index ] && 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
elsif params [ :homework_publish_time_group ] && min_publish_time == " "
setting . update_column ( :publish_time , Time . now )
group_id << setting . course_group_id
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 |
if params [ :homework_end_time_group ] && max_end_time != " "
if params [ :homework_end_time_group ] [ index ] && params [ :homework_end_time_group ] [ index ] != " "
setting . update_column ( :end_time , params [ :homework_end_time_group ] [ 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 ] [ index ] && 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
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
# 统一设置则删除分组设置
elsif @homework . unified_setting
@homework . homework_group_settings . destroy_all
end
# 统一设置则删除分组设置
elsif @homework . unified_setting
@homework . homework_group_settings . destroy_all
end
# homework 的记录更新
# 发布时间不为空
if params_publish_time && min_publish_time != " "
@homework . publish_time = min_publish_time
@homework . end_time = max_end_time
# @homework.archive_time = params_archive_time if params_archive_time
if @homework . publish_time < Time . now and @homework_detail_manual . comment_status == 0
@homework_detail_manual . comment_status = 1
create_homework_user = 1
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
# homework 的记录更新
# 发布时间不为空
if params_publish_time && min_publish_time != " "
@homework . publish_time = min_publish_time
@homework . end_time = max_end_time
# @homework.archive_time = params_archive_time if params_archive_time
if @homework . publish_time < Time . now and @homework_detail_manual . comment_status == 0
@homework_detail_manual . comment_status = 1
create_homework_user = 1
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
end
end
end
= begin
if @homework . archive_time < Time . now && @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
end
= end
# 发布时间未设置 则按当前时间立即发布
elsif params_publish_time && min_publish_time == " "
@homework_detail_manual . comment_status = 1
@homework . publish_time = Time . now
@homework . unified_setting = 1
@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)
create_homework_user = 1
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
end
# 已发布的作业,只更新截止时间和结束时间
else
@homework . end_time = max_end_time if params_end_time
# @homework.archive_time = params_archive_time if params_archive_time
# 发布时间未设置 则按当前时间立即发布
elsif params_publish_time && min_publish_time == " "
@homework_detail_manual . comment_status = 1
@homework . publish_time = Time . now
@homework . unified_setting = 1
@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)
create_homework_user = 1
if @homework . course_acts . size == 0
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
end
# 已发布的作业,只更新截止时间和结束时间
else
@homework . end_time = max_end_time if params_end_time
# @homework.archive_time = params_archive_time if params_archive_time
= begin
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
end
= end
end
end
if params [ :homework_allow_late ] == '1'
@homework . allow_late = true
if @homework . late_penalty != params [ :homework_late_penalty ] . to_i
@homework . student_works . where ( :work_status = > 2 ) . each do | work |
work . late_penalty = params [ :homework_late_penalty ] . to_i
work . save
if params [ :homework_allow_late ] == '1'
@homework . allow_late = true
if @homework . late_penalty != params [ :homework_late_penalty ] . to_i
@homework . student_works . where ( :work_status = > 2 ) . each do | work |
work . late_penalty = params [ :homework_late_penalty ] . to_i
work . save
end
end
@homework . late_penalty = params [ :homework_late_penalty ] . to_i
else
@homework . allow_late = false
@homework . late_penalty = 0
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
absence_penalty = @homework_detail_manual . absence_penalty
appeal_penalty = @homework_detail_manual . appeal_penalty
if @homework_detail_manual . comment_status < 3
if params [ :homework_anonymous_comment ]
@homework . anonymous_comment = 0
@homework_detail_manual . evaluation_start = params [ :homework_evaluation_start ] if params [ :homework_evaluation_start ]
anonymous_comment = @homework . anonymous_comment
absence_penalty = @homework_detail_manual . absence_penalty
appeal_penalty = @homework_detail_manual . appeal_penalty
if @homework_detail_manual . comment_status < 3
if params [ :homework_anonymous_comment ]
@homework . anonymous_comment = 0
@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_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_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 . 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_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
if appeal_penalty != @homework_detail_manual . appeal_penalty && @homework_detail_manual . comment_status > = 4
@homework . student_works . each do | student_work |
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
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
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 |
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 " )
student_work . teaching_asistant_score = ts_score . first . score . nil? ? nil : ts_score . first . score . try ( :round , 2 ) . to_f
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
else
@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 " )
student_work . teaching_asistant_score = ts_score . first . nil? ? nil : ts_score . first . score
end
if appeal_penalty != @homework_detail_manual . appeal_penalty && @homework_detail_manual . comment_status > = 4
@homework . student_works . each do | student_work |
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
end
end
end
# 最终成绩组成
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 . 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
# 助教评分模式有变更 则更新学生分数
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 |
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 " )
student_work . teaching_asistant_score = ts_score . first . score . nil? ? nil : ts_score . first . score . try ( :round , 2 ) . to_f
student_work . save
end
else
@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 " )
student_work . teaching_asistant_score = ts_score . first . nil? ? nil : ts_score . first . score
student_work . save
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_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
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
if @homework . homework_type == 4
@homework . work_efficiency = params [ :work_efficiency ] ? 1 : 0
if params [ :eff_score ] != @homework . eff_score
@homework . eff_score = params [ :eff_score ]
score_change = true
end
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
score_change = true
end
if @homework_detail_manual . shixun_evaluation != params [ :shixun_evaluation ] . to_i
@homework_detail_manual . shixun_evaluation = params [ :shixun_evaluation ] . to_i
score_change = true
end
if params [ :challenge ]
score_change = true
params [ :challenge ] . each_with_index do | challenge_id , index |
setting = @homework . homework_challenge_settings . where ( :challenge_id = > challenge_id ) . first
if setting
setting . update_attributes ( :score = > params [ :score ] [ index ] )
else
HomeworkChallengeSetting . create ( :homework_common_id = > @homework . id , :challenge_id = > challenge_id , :shixun_id = > @homework . homework_commons_shixuns . shixun_id , :score = > params [ :score ] [ index ] )
if @homework . homework_type == 4
@homework . work_efficiency = params [ :work_efficiency ] ? 1 : 0
if params [ :eff_score ] != @homework . eff_score
@homework . eff_score = params [ :eff_score ]
score_change = true
end
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
score_change = true
end
if @homework_detail_manual . shixun_evaluation != params [ :shixun_evaluation ] . to_i
@homework_detail_manual . shixun_evaluation = params [ :shixun_evaluation ] . to_i
score_change = true
end
if params [ :challenge ]
score_change = true
params [ :challenge ] . each_with_index do | challenge_id , index |
setting = @homework . homework_challenge_settings . where ( :challenge_id = > challenge_id ) . first
if setting
setting . update_attributes ( :score = > params [ :score ] [ index ] )
else
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
@homework . homework_challenge_settings . where ( " challenge_id not in ( #{ params [ :challenge ] . join ( ',' ) } ) " ) . destroy_all
end
@homework . homework_challenge_settings . where ( " challenge_id not in ( #{ params [ :challenge ] . join ( ',' ) } ) " ) . destroy_all
end
@homework . score_open = params [ :homework_score_open ] ? 1 : 0
@homework . save!
if score_change
homework_challenge_settings = HomeworkChallengeSetting . where ( :homework_common_id = > @homework . id )
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
set_shixun_final_score student_work , @homework_detail_manual . answer_open_evaluation , homework_challenge_settings
@homework . score_open = params [ :homework_score_open ] ? 1 : 0
@homework . save!
if score_change
homework_challenge_settings = HomeworkChallengeSetting . where ( :homework_common_id = > @homework . id )
@homework . student_works . where ( " work_status != 0 " ) . each do | student_work |
set_shixun_final_score student_work , @homework_detail_manual . answer_open_evaluation , homework_challenge_settings
end
# 更新所有学生的效率分
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
end
# 更新所有学生的效率分
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
else
@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
else
@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
@homework_detail_manual . save
if create_homework_user . present?
if group_id . present? && group_id . size != 0
if group_id . size == @course . course_groups . count
create_works_tiding @homework , @course . student
@homework_detail_manual . save
if create_homework_user . present?
if group_id . present? && group_id . size != 0
if group_id . size == @course . course_groups . count
create_works_tiding @homework , @course . student
else
members = @course . members . where ( :course_group_id = > group_id )
create_works_tiding @homework , members
end
else
members = @course . members . where ( :course_group_id = > group_id )
create_works_tiding @homework , members
create_works_tiding @homework , @course . student
end
else
create_works_tiding @homework , @course . student
end
end
redirect_to student_work_index_path ( :homework = > @homework . id )
@ -929,60 +931,62 @@ class HomeworkCommonController < ApplicationController
end
def publish_homework
if @homework . homework_detail_manual . try ( :comment_status ) == 0
if params [ :group_ids ]
if @course . course_groups . where ( :id = > params [ :group_ids ] . split ( " , " ) ) . count == @course . course_groups . count
@homework . homework_group_settings . destroy_all
@homework . update_attribute ( " unified_setting " , true )
# 发消息
create_works_tiding @homework , @course . student
else
@homework . update_attribute ( " unified_setting " , false )
@course . course_groups . each do | group |
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
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 )
ActiveRecord :: Base . transaction do
if @homework . homework_detail_manual . try ( :comment_status ) == 0
if params [ :group_ids ]
if @course . course_groups . where ( :id = > params [ :group_ids ] . split ( " , " ) ) . count == @course . course_groups . count
@homework . homework_group_settings . destroy_all
@homework . update_attribute ( " unified_setting " , true )
# 发消息
create_works_tiding @homework , @course . student
else
@homework . update_attribute ( " unified_setting " , false )
@course . course_groups . each do | group |
homework_group_setting = @homework . homework_group_settings . where ( :course_group_id = > group . id ) . first
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
@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
@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
else
@homework . homework_group_settings . destroy_all
create_works_tiding @homework , @course . student
end
else
@homework . homework_group_settings . destroy_all
create_works_tiding @homework , @course . student
end
@homework . update_attribute ( " publish_time " , Time . now )
@homework . update_attribute ( " publish_time " , Time . now )
if @homework . end_time . nil?
@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
@homework . update_attribute ( " end_time " , HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . map ( & :end_time ) . max )
end
if @homework . end_time . nil?
@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
@homework . update_attribute ( " end_time " , HomeworkGroupSetting . where ( " homework_common_id = #{ @homework . id } and end_time is not null " ) . map ( & :end_time ) . max )
end
= begin
if @homework . archive_time . nil?
@homework . update_attribute ( " archive_time " , Time . at ( ( ( 2 . months . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) )
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
@homework . course_acts << CourseActivity . new ( :user_id = > @homework . user_id , :course_id = > @homework . course_id )
if @homework . course_acts . size == 0
@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
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 )
if @homework . end_time > Time . now && @homework . homework_detail_manual . try ( :comment_status ) > 1
@homework . homework_detail_manual . update_attribute ( " comment_status " , 1 )
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
redirect_to student_work_index_path ( :homework = > @homework . id )
end
@ -1032,7 +1036,8 @@ class HomeworkCommonController < ApplicationController
def end_homework
time = Time . now
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 ]
# @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 )
@ -1069,7 +1074,9 @@ class HomeworkCommonController < ApplicationController
# 更新所有学生的效率分
update_student_eff_score HomeworkCommon . where ( :id = > @homework . id ) . first
end
# end
# end
end
redirect_to student_work_index_path ( :homework = > @homework . id )
end