|
|
|
@ -2,10 +2,10 @@ class PollsController < ApplicationController
|
|
|
|
|
# before_action :check_poll_status 问卷的发消息和定时任务没有做
|
|
|
|
|
before_action :require_login, :check_auth,except: [:index]
|
|
|
|
|
before_action :find_course, except: [:show,:poll_setting,:commit_setting,:edit,:update,:start_answer,:commit_poll,
|
|
|
|
|
:commit_result,:poll_lists,:cancel_publish,:cancel_publish_modal,:common_header]
|
|
|
|
|
:commit_result,:poll_lists,:cancel_publish,:cancel_publish_modal,:common_header,:publish_groups]
|
|
|
|
|
before_action :get_poll_and_course, only: [:show,:poll_setting,:commit_setting,:edit,:update,:start_answer,
|
|
|
|
|
:commit_poll,:commit_result,:poll_lists,:cancel_publish,
|
|
|
|
|
:cancel_publish_modal,:common_header]
|
|
|
|
|
:cancel_publish_modal,:common_header, :publish_groups]
|
|
|
|
|
before_action :user_course_identity
|
|
|
|
|
before_action :is_course_teacher, except: [:index,:start_answer,:poll_setting,:commit_poll,:commit_result,:poll_lists,:common_header] #判断是否为课堂老师
|
|
|
|
|
before_action :check_user_status
|
|
|
|
@ -242,12 +242,35 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 详情页的立即发布弹框
|
|
|
|
|
def publish_groups
|
|
|
|
|
@current_user = current_user
|
|
|
|
|
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
|
|
|
|
|
group_ids = @course.charge_group_ids(@current_user) - @poll.poll_group_settings.poll_group_published.pluck(:course_group_id)
|
|
|
|
|
@course_groups = @course.course_groups.where(id: group_ids)
|
|
|
|
|
@group_settings = @poll.poll_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 = Poll.where(id: params[:check_ids])
|
|
|
|
@ -259,26 +282,28 @@ class PollsController < ApplicationController
|
|
|
|
|
pl_status = poll.poll_group_settings.find_in_poll_group("course_group_id",params[:group_ids]).poll_group_not_published.present? ? 1 : 0 #立即发布针对分组设置的全部未发布的班级才生效
|
|
|
|
|
end
|
|
|
|
|
if pl_status == 1 #如果问卷存在已发布的,或者是已截止的,那么则直接跳过
|
|
|
|
|
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改
|
|
|
|
|
g_course = group_ids #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改
|
|
|
|
|
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?) # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置
|
|
|
|
|
poll.poll_group_settings.destroy_all
|
|
|
|
|
poll_unified = true
|
|
|
|
|
e_time = ex_end_time
|
|
|
|
|
e_time = params[:detail] ? group_end_times.max : ex_end_time
|
|
|
|
|
else
|
|
|
|
|
poll_unified = false
|
|
|
|
|
g_course.each do |i|
|
|
|
|
|
g_course.each_with_index do |i, index|
|
|
|
|
|
poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id,寻找问卷所在的班级
|
|
|
|
|
group_end_time = params[:detail] ? group_end_times[index] : ex_end_time
|
|
|
|
|
if poll_group_setting #如果该问卷分组存在,则更新,否则新建
|
|
|
|
|
poll_group_setting.update_attributes(publish_time:Time.now,end_time:ex_end_time)
|
|
|
|
|
poll_group_setting.update_attributes(publish_time: Time.now, end_time: group_end_time)
|
|
|
|
|
else
|
|
|
|
|
p_course_group = {
|
|
|
|
|
:poll_id => poll.id,
|
|
|
|
|
:course_group_id => i,
|
|
|
|
|
:course_id => poll.course.id,
|
|
|
|
|
:publish_time => Time.now,
|
|
|
|
|
:end_time => ex_end_time,
|
|
|
|
|
:end_time => group_end_time,
|
|
|
|
|
}
|
|
|
|
|
new_poll_group = poll.poll_group_settings.new p_course_group
|
|
|
|
|
new_poll_group.save
|
|
|
|
|