@ -18,7 +18,7 @@ class PollsController < ApplicationController
before_action :check_user_id_start_answer , only : [ :start_answer ]
before_action :check_user_id_start_answer , only : [ :start_answer ]
before_action :check_poll_question_complete , only : [ :commit_poll ] #问卷提交前来判断问题是否完成
before_action :check_poll_question_complete , only : [ :commit_poll ] #问卷提交前来判断问题是否完成
before_action :check_poll_commit_result , only : [ :commit_result ]
before_action :check_poll_commit_result , only : [ :commit_result ]
before_action :get_all_polls_commit , 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
include PollsHelper
@ -920,19 +920,32 @@ class PollsController < ApplicationController
def commit_result
def commit_result
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
begin
# @poll_questions = @poll.poll_questions.order("question_number ASC")
# 全部页面,需返回
# @poll_questions_count = @poll_questions.size
# 分页
# 分页
# @poll = @poll.includes(:poll_users,user: :user_extension)
@poll_users = @poll . poll_users
@poll_commit_ids = @poll_users . commit_by_status ( 1 ) . pluck ( :user_id ) #问卷提交用户的id
@page = params [ :page ] || 1
@page = params [ :page ] || 1
@limit = params [ :limit ] || 10
@limit = params [ :limit ] || 10
@poll_export_questions = @poll_questions . order ( " question_number ASC " )
@poll_export_questions = @poll_questions . order ( " question_number ASC " )
@poll_questions = @poll_questions . page ( @page ) . per ( @limit )
@poll_questions = @poll_questions . page ( @page ) . per ( @limit )
respond_to do | format |
respond_to do | format |
format . json
format . json
format . xlsx {
format . xlsx {
if @user_course_identity > Course :: ASSISTANT_PROFESSOR
if @user_course_identity > Course :: ASSISTANT_PROFESSOR
tip_exception ( 403 , " 无权限操作 " )
tip_exception ( 403 , " 无权限操作 " )
elsif @poll_export_questions . size == 0 || ( @poll_users . where ( " commit_status = ? " , 1 ) . size == 0 )
normal_status ( - 1 , " 暂时没有提交的用户 " )
else
else
polls_export_name = current_user . real_name + " _ " + @course . name + " _ " + @poll . polls_name + " _ " + Time . now . strftime ( '%Y%m%d_%H%M%S' )
polls_export_name = " #{ current_user . real_name } _ #{ @course . name } _ #{ @poll . polls_name } _ #{ Time . now . strftime ( '%Y%m%d_%H%M%S' ) } "
render xlsx : " #{ polls_export_name . strip . first ( 30 ) } " , template : " polls/commit_result.xlsx.axlsx " , locals : { poll_questions : @poll_export_questions }
render xlsx : " #{ polls_export_name . strip . first ( 30 ) } " , template : " polls/commit_result.xlsx.axlsx " , locals : {
poll_questions : @poll_export_questions ,
poll : @poll ,
poll_users : @poll_users ,
poll_commit_ids : @poll_commit_ids }
end
end
}
}
end
end
@ -953,15 +966,12 @@ class PollsController < ApplicationController
@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
logger . info ( " # # # # # # # F___________poll_user_ids________________ # # # #{ @poll . poll_users . pluck ( :id ) } " )
@poll_group_counts = @course . course_groups_count
@poll_group_counts = @course . course_groups_count
if @user_course_identity < Course :: STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷
if @user_course_identity < Course :: STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷
@poll_current_user_status = 0
@poll_current_user_status = 0
@poll_users_list = @poll . all_poll_users ( current_user . id ) #该老师分班的全部学生
@poll_users_list = @poll . all_poll_users ( current_user . id ) #该老师分班的全部学生
get_poll_answers ( @poll_users_list )
get_poll_answers ( @poll_users_list )
logger . info ( " # # # # # # # F__________@poll_users_list________________ # # # #{ @poll_users_list . pluck ( :id ) } " )
if @poll_list_status == 1
if @poll_list_status == 1
@poll_course_groups = [ ]
@poll_course_groups = [ ]
else
else
@ -1007,14 +1017,8 @@ class PollsController < ApplicationController
search_content = params [ :search ]
search_content = params [ :search ]
if @poll_users_list . present? && @poll_users_list . count > 0
if @poll_users_list . present? && @poll_users_list . count > 0
if order == " student_id "
@poll_users_list = @poll_users_list . joins ( user : [ :user_extension ] ) . order ( " user_extensions.student_id DESC " )
else
@poll_users_list = @poll_users_list . order ( " end_at DESC " )
end
#答题状态的选择
#答题状态的选择
#
if choose_type . present?
if choose_type . present?
@poll_users_list = @poll_users_list . commit_by_status ( choose_type )
@poll_users_list = @poll_users_list . commit_by_status ( choose_type )
end
end
@ -1031,11 +1035,18 @@ class PollsController < ApplicationController
@poll_users_list = @poll_users_list . joins ( user : :user_extension ) . where ( " CONCAT(lastname, firstname) like ? OR student_id like ? " , " % #{ search_content } % " , " % #{ search_content } % " )
@poll_users_list = @poll_users_list . joins ( user : :user_extension ) . where ( " CONCAT(lastname, firstname) like ? OR student_id like ? " , " % #{ search_content } % " , " % #{ search_content } % " )
end
end
if order == " student_id "
@poll_users_list = @poll_users_list . joins ( user : :user_extension ) . order ( " user_extensions.student_id DESC " )
else
@poll_users_list = @poll_users_list . joins ( user : :user_extension ) . order ( " end_at DESC " )
end
@poll_users_size = @poll_users_list . count
@poll_users_size = @poll_users_list . count
# 分页
# 分页
@page = params [ :page ] || 1
page = params [ :page ] || 1
@limit = params [ :limit ] || 20
limit = params [ :limit ] || 20
@poll_users_list = @poll_users_list . page ( @page ) . per ( @limit )
@poll_users_list = @poll_users_list . page ( page ) . per ( limit)
else
else
@poll_users_list = [ ]
@poll_users_list = [ ]
@poll_users_size = 0
@poll_users_size = 0
@ -1145,10 +1156,10 @@ class PollsController < ApplicationController
def get_questions_count
def get_questions_count
@poll_questions = @poll . poll_questions & . includes ( :poll_answers , :poll_votes ) . order ( " question_number ASC " )
@poll_questions = @poll . poll_questions & . includes ( :poll_answers , :poll_votes ) . order ( " question_number ASC " )
@poll_questions_count = @poll_questions . count # 全部的题目数
@poll_questions_count = @poll_questions . size # 全部的题目数
@poll_question_singles = @poll_questions . ques_count ( 1 ) . all . count # 单选题
@poll_question_singles = @poll_questions . ques_count ( 1 ) . all . size # 单选题
@poll_question_doubles = @poll_questions . ques_count ( 2 ) . all . count # 多选题
@poll_question_doubles = @poll_questions . ques_count ( 2 ) . all . size # 多选题
@poll_question_mains = @poll_questions . ques_count ( 3 ) . all . count #主观题
@poll_question_mains = @poll_questions . ques_count ( 3 ) . all . size #主观题
end
end
def check_poll_question_complete #commit_poll 的权限
def check_poll_question_complete #commit_poll 的权限