|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
class PollController < ApplicationController
|
|
|
|
|
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll]
|
|
|
|
|
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll,:export_poll]
|
|
|
|
|
before_filter :find_container, :only => [:new,:create, :index]
|
|
|
|
|
before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
|
|
|
|
|
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll]
|
|
|
|
|
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll]
|
|
|
|
|
include PollHelper
|
|
|
|
|
def index
|
|
|
|
|
if @course
|
|
|
|
@ -360,6 +360,17 @@ class PollController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#导出问卷
|
|
|
|
|
def export_poll
|
|
|
|
|
poll_questions = @poll.poll_questions
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.xls {
|
|
|
|
|
send_data(poll_to_xls(poll_questions), :type => "text/excel;charset=utf-8; header=present",
|
|
|
|
|
:filename => "#{@poll.polls_name}.xls")
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def find_poll_and_course
|
|
|
|
|
@poll = Poll.find params[:id]
|
|
|
|
@ -438,4 +449,41 @@ class PollController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
pu
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#将poll中题目转换为Excel
|
|
|
|
|
def poll_to_xls poll_questions
|
|
|
|
|
xls_report = StringIO.new
|
|
|
|
|
book = Spreadsheet::Workbook.new
|
|
|
|
|
sheet1 = book.create_worksheet :name => "poll"
|
|
|
|
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
|
|
|
|
count_row = 0
|
|
|
|
|
poll_questions.each do |poll_question|
|
|
|
|
|
if poll_question.question_type == 1 || poll_question.question_type == 2
|
|
|
|
|
sheet1.row(count_row).default_format = blue
|
|
|
|
|
sheet1[count_row,0]= l(:label_poll_question_num,:num => poll_question.question_number)
|
|
|
|
|
sheet1[count_row + 1,0] = l(:label_poll_subtotal)
|
|
|
|
|
sheet1[count_row + 2,0] = l(:label_poll_proportion)
|
|
|
|
|
poll_question.poll_answers.each_with_index do |poll_answer,i|
|
|
|
|
|
sheet1[count_row, i + 1] = poll_answer.answer_text
|
|
|
|
|
sheet1[count_row + 1, i + 1] = poll_answer.poll_votes.count
|
|
|
|
|
sheet1[count_row + 2, i + 1] = statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)).to_s + "%"
|
|
|
|
|
end
|
|
|
|
|
sheet1[count_row + 3,0] = l(:label_poll_valid_commit)
|
|
|
|
|
sheet1[count_row + 3,1] = total_answer(poll_question.id)
|
|
|
|
|
count_row += 5
|
|
|
|
|
else
|
|
|
|
|
sheet1.row(count_row).default_format = blue
|
|
|
|
|
sheet1[count_row,0] = l(:label_poll_question_num,:num => poll_question.question_number)
|
|
|
|
|
sheet1[count_row,1] = poll_question.question_title
|
|
|
|
|
count_row += 1
|
|
|
|
|
poll_question.poll_votes.each do |poll_vote|
|
|
|
|
|
sheet1[count_row,0] = poll_vote.vote_text
|
|
|
|
|
count_row += 1
|
|
|
|
|
end
|
|
|
|
|
count_row += 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
book.write xls_report
|
|
|
|
|
xls_report.string
|
|
|
|
|
end
|
|
|
|
|
end
|