|
|
|
@ -2,8 +2,7 @@ class PollVotesController < ApplicationController
|
|
|
|
|
#在开始回答和提交问卷的时候,已经做了判断用户的身份权限
|
|
|
|
|
before_action :require_login
|
|
|
|
|
before_action :get_poll_question
|
|
|
|
|
before_action :check_answer_in_question,only: [:create]
|
|
|
|
|
before_action :check_multi_answers
|
|
|
|
|
before_action :check_answer_in_question
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create #每一次答案的点击,请求一次
|
|
|
|
@ -124,7 +123,7 @@ class PollVotesController < ApplicationController
|
|
|
|
|
if @poll_question.blank?
|
|
|
|
|
normal_status(-1,"问卷试题不存在!")
|
|
|
|
|
else
|
|
|
|
|
@poll = @poll_question.poll
|
|
|
|
|
@poll = @poll_question.poll.includes(:poll_users)
|
|
|
|
|
@course = @poll.course
|
|
|
|
|
if @poll.blank?
|
|
|
|
|
normal_status(-1,"问卷不存在!")
|
|
|
|
@ -132,20 +131,22 @@ class PollVotesController < ApplicationController
|
|
|
|
|
normal_status(-1,"课堂不存在!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_answer_in_question
|
|
|
|
|
poll_answer_ids = @poll_question.poll_answers.pluck(:id)
|
|
|
|
|
if @poll_question.question_type == 1 #单选题/多选题
|
|
|
|
|
unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?)
|
|
|
|
|
normal_status(-1, "答案ID错误!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# poll_answer_ids = @poll_question.poll_answers.pluck(:id)
|
|
|
|
|
# if @poll_question.question_type == 1 #单选题/多选题
|
|
|
|
|
# unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?)
|
|
|
|
|
# normal_status(-1, "答案ID错误!")
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
poll_user_status = @poll.get_poll_status(current_user.id)
|
|
|
|
|
poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户
|
|
|
|
|
|
|
|
|
|
def check_multi_answers
|
|
|
|
|
if @poll_question.question_type == 2
|
|
|
|
|
question_type = @poll_question&.question_type
|
|
|
|
|
if [1,2].include?(question_type) && params[:poll_answer_id].blank?
|
|
|
|
|
normal_status(-1,"答案ID错误!")
|
|
|
|
|
elsif question_type == 2
|
|
|
|
|
user_vote_count = params[:poll_answer_id].size
|
|
|
|
|
if @poll_question.max_choices.present?
|
|
|
|
|
question_max_choices = @poll_question.max_choices
|
|
|
|
@ -155,6 +156,9 @@ class PollVotesController < ApplicationController
|
|
|
|
|
if question_max_choices > 0 && user_vote_count > question_max_choices
|
|
|
|
|
normal_status(-1,"多选题答案超过最大限制!")
|
|
|
|
|
end
|
|
|
|
|
elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3
|
|
|
|
|
normal_status(-1,"已提交/已结束的问卷不允许修改!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|