|
|
|
@ -1,25 +1,25 @@
|
|
|
|
|
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,: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, :publish_groups]
|
|
|
|
|
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, :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, :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 :is_course_teacher, except: [:index, :start_answer, :poll_setting, :commit_poll, :commit_result, :poll_lists, :common_header] #判断是否为课堂老师
|
|
|
|
|
before_action :check_user_status
|
|
|
|
|
before_action :is_course_public, only: [:set_public]
|
|
|
|
|
before_action :check_user_on_answer, only: [:show,:start_answer,:commit_poll,:poll_lists] #判断当前用户在问卷的权限/老师是否属于分班的权限
|
|
|
|
|
before_action :validate_params, only: [:create,:update]
|
|
|
|
|
before_action :validates_multi_ids, only: [:publish,:end_poll,:destroys,:set_public,:join_poll_banks]
|
|
|
|
|
before_action :check_poll_setting_status,only: [:commit_setting]
|
|
|
|
|
before_action :get_questions_count ,only: [:start_answer,:show,:commit_result,:edit]
|
|
|
|
|
before_action :check_user_id_start_answer,only: [:start_answer]
|
|
|
|
|
before_action :check_poll_question_complete,only: [:commit_poll] #问卷提交前来判断问题是否完成
|
|
|
|
|
before_action :check_poll_commit_result,only: [:commit_result]
|
|
|
|
|
before_action :check_user_on_answer, only: [:show, :start_answer, :commit_poll, :poll_lists] #判断当前用户在问卷的权限/老师是否属于分班的权限
|
|
|
|
|
before_action :validate_params, only: [:create, :update]
|
|
|
|
|
before_action :validates_multi_ids, only: [:publish, :end_poll, :destroys, :set_public, :join_poll_banks]
|
|
|
|
|
before_action :check_poll_setting_status, only: [:commit_setting]
|
|
|
|
|
before_action :get_questions_count, only: [:start_answer, :show, :commit_result, :edit]
|
|
|
|
|
before_action :check_user_id_start_answer, only: [:start_answer]
|
|
|
|
|
before_action :check_poll_question_complete, only: [:commit_poll] #问卷提交前来判断问题是否完成
|
|
|
|
|
before_action :check_poll_commit_result, only: [:commit_result]
|
|
|
|
|
# before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户
|
|
|
|
|
before_action :get_left_banner_id, only:[:common_header,:start_answer,:new,:edit,:index]
|
|
|
|
|
before_action :get_left_banner_id, only: [:common_header, :start_answer, :new, :edit, :index]
|
|
|
|
|
include PollsHelper
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
@ -66,7 +66,7 @@ class PollsController < ApplicationController
|
|
|
|
|
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_not_published.pluck(:poll_id)
|
|
|
|
|
when 2
|
|
|
|
|
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}")
|
|
|
|
|
.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:poll_id)
|
|
|
|
|
.where("publish_time is not null and publish_time <= ? and end_time > ?", Time.now, Time.now).pluck(:poll_id)
|
|
|
|
|
when 3
|
|
|
|
|
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_ended.pluck(:poll_id)
|
|
|
|
|
end
|
|
|
|
@ -83,7 +83,7 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 分页
|
|
|
|
|
@polls_select_count = @polls.size
|
|
|
|
|
@polls = @polls.order( "IF(ISNULL(publish_time),0,1), publish_time DESC,created_at DESC")
|
|
|
|
|
@polls = @polls.order("IF(ISNULL(publish_time),0,1), publish_time DESC,created_at DESC")
|
|
|
|
|
@page = params[:page] || 1
|
|
|
|
|
@limit = params[:limit] || 15
|
|
|
|
|
|
|
|
|
@ -126,7 +126,6 @@ class PollsController < ApplicationController
|
|
|
|
|
# un_anonymous 是否实名,默认为false,即不公开
|
|
|
|
|
def create
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
poll_name = params[:polls_name]
|
|
|
|
|
poll_desc = params[:polls_description]
|
|
|
|
|
poll_options = {
|
|
|
|
@ -138,11 +137,6 @@ class PollsController < ApplicationController
|
|
|
|
|
:polls_type => "Course",
|
|
|
|
|
}
|
|
|
|
|
@poll = Poll.create!(poll_options)
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("问卷创建失败!")
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -160,7 +154,6 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
poll_name = params[:polls_name]
|
|
|
|
|
poll_des = params[:polls_description]
|
|
|
|
|
poll_params = {
|
|
|
|
@ -168,12 +161,7 @@ class PollsController < ApplicationController
|
|
|
|
|
:polls_description => poll_des
|
|
|
|
|
}
|
|
|
|
|
@poll.update!(poll_params)
|
|
|
|
|
normal_status(0,"问卷更新成功!")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("没有权限")
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
normal_status(0, "问卷更新成功!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -207,8 +195,8 @@ class PollsController < ApplicationController
|
|
|
|
|
@user_poll_answer = 3 #教师页面
|
|
|
|
|
end
|
|
|
|
|
poll_id_array = [@poll.id]
|
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的
|
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的
|
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_id_array, 2).count #是否存在已发布的
|
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_id_array, 1).count #是否存在未发布的
|
|
|
|
|
|
|
|
|
|
if (@poll_publish_count == 0) && (@poll_unpublish_count == 0) #即表示没有分班
|
|
|
|
|
if @poll_status == 1
|
|
|
|
@ -231,7 +219,7 @@ class PollsController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
poll_ids = params[:check_ids]
|
|
|
|
|
if poll_ids.count > 0
|
|
|
|
|
@course_groups = get_user_permission_course(poll_ids,1)
|
|
|
|
|
@course_groups = get_user_permission_course(poll_ids, 1)
|
|
|
|
|
else
|
|
|
|
|
@course_groups = []
|
|
|
|
|
end
|
|
|
|
@ -258,23 +246,21 @@ class PollsController < ApplicationController
|
|
|
|
|
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)
|
|
|
|
|
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_end_times = params[:group_end_times].reject(&:blank?).map {|time| time.to_time}
|
|
|
|
|
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
|
|
|
|
|
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])
|
|
|
|
|
ex_end_time = params[:end_time].blank? ? Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) : params[:end_time].to_time
|
|
|
|
|
ex_end_time = params[:end_time].blank? ? Time.at(((1.month.since.to_i) / 3600.0).ceil * 3600) : params[:end_time].to_time
|
|
|
|
|
check_ids.each do |poll|
|
|
|
|
|
if poll.unified_setting
|
|
|
|
|
pl_status = poll.polls_status #则为试卷的状态
|
|
|
|
@ -294,7 +280,7 @@ class PollsController < ApplicationController
|
|
|
|
|
else
|
|
|
|
|
poll_unified = false
|
|
|
|
|
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,寻找问卷所在的班级
|
|
|
|
|
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.present? #如果该问卷分组存在,则更新,否则新建
|
|
|
|
|
poll_group_setting.update!(publish_time: Time.now, end_time: group_end_time)
|
|
|
|
@ -318,7 +304,7 @@ class PollsController < ApplicationController
|
|
|
|
|
poll_unified = true
|
|
|
|
|
e_time = ex_end_time
|
|
|
|
|
end
|
|
|
|
|
poll_status = set_poll_status(Time.now,e_time)
|
|
|
|
|
poll_status = set_poll_status(Time.now, e_time)
|
|
|
|
|
|
|
|
|
|
poll_params = {
|
|
|
|
|
:publish_time => Time.now,
|
|
|
|
@ -328,7 +314,7 @@ class PollsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
poll.update!(poll_params)
|
|
|
|
|
if poll.course_acts.size == 0
|
|
|
|
|
poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id)
|
|
|
|
|
poll.course_acts << CourseActivity.new(:user_id => poll.user_id, :course_id => poll.course_id)
|
|
|
|
|
end
|
|
|
|
|
PollPublishNotifyJob.perform_later(poll.id, g_course)
|
|
|
|
|
end
|
|
|
|
@ -350,7 +336,7 @@ class PollsController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
poll_ids = params[:check_ids]
|
|
|
|
|
if poll_ids.count > 0
|
|
|
|
|
@course_groups = get_user_permission_course(poll_ids,3)
|
|
|
|
|
@course_groups = get_user_permission_course(poll_ids, 3)
|
|
|
|
|
else
|
|
|
|
|
@course_groups = []
|
|
|
|
|
end
|
|
|
|
@ -385,12 +371,12 @@ class PollsController < ApplicationController
|
|
|
|
|
poll_users = poll_unified ? poll.poll_users :
|
|
|
|
|
poll.poll_users.joins("join course_members on poll_users.user_id = course_members.user_id").where(course_members: {course_group_id: g_course, role: 4})
|
|
|
|
|
poll_group_setting = poll.poll_group_settings
|
|
|
|
|
old_poll_groups = poll_group_setting.find_in_poll_group("course_group_id",g_course) #问卷分组的截止时间更改
|
|
|
|
|
old_poll_groups = poll_group_setting.find_in_poll_group("course_group_id", g_course) #问卷分组的截止时间更改
|
|
|
|
|
old_poll_groups.update_all(:end_time => Time.now)
|
|
|
|
|
new_end_time = poll_group_setting.end_time_present.map(&:end_time) # 问卷结束时间不为空的
|
|
|
|
|
new_end_time_s = new_end_time.size > 0 ? new_end_time.max : Time.now
|
|
|
|
|
new_poll_status = set_poll_status(poll.publish_time,new_end_time_s)
|
|
|
|
|
poll.update!(:end_time => new_end_time_s,:polls_status => new_poll_status,:unified_setting => poll_unified)
|
|
|
|
|
new_poll_status = set_poll_status(poll.publish_time, new_end_time_s)
|
|
|
|
|
poll.update!(:end_time => new_end_time_s, :polls_status => new_poll_status, :unified_setting => poll_unified)
|
|
|
|
|
elsif poll.unified_setting
|
|
|
|
|
poll_users = poll.poll_users
|
|
|
|
|
poll.update!(:polls_status => 3, :end_time => Time.now)
|
|
|
|
@ -414,7 +400,7 @@ class PollsController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
poll_ids = [@poll.id]
|
|
|
|
|
if poll_ids.count > 0
|
|
|
|
|
@course_groups = get_user_permission_course(poll_ids,2)
|
|
|
|
|
@course_groups = get_user_permission_course(poll_ids, 2)
|
|
|
|
|
else
|
|
|
|
|
@course_groups = []
|
|
|
|
|
end
|
|
|
|
@ -433,12 +419,12 @@ class PollsController < ApplicationController
|
|
|
|
|
g_course = params[:group_ids]
|
|
|
|
|
if !@poll.unified_setting #如果问卷为分班设置,且传入的班级id存在
|
|
|
|
|
if g_course.present?
|
|
|
|
|
course_group_ids = @course.course_members.course_find_by_ids("course_group_id",g_course).pluck(:user_id).uniq #传入班级的全部学生人数
|
|
|
|
|
all_poll_settings = @poll.poll_group_settings.find_in_poll_group("course_group_id",g_course) #根据传入的班级id来获取问卷的分组设置
|
|
|
|
|
course_group_ids = @course.course_members.course_find_by_ids("course_group_id", g_course).pluck(:user_id).uniq #传入班级的全部学生人数
|
|
|
|
|
all_poll_settings = @poll.poll_group_settings.find_in_poll_group("course_group_id", g_course) #根据传入的班级id来获取问卷的分组设置
|
|
|
|
|
all_poll_settings.destroy_all #问卷的设置文件全部删除
|
|
|
|
|
# @poll.poll_users.find_by_group_ids(course_group_ids).destroy_all #问卷的提交信息
|
|
|
|
|
poll_question_ids = @poll.poll_questions.pluck(:id) #问卷的全部问卷
|
|
|
|
|
PollVote.find_current_vote("user_id",course_group_ids).find_current_vote("poll_question_id",poll_question_ids).destroy_all
|
|
|
|
|
PollVote.find_current_vote("user_id", course_group_ids).find_current_vote("poll_question_id", poll_question_ids).destroy_all
|
|
|
|
|
poll_user_options = {
|
|
|
|
|
:commit_status => 0,
|
|
|
|
|
:start_at => nil,
|
|
|
|
@ -456,7 +442,7 @@ class PollsController < ApplicationController
|
|
|
|
|
if p_time.nil? #发布时间为空,则表示问卷未发布
|
|
|
|
|
poll_status = 1
|
|
|
|
|
elsif p_time.present? && e_time.present?
|
|
|
|
|
poll_status = set_poll_status(p_time,e_time)
|
|
|
|
|
poll_status = set_poll_status(p_time, e_time)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
unified_setting = true
|
|
|
|
@ -471,9 +457,9 @@ class PollsController < ApplicationController
|
|
|
|
|
:end_time => e_time
|
|
|
|
|
}
|
|
|
|
|
@poll.update!(poll_options)
|
|
|
|
|
normal_status(0,"分班问卷撤销发布成功!")
|
|
|
|
|
normal_status(0, "分班问卷撤销发布成功!")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1,"请选择撤销发布班级!")
|
|
|
|
|
normal_status(-1, "请选择撤销发布班级!")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
poll_user_options = {
|
|
|
|
@ -483,7 +469,7 @@ class PollsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
@poll.poll_users.update_all(poll_user_options)
|
|
|
|
|
poll_question_ids = @poll.poll_questions.pluck(:id)
|
|
|
|
|
PollVote.find_current_vote("poll_question_id",poll_question_ids).destroy_all
|
|
|
|
|
PollVote.find_current_vote("poll_question_id", poll_question_ids).destroy_all
|
|
|
|
|
poll_new_params = {
|
|
|
|
|
:polls_status => 1,
|
|
|
|
|
:publish_time => nil,
|
|
|
|
@ -492,7 +478,7 @@ class PollsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
@poll.update!(poll_new_params)
|
|
|
|
|
@poll.poll_group_settings.destroy_all
|
|
|
|
|
normal_status(0,"问卷撤销发布成功!")
|
|
|
|
|
normal_status(0, "问卷撤销发布成功!")
|
|
|
|
|
|
|
|
|
|
## @poll.tidings.destroy_all 用户的发送消息全部删除,因接口未定,所以先注释
|
|
|
|
|
|
|
|
|
@ -510,7 +496,7 @@ class PollsController < ApplicationController
|
|
|
|
|
def destroys
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
check_ids = Poll.where(id:params[:check_ids])
|
|
|
|
|
check_ids = Poll.where(id: params[:check_ids])
|
|
|
|
|
check_ids.each do |poll|
|
|
|
|
|
if poll.present?
|
|
|
|
|
poll.destroy
|
|
|
|
@ -529,7 +515,7 @@ class PollsController < ApplicationController
|
|
|
|
|
def set_public
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
check_ids = Poll.where(id:params[:check_ids])
|
|
|
|
|
check_ids = Poll.where(id: params[:check_ids])
|
|
|
|
|
check_ids.each do |poll|
|
|
|
|
|
poll.update!(is_public: true)
|
|
|
|
|
end
|
|
|
|
@ -548,7 +534,7 @@ class PollsController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
check_ids = Poll.where(id: params[:check_ids])
|
|
|
|
|
check_ids.each do |poll|
|
|
|
|
|
current_ex_bank = current_user.exercise_banks.find_by_container(poll.id,"Poll").first
|
|
|
|
|
current_ex_bank = current_user.exercise_banks.find_by_container(poll.id, "Poll").first
|
|
|
|
|
if current_ex_bank.present? #当前用户的选择问卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库
|
|
|
|
|
ex_params = {
|
|
|
|
|
:name => poll.polls_name,
|
|
|
|
@ -556,7 +542,7 @@ class PollsController < ApplicationController
|
|
|
|
|
:course_list_id => poll.course.try(:course_list_id)
|
|
|
|
|
}
|
|
|
|
|
current_ex_bank.update!(ex_params)
|
|
|
|
|
question_bank = QuestionBank.ques_by_container(current_ex_bank.id,current_ex_bank.container_type) #该习题库是否存在于问题库里
|
|
|
|
|
question_bank = QuestionBank.ques_by_container(current_ex_bank.id, current_ex_bank.container_type) #该习题库是否存在于问题库里
|
|
|
|
|
ques_params = {
|
|
|
|
|
:name => current_ex_bank.name,
|
|
|
|
|
:course_list_id => current_ex_bank.course_list_id
|
|
|
|
@ -574,7 +560,7 @@ class PollsController < ApplicationController
|
|
|
|
|
:container_type => "Poll",
|
|
|
|
|
:quotes => 1
|
|
|
|
|
}
|
|
|
|
|
current_ex_bank= ExerciseBank.new ex_params
|
|
|
|
|
current_ex_bank = ExerciseBank.new ex_params
|
|
|
|
|
if current_ex_bank.save! #如果习题库保存成功,则会创建问题库question_bank
|
|
|
|
|
ques_params = {
|
|
|
|
|
:name => current_ex_bank.name,
|
|
|
|
@ -692,9 +678,9 @@ class PollsController < ApplicationController
|
|
|
|
|
@user_permission = 2
|
|
|
|
|
@user_course_groups = @course.teacher_group(current_user.id) #当前老师的分班
|
|
|
|
|
@being_setting_course_ids = @poll.poll_published_ids(current_user.id) #当前用户已发布的班级的id
|
|
|
|
|
@user_published_setting = @poll.poll_group_settings.find_in_poll_group("course_group_id",@being_setting_course_ids)
|
|
|
|
|
@user_published_setting = @poll.poll_group_settings.find_in_poll_group("course_group_id", @being_setting_course_ids)
|
|
|
|
|
poll_ids = [@poll.id]
|
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_ids,2).count
|
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_ids, 2).count
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
@ -725,19 +711,18 @@ class PollsController < ApplicationController
|
|
|
|
|
tip_exception("发布时间不能为空") if params[:publish_time].blank?
|
|
|
|
|
tip_exception("截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间必须晚于发布时间") if params[:publish_time].to_time >= params[:end_time].to_time
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
@course.end_date.present? && params[:end_time].to_time > @course.end_date.end_of_day
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:end_time].to_time > @course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
params_publish_time = params[:publish_time].to_time
|
|
|
|
|
params_end_time = params[:end_time].to_time
|
|
|
|
|
|
|
|
|
|
if poll_status != 1 && @poll.publish_time != params_publish_time
|
|
|
|
|
normal_status(-1,"不允许修改发布时间")
|
|
|
|
|
normal_status(-1, "不允许修改发布时间")
|
|
|
|
|
elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time
|
|
|
|
|
normal_status(-1,"截止时间不能小于发布时间")
|
|
|
|
|
normal_status(-1, "截止时间不能小于发布时间")
|
|
|
|
|
else
|
|
|
|
|
#发布时间小于当前时间,则poll显示为未发布,当截止时间大于当前时间,则显示为已截止
|
|
|
|
|
poll_status_n = set_poll_status(params_publish_time,params_end_time)
|
|
|
|
|
poll_status_n = set_poll_status(params_publish_time, params_end_time)
|
|
|
|
|
poll_params = {
|
|
|
|
|
:unified_setting => unified_setting,
|
|
|
|
|
:show_result => show_result,
|
|
|
|
@ -752,23 +737,22 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
params_times = params[:publish_time_groups] #分班返回的json数组{"publish_time_groups":[{"course_group_id":["1","2"],"publish_time":"xx","end_time":"xxx"}]}
|
|
|
|
|
poll_groups = @poll.poll_group_settings.find_in_poll_group("course_id",@course.id) #当前课堂问卷的班级全部分班信息
|
|
|
|
|
poll_groups = @poll.poll_group_settings.find_in_poll_group("course_id", @course.id) #当前课堂问卷的班级全部分班信息
|
|
|
|
|
poll_groups_ids = poll_groups.pluck(:course_group_id) #问卷的全部分班id
|
|
|
|
|
total_common = params_times.map{|k| k[:course_group_id]}.sum #传入的所有分组的分班id
|
|
|
|
|
total_common = params_times.map {|k| k[:course_group_id]}.sum #传入的所有分组的分班id
|
|
|
|
|
total_common_group = poll_groups_ids & total_common #传入的分班与问卷已存在的分班的交集
|
|
|
|
|
old_poll_groups = poll_groups_ids - total_common_group #后来传入的分班里,没有了的班级,即需要删除
|
|
|
|
|
params_times.each do |t|
|
|
|
|
|
tip_exception("发布时间不能为空") if t[:publish_time].blank?
|
|
|
|
|
tip_exception("截止时间不能为空") if t[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if t[:publish_time].to_time > t[:end_time].to_time
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
|
|
|
|
|
@course.end_date.present? && t[:end_time].to_time > @course.end_date.end_of_day
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && t[:end_time].to_time > @course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
course_id = t[:course_group_id]
|
|
|
|
|
poll_publish_time = t[:publish_time].to_time
|
|
|
|
|
poll_end_time = t[:end_time].to_time
|
|
|
|
|
|
|
|
|
|
poll_group = poll_groups.find_in_poll_group("course_group_id",course_id) #判断该分班是否存在
|
|
|
|
|
poll_group = poll_groups.find_in_poll_group("course_group_id", course_id) #判断该分班是否存在
|
|
|
|
|
|
|
|
|
|
if poll_group.present? && (poll_group.first.publish_time < Time.now) && (poll_publish_time != poll_group.first.publish_time)
|
|
|
|
|
error_count += 1
|
|
|
|
@ -781,14 +765,14 @@ class PollsController < ApplicationController
|
|
|
|
|
common_group = poll_groups_ids & course_id #传入的班级与问卷已存在的班级的交集,即表示已有分班的
|
|
|
|
|
new_group_ids = course_id - common_group #新传入的班级id
|
|
|
|
|
if common_group.size > 0 #传入的参数存在已发布的分班
|
|
|
|
|
poll_group = poll_groups.find_in_poll_group("course_group_id",common_group)
|
|
|
|
|
poll_group = poll_groups.find_in_poll_group("course_group_id", common_group)
|
|
|
|
|
poll_group.each do |the_group_setting|
|
|
|
|
|
poll_group_params = {
|
|
|
|
|
:publish_time => poll_publish_time,
|
|
|
|
|
:end_time => poll_end_time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
the_group_setting_status = set_poll_status(the_group_setting.publish_time,the_group_setting.end_time)
|
|
|
|
|
the_group_setting_status = set_poll_status(the_group_setting.publish_time, the_group_setting.end_time)
|
|
|
|
|
if the_group_setting_status == 2
|
|
|
|
|
poll_group_params = {
|
|
|
|
|
:publish_time => the_group_setting.publish_time,
|
|
|
|
@ -821,11 +805,11 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
if error_count > 0
|
|
|
|
|
error_count == 0
|
|
|
|
|
normal_status(-1,"已发布/已截止的问卷不允许修改时间")
|
|
|
|
|
normal_status(-1, "已发布/已截止的问卷不允许修改时间")
|
|
|
|
|
else
|
|
|
|
|
# 未发布的分班设置才能删除
|
|
|
|
|
if old_poll_groups.size > 0
|
|
|
|
|
old_all_poll_groups = poll_groups.find_in_poll_group("course_group_id",old_poll_groups).poll_group_not_published
|
|
|
|
|
old_all_poll_groups = poll_groups.find_in_poll_group("course_group_id", old_poll_groups).poll_group_not_published
|
|
|
|
|
old_all_poll_groups.destroy_all
|
|
|
|
|
end
|
|
|
|
|
#问卷更新为poll_group_setting的发布时间最小,截止时间最大
|
|
|
|
@ -837,7 +821,7 @@ class PollsController < ApplicationController
|
|
|
|
|
if p_time.nil? #发布时间为空,则表示问卷未发布
|
|
|
|
|
poll_status = 1
|
|
|
|
|
elsif p_time.present? && e_time.present?
|
|
|
|
|
poll_status = set_poll_status(p_time,e_time)
|
|
|
|
|
poll_status = set_poll_status(p_time, e_time)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
poll_params = {
|
|
|
|
@ -851,7 +835,7 @@ class PollsController < ApplicationController
|
|
|
|
|
@poll.update!(poll_params)
|
|
|
|
|
if @poll.polls_status == 2
|
|
|
|
|
if @poll.course_acts.size == 0
|
|
|
|
|
@poll.course_acts << CourseActivity.new(:user_id => @poll.user_id,:course_id => @poll.course_id)
|
|
|
|
|
@poll.course_acts << CourseActivity.new(:user_id => @poll.user_id, :course_id => @poll.course_id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
normal_status(0, "问卷设置成功!")
|
|
|
|
@ -870,7 +854,7 @@ class PollsController < ApplicationController
|
|
|
|
|
def start_answer
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
poll_user_current = PollUser.where(user_id:@poll_current_user_id,poll_id:@poll.id)&.first #查找当前用户是否有过答题
|
|
|
|
|
poll_user_current = PollUser.where(user_id: @poll_current_user_id, poll_id: @poll.id)&.first #查找当前用户是否有过答题
|
|
|
|
|
@poll_status = @poll.get_poll_status(current_user)
|
|
|
|
|
if poll_user_current.blank?
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的
|
|
|
|
@ -897,7 +881,7 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 判断是否已经回答还是新建的回答
|
|
|
|
|
@poll_questions.each do |q|
|
|
|
|
|
ques_vote = q.poll_votes.find_current_vote("user_id",@poll_current_user_id)
|
|
|
|
|
ques_vote = q.poll_votes.find_current_vote("user_id", @poll_current_user_id)
|
|
|
|
|
ques_type = q.question_type
|
|
|
|
|
|
|
|
|
|
if ques_type != 3 #非简答题时
|
|
|
|
@ -941,13 +925,13 @@ class PollsController < ApplicationController
|
|
|
|
|
def commit_poll
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
@poll_multi_questions = @poll.poll_questions.where(question_type:2).select(:id,:max_choices,:min_choices,:question_number)
|
|
|
|
|
@poll_multi_questions = @poll.poll_questions.where(question_type: 2).select(:id, :max_choices, :min_choices, :question_number)
|
|
|
|
|
error_question = []
|
|
|
|
|
@poll_multi_questions.each do |q|
|
|
|
|
|
poll_user_votes = current_user.poll_votes.where(poll_question_id:q.id)&.size
|
|
|
|
|
poll_user_votes = current_user.poll_votes.where(poll_question_id: q.id)&.size
|
|
|
|
|
if q.max_choices.present? && (q.max_choices > 0) && (poll_user_votes > q.max_choices)
|
|
|
|
|
error_messages = "第#{q.question_number}题:超过最大选项限制"
|
|
|
|
|
elsif q.min_choices.present? && (q.min_choices > 0)&& (poll_user_votes < q.min_choices)
|
|
|
|
|
elsif q.min_choices.present? && (q.min_choices > 0) && (poll_user_votes < q.min_choices)
|
|
|
|
|
error_messages = "第#{q.question_number}题:不得少于最小选项限制"
|
|
|
|
|
else
|
|
|
|
|
error_messages = nil
|
|
|
|
@ -980,7 +964,7 @@ class PollsController < ApplicationController
|
|
|
|
|
def commit_result
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
@poll_users = @poll.all_poll_users(current_user.id).where(commit_status:1) # 问卷已提交的用户
|
|
|
|
|
@poll_users = @poll.all_poll_users(current_user.id).where(commit_status: 1) # 问卷已提交的用户
|
|
|
|
|
@poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id
|
|
|
|
|
@page = params[:page] || 1
|
|
|
|
|
@limit = params[:limit] || 10
|
|
|
|
@ -988,18 +972,18 @@ class PollsController < ApplicationController
|
|
|
|
|
@poll_questions = @poll_questions.page(@page).per(@limit)
|
|
|
|
|
if params[:format] == "xlsx"
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR
|
|
|
|
|
tip_exception(403,"无权限操作")
|
|
|
|
|
tip_exception(403, "无权限操作")
|
|
|
|
|
elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0)
|
|
|
|
|
normal_status(-1,"暂无用户提交")
|
|
|
|
|
normal_status(-1, "暂无用户提交")
|
|
|
|
|
elsif params[:export].present? && params[:export]
|
|
|
|
|
normal_status(0,"正在下载中")
|
|
|
|
|
normal_status(0, "正在下载中")
|
|
|
|
|
else
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.xlsx{
|
|
|
|
|
format.xlsx {
|
|
|
|
|
set_export_cookies
|
|
|
|
|
polls_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
|
|
|
|
|
polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids)
|
|
|
|
|
render xlsx: "#{polls_export_name_.strip}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit}
|
|
|
|
|
polls_user_commit = poll_commit_result(@poll, @poll_export_questions, @poll_users, @poll_commit_ids)
|
|
|
|
|
render xlsx: "#{polls_export_name_.strip}", template: "polls/commit_result.xlsx.axlsx", locals: {polls_user_commit: polls_user_commit}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -1018,8 +1002,8 @@ class PollsController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
poll_ids = [@poll.id]
|
|
|
|
|
@poll_list_status = @poll.get_poll_status(current_user)
|
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_ids,2).count
|
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_ids,1).count
|
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_ids, 2).count
|
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_ids, 1).count
|
|
|
|
|
@course_all_members = @course.students
|
|
|
|
|
@poll_group_counts = @course.course_groups_count
|
|
|
|
|
|
|
|
|
@ -1028,7 +1012,7 @@ class PollsController < ApplicationController
|
|
|
|
|
@poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生
|
|
|
|
|
get_poll_answers(@poll_users_list, @poll_list_status)
|
|
|
|
|
if @poll_list_status == 1
|
|
|
|
|
@poll_course_groups =[]
|
|
|
|
|
@poll_course_groups = []
|
|
|
|
|
else
|
|
|
|
|
poll_common_ids = @poll.poll_published_ids(current_user.id)
|
|
|
|
|
@poll_course_groups = @course.get_ex_published_course(poll_common_ids)
|
|
|
|
@ -1080,7 +1064,7 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
#班级的选择
|
|
|
|
|
if group_id.present?
|
|
|
|
|
poll_students = @course_all_members.course_find_by_ids("course_group_id",group_id) # 问卷所分班的全部人数
|
|
|
|
|
poll_students = @course_all_members.course_find_by_ids("course_group_id", group_id) # 问卷所分班的全部人数
|
|
|
|
|
user_ids = poll_students.pluck(:user_id).reject(&:blank?)
|
|
|
|
|
@poll_users_list = @poll_users_list.find_by_group_ids(user_ids)
|
|
|
|
|
end
|
|
|
|
@ -1134,8 +1118,8 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def poll_params
|
|
|
|
|
params.require(:poll).permit(:polls_name,:polls_status,:publish_time,:end_time,:polls_description,
|
|
|
|
|
:show_result,:exercise_bank_id,:is_public,:unified_setting,:un_anonymous)
|
|
|
|
|
params.require(:poll).permit(:polls_name, :polls_status, :publish_time, :end_time, :polls_description,
|
|
|
|
|
:show_result, :exercise_bank_id, :is_public, :unified_setting, :un_anonymous)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获得问卷及课堂
|
|
|
|
@ -1176,7 +1160,7 @@ class PollsController < ApplicationController
|
|
|
|
|
def check_unified_setting?(poll) #问卷是否统一设置,如为分班设置,当前用户是否在班级内
|
|
|
|
|
if !poll.unified_setting #如果为分班设置,则需判断用户是否在班级内
|
|
|
|
|
poll_group_settings = poll.poll_group_settings.pluck(:course_group_id)
|
|
|
|
|
member = @course.course_members.course_find_by_ids("user_id",current_user.id)
|
|
|
|
|
member = @course.course_members.course_find_by_ids("user_id", current_user.id)
|
|
|
|
|
member_group_id = member.pluck(:course_group_id).uniq
|
|
|
|
|
if (member_group_id & poll_group_settings).size > 0 || @user_course_identity < Course::STUDENT
|
|
|
|
|
true
|
|
|
|
@ -1196,7 +1180,7 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def set_poll_status(publish_time,end_time)
|
|
|
|
|
def set_poll_status(publish_time, end_time)
|
|
|
|
|
time_now_i = Time.now
|
|
|
|
|
if publish_time.present? && end_time.present? && publish_time <= time_now_i && end_time > time_now_i
|
|
|
|
|
2
|
|
|
|
@ -1217,20 +1201,20 @@ class PollsController < ApplicationController
|
|
|
|
|
@poll_question_singles = @poll_questions.ques_count(1).size # 单选题
|
|
|
|
|
@poll_question_doubles = @poll_questions.ques_count(2).size # 多选题
|
|
|
|
|
@poll_question_mains = @poll_questions.ques_count(3).size #主观题
|
|
|
|
|
@poll_questions = @poll_questions&.includes(:poll_answers,:poll_votes).distinct
|
|
|
|
|
@poll_questions = @poll_questions&.includes(:poll_answers, :poll_votes).distinct
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_poll_question_complete #commit_poll 的权限
|
|
|
|
|
poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first
|
|
|
|
|
poll_status = @poll.get_poll_status(current_user)
|
|
|
|
|
if @user_course_identity < Course::STUDENT || (poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1)
|
|
|
|
|
normal_status(-1,"用户没有权限!") #老师/管理员在提交时没有权限
|
|
|
|
|
normal_status(-1, "用户没有权限!") #老师/管理员在提交时没有权限
|
|
|
|
|
else
|
|
|
|
|
necessary_answer = 0
|
|
|
|
|
poll_questions = @poll.poll_questions
|
|
|
|
|
necessary_question = poll_questions.ques_necessary # 问卷必答的问题
|
|
|
|
|
necessary_question.each do |q|
|
|
|
|
|
user_vote = q.poll_votes.find_current_vote("user_id",current_user.id)
|
|
|
|
|
user_vote = q.poll_votes.find_current_vote("user_id", current_user.id)
|
|
|
|
|
vote_answer_id = user_vote.pluck(:poll_answer_id).reject(&:blank?).size
|
|
|
|
|
vote_text_count = user_vote.pluck(:vote_text).reject(&:blank?).size
|
|
|
|
|
if vote_answer_id == 0 && vote_text_count == 0
|
|
|
|
@ -1238,7 +1222,7 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if necessary_answer > 0
|
|
|
|
|
normal_status(-1,"问卷提交失败,有#{necessary_answer}个未答的必答题!")
|
|
|
|
|
normal_status(-1, "问卷提交失败,有#{necessary_answer}个未答的必答题!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -1247,7 +1231,7 @@ class PollsController < ApplicationController
|
|
|
|
|
poll_status = @poll.get_poll_status(current_user)
|
|
|
|
|
commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的
|
|
|
|
|
unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?)
|
|
|
|
|
normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
|
|
|
|
|
normal_status(-1, "没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -1255,11 +1239,11 @@ class PollsController < ApplicationController
|
|
|
|
|
user_login = params[:login]
|
|
|
|
|
# @poll_current_user_id = params[:user_id]
|
|
|
|
|
if user_login.blank? && @user_course_identity < Course::STUDENT #id不存在,且当前为老师/管理员等
|
|
|
|
|
normal_status(-1,"请输入学生登陆名!")
|
|
|
|
|
normal_status(-1, "请输入学生登陆名!")
|
|
|
|
|
else
|
|
|
|
|
@answer_user = User.find_by(login:user_login)
|
|
|
|
|
@answer_user = User.find_by(login: user_login)
|
|
|
|
|
if @answer_user.blank?
|
|
|
|
|
normal_status(404,"答题用户不存在")
|
|
|
|
|
normal_status(404, "答题用户不存在")
|
|
|
|
|
else
|
|
|
|
|
@poll_current_user_id = @answer_user.id || current_user.id
|
|
|
|
|
end
|
|
|
|
@ -1273,11 +1257,11 @@ class PollsController < ApplicationController
|
|
|
|
|
@poll_questions_count = @poll_questions.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布
|
|
|
|
|
def get_user_permission_course(poll_ids, status) #获取用户权限范围内的已发布/未发布
|
|
|
|
|
poll_status = status.to_i
|
|
|
|
|
unpublish_group = []
|
|
|
|
|
user_groups_id = @course.charge_group_ids(current_user)
|
|
|
|
|
all_polls = Poll.where(id:poll_ids)
|
|
|
|
|
all_polls = Poll.where(id: poll_ids)
|
|
|
|
|
all_polls.each do |poll|
|
|
|
|
|
if poll.present?
|
|
|
|
|
if poll.unified_setting
|
|
|
|
@ -1317,28 +1301,28 @@ class PollsController < ApplicationController
|
|
|
|
|
publish_course = params[:publish_time_groups]
|
|
|
|
|
unified_setting = params[:unified_setting]
|
|
|
|
|
if @course.is_end
|
|
|
|
|
normal_status(-1,"课堂已结束不能再修改!")
|
|
|
|
|
normal_status(-1, "课堂已结束不能再修改!")
|
|
|
|
|
elsif unified_setting
|
|
|
|
|
poll_group_settings = @poll.poll_group_settings
|
|
|
|
|
if poll_group_settings.present?
|
|
|
|
|
p_time_present = poll_group_settings.publish_time_present.map(&:publish_time).min
|
|
|
|
|
if p_time_present < Time.now
|
|
|
|
|
normal_status(-1,"设置失败,存在已发布的分班!")
|
|
|
|
|
normal_status(-1, "设置失败,存在已发布的分班!")
|
|
|
|
|
end
|
|
|
|
|
elsif params[:publish_time].blank?
|
|
|
|
|
normal_status(-1,"发布时间不允许为空")
|
|
|
|
|
normal_status(-1, "发布时间不允许为空")
|
|
|
|
|
end
|
|
|
|
|
elsif unified_setting.present? && !unified_setting #非统一设置,分班不能为空
|
|
|
|
|
if publish_course.present?
|
|
|
|
|
course_ids = publish_course.map{|a| a[:course_group_id]}.sum
|
|
|
|
|
publish_t = publish_course.map{|a| a[:publish_time]}
|
|
|
|
|
course_ids = publish_course.map {|a| a[:course_group_id]}.sum
|
|
|
|
|
publish_t = publish_course.map {|a| a[:publish_time]}
|
|
|
|
|
if course_ids.include?(nil) || course_ids.count == 0
|
|
|
|
|
normal_status(-1,"请选择分班!")
|
|
|
|
|
normal_status(-1, "请选择分班!")
|
|
|
|
|
elsif publish_t.include?(nil) || publish_t.count == 0
|
|
|
|
|
normal_status(-1,"发布时间不允许为空")
|
|
|
|
|
normal_status(-1, "发布时间不允许为空")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1,"请选择分班!")
|
|
|
|
|
normal_status(-1, "请选择分班!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -1354,7 +1338,7 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#问卷的统计结果的导出
|
|
|
|
|
def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids)
|
|
|
|
|
def poll_commit_result(poll, poll_questions, poll_users, poll_commit_ids)
|
|
|
|
|
sub_commit = []
|
|
|
|
|
user_commit = []
|
|
|
|
|
poll_users_info = %w(序号)
|
|
|
|
@ -1368,50 +1352,50 @@ class PollsController < ApplicationController
|
|
|
|
|
poll_users_info = poll_users_info + user_info + poll_ques_titles
|
|
|
|
|
poll_questions.each do |q|
|
|
|
|
|
if q.question_type != 3 #问题不为主观题
|
|
|
|
|
question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size #该问题的有效填写量
|
|
|
|
|
question_vote_user = q.poll_votes.find_current_vote("user_id", poll_commit_ids)&.size #该问题的有效填写量
|
|
|
|
|
sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组
|
|
|
|
|
sheet_answer_row = ["小计"] #选择题回答的答案人数,数组
|
|
|
|
|
sheet_answer_percent = ["比例"]
|
|
|
|
|
sheet_answer_useful = ["本题有效填写人次",question_vote_user]
|
|
|
|
|
sheet_answer_useful = ["本题有效填写人次", question_vote_user]
|
|
|
|
|
q.poll_answers.each do |a| #问卷的答案选项
|
|
|
|
|
answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size
|
|
|
|
|
answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%"
|
|
|
|
|
answer_users_count = a.poll_votes.find_current_vote("user_id", poll_commit_ids)&.size
|
|
|
|
|
answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f) * 100).round(1).to_s}%"
|
|
|
|
|
sheet_row.push(a.answer_text)
|
|
|
|
|
sheet_answer_row.push(answer_users_count)
|
|
|
|
|
sheet_answer_percent.push(answer_percent)
|
|
|
|
|
end
|
|
|
|
|
sheet_sub_commit = {
|
|
|
|
|
sub_title: sheet_row,
|
|
|
|
|
sub_user_votes:[sheet_answer_row,sheet_answer_percent,sheet_answer_useful]
|
|
|
|
|
sub_user_votes: [sheet_answer_row, sheet_answer_percent, sheet_answer_useful]
|
|
|
|
|
}
|
|
|
|
|
sub_commit.push(sheet_sub_commit)
|
|
|
|
|
else #主观题答案
|
|
|
|
|
user_votes= []
|
|
|
|
|
main_show_row = ["第#{q.question_number}题", q.question_title ]
|
|
|
|
|
q.poll_votes.each_with_index do |v,index| #主观题的答案
|
|
|
|
|
q_poll_vote = [(index+1), v.vote_text.present? ? v.vote_text : "--"]
|
|
|
|
|
user_votes = []
|
|
|
|
|
main_show_row = ["第#{q.question_number}题", q.question_title]
|
|
|
|
|
q.poll_votes.each_with_index do |v, index| #主观题的答案
|
|
|
|
|
q_poll_vote = [(index + 1), v.vote_text.present? ? v.vote_text : "--"]
|
|
|
|
|
user_votes.push(q_poll_vote)
|
|
|
|
|
end
|
|
|
|
|
sheet_sub_commit = {
|
|
|
|
|
sub_title: main_show_row,
|
|
|
|
|
sub_user_votes:user_votes
|
|
|
|
|
sub_user_votes: user_votes
|
|
|
|
|
}
|
|
|
|
|
sub_commit.push(sheet_sub_commit)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end #each_with_index
|
|
|
|
|
|
|
|
|
|
poll_users.includes(user: [:user_extension,:poll_votes]).each_with_index do |u,index|
|
|
|
|
|
poll_users.includes(user: [:user_extension, :poll_votes]).each_with_index do |u, index|
|
|
|
|
|
u_user = u.user
|
|
|
|
|
user_answer_array = []
|
|
|
|
|
poll_questions.each do |q|
|
|
|
|
|
user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id)
|
|
|
|
|
user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id", q.id)
|
|
|
|
|
if user_poll_votes.present?
|
|
|
|
|
if q.question_type < 3
|
|
|
|
|
user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?)
|
|
|
|
|
if user_poll_answer_ids.count > 0
|
|
|
|
|
answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids)
|
|
|
|
|
if user_poll_answer_ids.count >1
|
|
|
|
|
answer_content = q.poll_answers.find_answer_by_custom("id", user_poll_answer_ids)
|
|
|
|
|
if user_poll_answer_ids.count > 1
|
|
|
|
|
u_answer = answer_content.pluck(:answer_text).join(";")
|
|
|
|
|
else
|
|
|
|
|
u_answer = answer_content.first&.answer_text
|
|
|
|
@ -1436,23 +1420,23 @@ class PollsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
user_answer_array.push(u_answer)
|
|
|
|
|
end
|
|
|
|
|
user_cell = [index+1]
|
|
|
|
|
user_cell = [index + 1]
|
|
|
|
|
if poll_un_anony
|
|
|
|
|
user_login = u_user.login
|
|
|
|
|
user_name = u_user.real_name.present? ? u_user.real_name : "--"
|
|
|
|
|
user_class = poll.course.user_group_name(u_user.id)
|
|
|
|
|
user_student_id = u_user.student_id.present? ? u_user.student_id : "--"
|
|
|
|
|
user_school_name = u_user.school_name.present? ? u_user.school_name : "--"
|
|
|
|
|
user_cell += [user_login,user_name, user_class, u_user.mail, user_student_id, user_school_name]
|
|
|
|
|
user_cell += [user_login, user_name, user_class, u_user.mail, user_student_id, user_school_name]
|
|
|
|
|
end
|
|
|
|
|
all_user_cell = user_cell + user_answer_array
|
|
|
|
|
user_commit.push(all_user_cell)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
poll_users_info:poll_users_info,
|
|
|
|
|
sub_commit:sub_commit,
|
|
|
|
|
user_commit:user_commit
|
|
|
|
|
poll_users_info: poll_users_info,
|
|
|
|
|
sub_commit: sub_commit,
|
|
|
|
|
user_commit: user_commit
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|