|
|
@ -31,50 +31,48 @@ class PollsController < ApplicationController
|
|
|
|
@current_user_ = current_user
|
|
|
|
@current_user_ = current_user
|
|
|
|
@course_status = @course.is_end ? 0 : 1 # 课堂是否结束
|
|
|
|
@course_status = @course.is_end ? 0 : 1 # 课堂是否结束
|
|
|
|
@course_is_public = @course.is_public
|
|
|
|
@course_is_public = @course.is_public
|
|
|
|
@polls_count = @polls_all.count # 全部页面,需返回
|
|
|
|
|
|
|
|
@polls_unpublish_counts = @polls_all.poll_by_status(1).count #未发布的问卷数
|
|
|
|
|
|
|
|
@polls_published_counts = @polls_all.poll_by_status([2, 3]).count # 已发布的问卷数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 课堂的学生人数
|
|
|
|
# 课堂的学生人数
|
|
|
|
@course_all_members = @course.students #当前课堂的全部学生
|
|
|
|
@course_all_members = @course.students #当前课堂的全部学生
|
|
|
|
@course_all_members_count = @course_all_members.count #当前课堂的学生数
|
|
|
|
|
|
|
|
@current_student = @course_all_members.find_by(user_id: current_user.id) #当前用户是否为课堂的学生
|
|
|
|
@current_student = @course_all_members.find_by(user_id: current_user.id) #当前用户是否为课堂的学生
|
|
|
|
|
|
|
|
|
|
|
|
# polls的不同用户群体的显示
|
|
|
|
# polls的不同用户群体的显示
|
|
|
|
if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
|
|
|
|
if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
|
|
|
|
@is_teacher_or = 1
|
|
|
|
@is_teacher_or = 1
|
|
|
|
@teacher_groups_ids = @course.charge_group_ids(current_user)
|
|
|
|
|
|
|
|
@polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
|
|
|
|
@polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
|
|
|
|
elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的
|
|
|
|
elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的
|
|
|
|
@is_teacher_or = 2
|
|
|
|
@is_teacher_or = 2
|
|
|
|
member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0
|
|
|
|
@member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0
|
|
|
|
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
|
|
|
|
if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
|
|
|
|
@polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : []
|
|
|
|
@polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : []
|
|
|
|
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
|
|
|
|
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
|
|
|
|
# 已发布 当前用户班级分组的 试卷id
|
|
|
|
# 已发布 当前用户班级分组的 试卷id
|
|
|
|
poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published.pluck(:poll_id).uniq # 选择成员的班级id等于课堂问卷设置的班级id
|
|
|
|
not_poll_ids = @course.poll_group_settings.poll_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id)
|
|
|
|
@polls = member_show_polls.present? ? member_show_polls.public_or_unset.or(member_show_polls.where(id: poll_settings_ids)) : []
|
|
|
|
@polls = member_show_polls.where.not(id: not_poll_ids)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
|
|
|
|
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
|
|
|
|
@is_teacher_or = 0
|
|
|
|
@is_teacher_or = 0
|
|
|
|
@polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : []
|
|
|
|
@polls = member_show_polls.public_or_unset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if @polls.count > 0
|
|
|
|
if @polls.count > 0
|
|
|
|
if params[:type].present?
|
|
|
|
if params[:type].present?
|
|
|
|
choose_type = params[:type]
|
|
|
|
choose_type = params[:type]
|
|
|
|
member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0
|
|
|
|
poll_setting_ids = []
|
|
|
|
if @is_teacher_or == 2 && member_group_id > 0
|
|
|
|
if @is_teacher_or != 2
|
|
|
|
poll_groups_sets = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published
|
|
|
|
@polls = @polls.where("polls_status = #{choose_type}")
|
|
|
|
poll_settings_ids = poll_groups_sets.pluck(:poll_id)
|
|
|
|
|
|
|
|
poll_ended_ids = poll_groups_sets.poll_group_ended.pluck(:poll_id).uniq
|
|
|
|
|
|
|
|
# poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_ended.pluck(:poll_id).uniq
|
|
|
|
|
|
|
|
if choose_type.to_i == 2
|
|
|
|
|
|
|
|
@polls = @polls_all.present? ? @polls_all.poll_by_status(2).public_or_unset.or(@polls_all.where(id:(poll_settings_ids - poll_ended_ids).uniq)).distinct : []
|
|
|
|
|
|
|
|
elsif choose_type.to_i == 3
|
|
|
|
|
|
|
|
@polls = @polls_all.present? ? @polls_all.poll_by_status(3).public_or_unset.or(@polls_all.where(id: poll_ended_ids)).distinct : []
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@polls = @polls.poll_by_status(choose_type)
|
|
|
|
case choose_type
|
|
|
|
|
|
|
|
when 1
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
when 3
|
|
|
|
|
|
|
|
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_ended.pluck(:poll_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
unified_setting_ids = @polls.public_or_unset.where("polls_status = #{choose_type}").pluck(:id)
|
|
|
|
|
|
|
|
ex_ids = (poll_setting_ids + unified_setting_ids).uniq
|
|
|
|
|
|
|
|
@polls = @polls.where(id: ex_ids)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -91,10 +89,15 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
@polls = @polls.page(@page).per(@limit)
|
|
|
|
@polls = @polls.page(@page).per(@limit)
|
|
|
|
@polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings)
|
|
|
|
@polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings)
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@polls = []
|
|
|
|
@polls = []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@polls_count = @polls_all.size # 全部页面,需返回
|
|
|
|
|
|
|
|
@polls_unpublish_counts = @polls_all.poll_by_status(1).size #未发布的问卷数
|
|
|
|
|
|
|
|
@polls_published_counts = @polls_count - @polls_unpublish_counts # 已发布的问卷数
|
|
|
|
|
|
|
|
@course_all_members_count = @course_all_members.size #当前课堂的学生数
|
|
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
tip_exception(e.message)
|
|
|
|
tip_exception(e.message)
|
|
|
@ -202,7 +205,7 @@ class PollsController < ApplicationController
|
|
|
|
@is_teacher_or = 1
|
|
|
|
@is_teacher_or = 1
|
|
|
|
@user_poll_answer = 3 #教师页面
|
|
|
|
@user_poll_answer = 3 #教师页面
|
|
|
|
end
|
|
|
|
end
|
|
|
|
poll_status = @poll.get_poll_status(current_user.id)
|
|
|
|
poll_status = @poll.get_poll_status(current_user)
|
|
|
|
poll_id_array = [@poll.id]
|
|
|
|
poll_id_array = [@poll.id]
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_id_array,2).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 #是否存在未发布的
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的
|
|
|
@ -344,7 +347,7 @@ class PollsController < ApplicationController
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
check_ids = Poll.where(id: params[:check_ids])
|
|
|
|
check_ids = Poll.where(id: params[:check_ids])
|
|
|
|
check_ids.each do |poll|
|
|
|
|
check_ids.each do |poll|
|
|
|
|
poll_status = poll.get_poll_status(current_user.id)
|
|
|
|
poll_status = poll.get_poll_status(current_user)
|
|
|
|
if poll_status == 2 #跳过已截止的或未发布的
|
|
|
|
if poll_status == 2 #跳过已截止的或未发布的
|
|
|
|
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改,poll_group_settings
|
|
|
|
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改,poll_group_settings
|
|
|
|
if g_course
|
|
|
|
if g_course
|
|
|
@ -687,7 +690,7 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组
|
|
|
|
course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组
|
|
|
|
|
|
|
|
|
|
|
|
poll_status = @poll.get_poll_status(current_user.id)
|
|
|
|
poll_status = @poll.get_poll_status(current_user)
|
|
|
|
if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理
|
|
|
|
if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理
|
|
|
|
unified_setting = params[:unified_setting]
|
|
|
|
unified_setting = params[:unified_setting]
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -847,7 +850,7 @@ class PollsController < ApplicationController
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题
|
|
|
|
poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题
|
|
|
|
@poll_status = @poll.get_poll_status(current_user.id)
|
|
|
|
@poll_status = @poll.get_poll_status(current_user)
|
|
|
|
if poll_user_current.blank?
|
|
|
|
if poll_user_current.blank?
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的
|
|
|
|
poll_user_params = {
|
|
|
|
poll_user_params = {
|
|
|
@ -955,7 +958,7 @@ class PollsController < ApplicationController
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
poll_ids = [@poll.id]
|
|
|
|
poll_ids = [@poll.id]
|
|
|
|
@poll_list_status = @poll.get_poll_status(current_user.id)
|
|
|
|
@poll_list_status = @poll.get_poll_status(current_user)
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_ids,2).count
|
|
|
|
@poll_publish_count = get_user_permission_course(poll_ids,2).count
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_ids,1).count
|
|
|
|
@poll_unpublish_count = get_user_permission_course(poll_ids,1).count
|
|
|
|
@course_all_members = @course.students
|
|
|
|
@course_all_members = @course.students
|
|
|
@ -1103,7 +1106,7 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
## 判断开始答题页面的用户权限
|
|
|
|
## 判断开始答题页面的用户权限
|
|
|
|
def check_user_on_answer
|
|
|
|
def check_user_on_answer
|
|
|
|
poll_status = @poll.get_poll_status(current_user.id)
|
|
|
|
poll_status = @poll.get_poll_status(current_user)
|
|
|
|
if @user_course_identity == Course::STUDENT && poll_status == 1 #问卷未发布,且当前用户不为老师/管理员
|
|
|
|
if @user_course_identity == Course::STUDENT && poll_status == 1 #问卷未发布,且当前用户不为老师/管理员
|
|
|
|
normal_status(-1, "未发布问卷!")
|
|
|
|
normal_status(-1, "未发布问卷!")
|
|
|
|
elsif @user_course_identity > Course::STUDENT && (!@poll.is_public || (@poll.is_public && !@poll.unified_setting)) ##不为课堂成员,且问卷不为公开的,或问卷公开,但是不是统一设置的
|
|
|
|
elsif @user_course_identity > Course::STUDENT && (!@poll.is_public || (@poll.is_public && !@poll.unified_setting)) ##不为课堂成员,且问卷不为公开的,或问卷公开,但是不是统一设置的
|
|
|
@ -1160,7 +1163,7 @@ class PollsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
def check_poll_question_complete #commit_poll 的权限
|
|
|
|
def check_poll_question_complete #commit_poll 的权限
|
|
|
|
poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first
|
|
|
|
poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first
|
|
|
|
poll_status = @poll.get_poll_status(current_user.id)
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
else
|
|
|
@ -1182,7 +1185,7 @@ class PollsController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def check_poll_commit_result
|
|
|
|
def check_poll_commit_result
|
|
|
|
poll_status = @poll.get_poll_status(current_user.id)
|
|
|
|
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) #当前用户已提交问卷的
|
|
|
|
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?)
|
|
|
|
unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?)
|
|
|
|
normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
|
|
|
|
normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
|
|
|
@ -1214,18 +1217,12 @@ class PollsController < ApplicationController
|
|
|
|
def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布
|
|
|
|
def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布
|
|
|
|
poll_status = status.to_i
|
|
|
|
poll_status = status.to_i
|
|
|
|
unpublish_group = []
|
|
|
|
unpublish_group = []
|
|
|
|
# g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq
|
|
|
|
|
|
|
|
# if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限
|
|
|
|
|
|
|
|
# user_groups_id = @course.course_groups.pluck(:id)
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# user_groups_id = g_course_ids
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
user_groups_id = @course.charge_group_ids(current_user)
|
|
|
|
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|
|
|
|
|
all_polls.each do |poll|
|
|
|
|
if poll.present?
|
|
|
|
if poll.present?
|
|
|
|
if poll.unified_setting
|
|
|
|
if poll.unified_setting
|
|
|
|
poll_user_status = poll.get_poll_status(current_user.id) #当前用户的能看到的试卷
|
|
|
|
poll_user_status = poll.get_poll_status(current_user) #当前用户的能看到的试卷
|
|
|
|
if poll_user_status == poll_status || poll_status == 3 #未发布的情况
|
|
|
|
if poll_user_status == poll_status || poll_status == 3 #未发布的情况
|
|
|
|
unpublish_group = unpublish_group + user_groups_id
|
|
|
|
unpublish_group = unpublish_group + user_groups_id
|
|
|
|
else
|
|
|
|
else
|
|
|
|