|
|
|
@ -410,6 +410,68 @@ class PollController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 将其他地方的问卷导出来
|
|
|
|
|
def other_poll
|
|
|
|
|
# 查作者是我,且不在当前课程内的问卷 进行导入
|
|
|
|
|
@polls = Poll.where("user_id = #{User.current.id} and polls_type = 'course' and polls_group_id != #{params[:polls_group_id]}")
|
|
|
|
|
@polls_group_id = params[:polls_group_id]
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 将问卷导入本课程
|
|
|
|
|
def import_other_poll
|
|
|
|
|
course_id = params[:course_id]
|
|
|
|
|
@course = Course.find(course_id)
|
|
|
|
|
params[:polls].each_with_index do |p,i|
|
|
|
|
|
poll = Poll.find(p)
|
|
|
|
|
option = {
|
|
|
|
|
:polls_name => poll.polls_name,
|
|
|
|
|
:polls_type => 'Course',
|
|
|
|
|
:polls_group_id => course_id,
|
|
|
|
|
:polls_status => 1,
|
|
|
|
|
:user_id => User.current.id,
|
|
|
|
|
:published_at => Time.now,
|
|
|
|
|
:closed_at => Time.now,
|
|
|
|
|
:show_result => 1,
|
|
|
|
|
:polls_description => poll.polls_description
|
|
|
|
|
}
|
|
|
|
|
@poll = Poll.create option
|
|
|
|
|
|
|
|
|
|
poll.poll_questions.each do | q|
|
|
|
|
|
#question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
|
|
|
|
|
option = {
|
|
|
|
|
:is_necessary => q[:is_necessary],
|
|
|
|
|
:question_title => q[:question_title],
|
|
|
|
|
:question_type => q[:question_type] || 1,
|
|
|
|
|
:question_number => q[:question_number]
|
|
|
|
|
}
|
|
|
|
|
@poll_questions = @poll.poll_questions.new option
|
|
|
|
|
|
|
|
|
|
for i in 1..q.poll_answers.count
|
|
|
|
|
answer = q.poll_answers[i-1].nil? ? l(:label_new_answer) : q.poll_answers[i-1][:answer_text]
|
|
|
|
|
question_option = {
|
|
|
|
|
:answer_position => i,
|
|
|
|
|
:answer_text => answer
|
|
|
|
|
}
|
|
|
|
|
@poll_questions.poll_answers.new question_option
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@poll.save
|
|
|
|
|
end
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
|
|
|
|
if @is_teacher
|
|
|
|
|
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
|
|
|
|
|
else
|
|
|
|
|
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
|
|
|
|
|
end
|
|
|
|
|
@polls = paginateHelper polls,20 #分页
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def find_poll_and_course
|
|
|
|
|
@poll = Poll.find params[:id]
|
|
|
|
|