|
|
|
@ -683,12 +683,34 @@ class ExercisesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 详情页的立即发布弹框
|
|
|
|
|
def publish_groups
|
|
|
|
|
@current_user = current_user
|
|
|
|
|
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
|
|
|
|
|
group_ids = @course.charge_group_ids(@current_user) - @exercise.exercise_group_settings.exercise_group_published.pluck(:course_group_id)
|
|
|
|
|
@course_groups = @course.course_groups.where(id: group_ids)
|
|
|
|
|
@group_settings = @exercise.exercise_group_settings.where(id: group_ids)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。
|
|
|
|
|
def publish
|
|
|
|
|
tip_exception("缺少截止时间参数") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
@course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
if params[:detail].blank?
|
|
|
|
|
tip_exception("缺少截止时间参数") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
@course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
else
|
|
|
|
|
group_end_times = params[:group_end_times].reject(&:blank?).map{|time| time.to_time}
|
|
|
|
|
group_ids = params[:group_ids].reject(&:blank?)
|
|
|
|
|
tip_exception("缺少截止时间参数") if group_end_times.blank?
|
|
|
|
|
tip_exception("截止时间和分班参数的个数不一致") if group_end_times.length != group_ids.length
|
|
|
|
|
group_end_times.each do |time|
|
|
|
|
|
tip_exception("分班截止时间不能早于当前时间") if time <= Time.now
|
|
|
|
|
tip_exception("分班截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
@course.end_date.present? && time > @course.end_date.end_of_day
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
check_ids = Exercise.where(id: params[:check_ids])
|
|
|
|
@ -702,28 +724,30 @@ class ExercisesController < ApplicationController
|
|
|
|
|
.exercise_group_not_published.present? ? 1 : 0
|
|
|
|
|
end
|
|
|
|
|
if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过
|
|
|
|
|
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改
|
|
|
|
|
g_course = group_ids #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改
|
|
|
|
|
tiding_group_ids = g_course
|
|
|
|
|
if g_course
|
|
|
|
|
user_course_groups = @course.charge_group_ids(current_user)
|
|
|
|
|
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置
|
|
|
|
|
user_course_groups = @course.course_groups.pluck(:id)
|
|
|
|
|
if g_course.map(&:to_i).sort == user_course_groups.sort &&
|
|
|
|
|
((params[:detail] && group_end_times.min == group_end_times.max) || params[:detail].blank?) # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置
|
|
|
|
|
exercise.exercise_group_settings.destroy_all
|
|
|
|
|
ex_unified = true
|
|
|
|
|
e_time = ex_end_time
|
|
|
|
|
e_time = params[:detail] ? group_end_times.max : ex_end_time
|
|
|
|
|
tiding_group_ids = []
|
|
|
|
|
else
|
|
|
|
|
ex_unified = false
|
|
|
|
|
g_course.each do |i|
|
|
|
|
|
g_course.each_with_index do |i, index|
|
|
|
|
|
exercise_group_setting = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",i).first #根据课堂分班的id,寻找试卷所在的班级
|
|
|
|
|
group_end_time = params[:detail] ? group_end_times[index] : ex_end_time
|
|
|
|
|
if exercise_group_setting #如果该试卷分组存在,则更新,否则新建
|
|
|
|
|
exercise_group_setting.update_attributes(publish_time:Time.now,end_time:ex_end_time)
|
|
|
|
|
exercise_group_setting.update_attributes(publish_time: Time.now, end_time: group_end_time)
|
|
|
|
|
else
|
|
|
|
|
p_course_group = {
|
|
|
|
|
:exercise_id => exercise.id,
|
|
|
|
|
:course_group_id => i,
|
|
|
|
|
:course_id => exercise.course.id,
|
|
|
|
|
:publish_time => Time.now,
|
|
|
|
|
:end_time => ex_end_time,
|
|
|
|
|
:end_time => group_end_time,
|
|
|
|
|
}
|
|
|
|
|
new_exercise_group = exercise.exercise_group_settings.new p_course_group
|
|
|
|
|
new_exercise_group.save
|
|
|
|
|