You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

poll_controller.rb 22 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
12 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #encoding utf-8
  2. class PollController < ApplicationController
  3. 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]
  4. before_filter :find_container, :only => [:new,:create, :index]
  5. before_filter :is_logged, :only => [:index, :show, :poll_result,:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll,:commit_answer,:commit_poll,:statistics_result]
  6. before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
  7. before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll]
  8. include PollHelper
  9. def index
  10. if @course
  11. @is_teacher = User.current.allowed_to?(:as_teacher,@course)
  12. if @is_teacher
  13. polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
  14. else
  15. polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
  16. end
  17. @polls = paginateHelper polls,20 #分页
  18. @left_nav_type = 7
  19. respond_to do |format|
  20. format.html{render :layout => 'base_courses'}
  21. end
  22. elsif @project
  23. #项目的问卷调查相关代码
  24. end
  25. end
  26. def show
  27. @poll = Poll.find params[:id]
  28. if @poll.polls_status != 2 && !(User.current.allowed_to?(:as_teacher,@course) || User.current.admin?)
  29. render_403
  30. return
  31. end
  32. # 问卷消息状态更新
  33. query_course_poll = @poll.course_messages
  34. query_course_poll.each do |query|
  35. if User.current.id == query.user_id
  36. query.update_attributes(:viewed => true)
  37. end
  38. end
  39. #已提交问卷的用户不能再访问该界面
  40. if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
  41. redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id)
  42. else
  43. @can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin?
  44. @percent = get_percent(@poll,User.current)
  45. poll_questions = @poll.poll_questions
  46. @poll_questions = paginateHelper poll_questions,5 #分页
  47. @left_nav_type = 7
  48. respond_to do |format|
  49. format.html {render :layout => 'base_courses'}
  50. end
  51. end
  52. end
  53. def new
  54. if @course
  55. option = {
  56. :polls_name => "",
  57. :polls_type => @course.class.to_s,
  58. :polls_group_id => @course.id,
  59. :polls_status => 1,
  60. :user_id => User.current.id,
  61. :published_at => Time.now,
  62. :closed_at => Time.now,
  63. :show_result => 1,
  64. :polls_description => ""
  65. }
  66. @poll = Poll.create option
  67. if @poll
  68. redirect_to edit_poll_url @poll.id
  69. end
  70. elsif @project
  71. #项目的问卷调查相关代码
  72. end
  73. end
  74. def create
  75. end
  76. def edit
  77. respond_to do |format|
  78. @left_nav_type = 7
  79. format.html{render :layout => 'base_courses'}
  80. end
  81. end
  82. def update
  83. @poll.polls_name = params[:polls_name]
  84. @poll.polls_description = params[:polls_description]
  85. if @poll.save
  86. respond_to do |format|
  87. format.js
  88. end
  89. else
  90. render_404
  91. end
  92. end
  93. def destroy
  94. if @poll && @poll.destroy
  95. if @is_teacher
  96. polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
  97. else
  98. polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
  99. end
  100. @polls = paginateHelper polls,20 #分页
  101. respond_to do |format|
  102. format.js
  103. end
  104. end
  105. end
  106. def statistics_result
  107. @poll = Poll.find(params[:id])
  108. poll_questions = @poll.poll_questions
  109. @poll_questions = paginateHelper poll_questions, 5
  110. @left_nav_type = 7
  111. respond_to do |format|
  112. format.html{render :layout => 'base_courses'}
  113. end
  114. end
  115. def get_poll_totalcount poll_question
  116. @total_questions_count = poll_question.poll_votes.count
  117. end
  118. def get_poll_everycount poll_answer
  119. @every_answer_count = poll_answer.poll_votes.count
  120. end
  121. #添加题目
  122. def create_poll_question
  123. question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
  124. option = {
  125. :is_necessary => (params[:is_necessary]=="true" ? 1 : 0),
  126. :question_title => question_title,
  127. :question_type => params[:question_type] || 1,
  128. :question_number => @poll.poll_questions.count + 1
  129. }
  130. @poll_questions = @poll.poll_questions.new option
  131. if params[:question_answer]
  132. for i in 1..params[:question_answer].count
  133. answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
  134. question_option = {
  135. :answer_position => i,
  136. :answer_text => answer
  137. }
  138. @poll_questions.poll_answers.new question_option
  139. end
  140. end
  141. # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1
  142. if params[:quest_id]
  143. @is_insert = true
  144. @poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1")
  145. @poll_question_num = params[:quest_num].to_i
  146. @poll_questions.question_number = params[:quest_num].to_i + 1
  147. end
  148. if @poll_questions.save
  149. respond_to do |format|
  150. format.js
  151. end
  152. end
  153. end
  154. #修改题目
  155. def update_poll_question
  156. @poll_question = PollQuestion.find params[:poll_question]
  157. #@poll = @poll_question.poll
  158. @poll_question.is_necessary = params[:is_necessary]=="true" ? 1 : 0
  159. @poll_question.question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
  160. ################处理选项
  161. if params[:question_answer]
  162. @poll_question.poll_answers.each do |answer|
  163. answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
  164. end
  165. for i in 1..params[:question_answer].count
  166. question = @poll_question.poll_answers.find_by_id params[:question_answer].keys[i-1]
  167. answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
  168. if question
  169. question.answer_position = i
  170. question.answer_text = answer
  171. question.save
  172. else
  173. question_option = {
  174. :answer_position => i,
  175. :answer_text => answer
  176. }
  177. @poll_question.poll_answers.new question_option
  178. end
  179. end
  180. end
  181. @poll_question.save
  182. respond_to do |format|
  183. format.js
  184. end
  185. end
  186. #删除题目
  187. def delete_poll_question
  188. @poll_question = PollQuestion.find params[:poll_question]
  189. @poll = @poll_question.poll
  190. poll_questions = @poll.poll_questions.where("question_number > #{@poll_question.question_number}")
  191. poll_questions.each do |question|
  192. question.question_number -= 1
  193. question.save
  194. end
  195. if @poll_question && @poll_question.destroy
  196. respond_to do |format|
  197. format.js
  198. end
  199. end
  200. end
  201. #发布问卷
  202. def publish_poll
  203. @poll.polls_status = 2
  204. @poll.published_at = Time.now
  205. @poll.show_result = params[:show_result]
  206. if @poll.save
  207. if params[:is_remote]
  208. redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id)
  209. else
  210. respond_to do |format|
  211. format.js
  212. end
  213. end
  214. end
  215. end
  216. #提交答案
  217. def commit_answer
  218. pq = PollQuestion.find(params[:poll_question_id])
  219. if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
  220. render :json => {:text => "failure"}
  221. return
  222. end
  223. if pq.question_type == 1
  224. #单选题
  225. pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
  226. if pv.nil?
  227. #尚未答该题,添加答案
  228. pv = PollVote.new
  229. pv.user_id = User.current.id
  230. pv.poll_question_id = params[:poll_question_id]
  231. end
  232. #修改该题对应答案
  233. pv.poll_answer_id = params[:poll_answer_id]
  234. if pv.save
  235. #保存成功返回成功信息及当前以答题百分比
  236. @percent = get_percent(@poll,User.current)
  237. render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)}
  238. else
  239. #返回失败信息
  240. render :json => {:text => "failure"}
  241. end
  242. elsif pq.question_type == 2
  243. #多选题
  244. pv = PollVote.find_by_poll_answer_id_and_user_id(params[:poll_answer_id],User.current.id)
  245. if pv.nil?
  246. #尚未答该题,添加答案
  247. pv = PollVote.new
  248. pv.user_id = User.current.id
  249. pv.poll_question_id = params[:poll_question_id]
  250. pv.poll_answer_id = params[:poll_answer_id]
  251. if pv.save
  252. @percent = get_percent(@poll,User.current)
  253. render :json => {:text => "true",:percent => format("%.2f" ,@percent)}
  254. else
  255. render :json => {:text => "failure"}
  256. end
  257. else
  258. #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
  259. if pv.delete
  260. @percent = get_percent(@poll,User.current)
  261. render :json => {:text => "false" ,:percent => format("%.2f" ,@percent)}
  262. else
  263. render :json => {:text => "failure"}
  264. end
  265. end
  266. elsif pq.question_type == 3 || pq.question_type == 4
  267. #单行文本,多行文本题
  268. pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
  269. if pv.nil?
  270. #pv为空之前尚未答题,添加答案
  271. if params[:vote_text].nil? || params[:vote_text].blank?
  272. #用户提交空答案,视作不作答
  273. @percent = get_percent(@poll,User.current)
  274. render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
  275. else
  276. #添加答案
  277. pv = PollVote.new
  278. pv.user_id = User.current.id
  279. pv.poll_question_id = params[:poll_question_id]
  280. pv.vote_text = params[:vote_text]
  281. if pv.save
  282. @percent = get_percent(@poll,User.current)
  283. render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
  284. else
  285. render :json => {:text => "failure"}
  286. end
  287. end
  288. else
  289. #pv不为空说明用户之前已作答
  290. if params[:vote_text].nil? || params[:vote_text].blank?
  291. #用户提交空答案,视为删除答案
  292. if pv.delete
  293. @percent = get_percent(@poll,User.current)
  294. render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
  295. else
  296. render :json => {:text => "failure"}
  297. end
  298. else
  299. #用户修改答案
  300. pv.vote_text = params[:vote_text]
  301. if pv.save
  302. @percent = get_percent(@poll,User.current)
  303. render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
  304. else
  305. render :json => {:text => "failure"}
  306. end
  307. end
  308. end
  309. else
  310. render :json => {:text => "failure"}
  311. end
  312. end
  313. #提交问卷
  314. def commit_poll
  315. @uncomplete_question = get_uncomplete_question(@poll,User.current)
  316. if @uncomplete_question.count < 1
  317. pu = get_poll_user(@poll.id,User.current.id)
  318. pu.user_id = User.current.id
  319. pu.poll_id = @poll.id
  320. if pu.save
  321. #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
  322. @status = 0 #提交成功
  323. else
  324. @status = 2 #未知错误
  325. end
  326. else
  327. @status = 1 #有未做得必答题
  328. end
  329. respond_to do |format|
  330. format.js
  331. end
  332. end
  333. def import_poll
  334. @poll = Poll.find(params[:to_id])
  335. question_num = @poll.poll_questions.select("max(question_number) question_number").first.question_number
  336. import_poll = Poll.find(params[:import_id])
  337. import_poll.poll_questions.each_with_index do |question,index|
  338. option = {
  339. :is_necessary => question.is_necessary,
  340. :question_title => question.question_title,
  341. :question_type => question.question_type,
  342. :question_number => question_num + index+1
  343. }
  344. poll_questions = @poll.poll_questions.new option
  345. for i in 1..question.poll_answers.count
  346. answer = question.poll_answers[i-1][:answer_text]
  347. question_option = {
  348. :answer_position => i,
  349. :answer_text => answer
  350. }
  351. poll_questions.poll_answers.new question_option
  352. end
  353. @poll.poll_questions << poll_questions
  354. end
  355. if @poll.save
  356. @poll = Poll.find(params[:to_id])
  357. respond_to do |format|
  358. format.js
  359. end
  360. end
  361. end
  362. #重新发布问卷
  363. def republish_poll
  364. @poll.poll_questions.each do |poll_question|
  365. poll_question.poll_votes.destroy_all
  366. end
  367. @poll.poll_users.destroy_all
  368. @poll.polls_status = 1
  369. @poll.save
  370. respond_to do |format|
  371. format.js
  372. end
  373. end
  374. #显示某个学生某份问卷的填写结果
  375. def poll_result
  376. @poll_questions = paginateHelper @poll.poll_questions,5
  377. @left_nav_type = 7
  378. respond_to do |format|
  379. format.html{render :layout => 'base_courses'}
  380. end
  381. end
  382. #关闭问卷
  383. def close_poll
  384. @poll.polls_status = 3
  385. @poll.closed_at = Time.now
  386. if @poll.save
  387. respond_to do |format|
  388. format.js
  389. end
  390. end
  391. end
  392. #导出问卷
  393. def export_poll
  394. poll_questions = @poll.poll_questions
  395. respond_to do |format|
  396. format.xls {
  397. send_data(poll_to_xls(poll_questions), :type => "text/excel;charset=utf-8; header=present",
  398. :filename => filename_for_content_disposition("#{@poll.polls_name}.xls") )
  399. }
  400. end
  401. end
  402. # 将其他地方的问卷导出来
  403. def other_poll
  404. # 查作者是我,或者作者是当前课程的老师,且不在当前课程内的问卷 进行导入
  405. courses = User.current.courses.select { |course| User.current.allowed_to?(:as_teacher,course)}
  406. course_ids = courses.empty? ? "(-1)" : "(" + courses.map { |course| course.id}.join(',') + ")"
  407. none_courses = User.current.courses.where("is_delete = 1 or #{Course.table_name}.id = #{params[:polls_group_id].to_i}")
  408. none_course_ids = none_courses.empty? ? "(-1)" : "(" + none_courses.map { |course| course.id}.join(',') + ")"
  409. #tea_ids = '('
  410. #tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')'
  411. @polls = Poll.where("(user_id = #{User.current.id} or polls_group_id in #{course_ids}) and polls_type = 'course' and polls_group_id not in #{none_course_ids}")
  412. @polls_group_id = params[:polls_group_id]
  413. respond_to do |format|
  414. format.js
  415. end
  416. end
  417. # 将问卷导入本课程
  418. def import_other_poll
  419. course_id = params[:course_id]
  420. @course = Course.find(course_id)
  421. params[:polls].each_with_index do |p,i|
  422. poll = Poll.find(p)
  423. option = {
  424. :polls_name => poll.polls_name || l(:label_poll_new),
  425. :polls_type => 'Course',
  426. :polls_group_id => course_id,
  427. :polls_status => 1,
  428. :user_id => User.current.id,
  429. :published_at => Time.now,
  430. :closed_at => Time.now,
  431. :show_result => 1,
  432. :polls_description => poll.polls_description
  433. }
  434. @poll = Poll.create option
  435. poll.poll_questions.each do | q|
  436. #question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
  437. option = {
  438. :is_necessary => q[:is_necessary],
  439. :question_title => q[:question_title],
  440. :question_type => q[:question_type] || 1,
  441. :question_number => q[:question_number]
  442. }
  443. @poll_questions = @poll.poll_questions.new option
  444. for i in 1..q.poll_answers.count
  445. answer = q.poll_answers[i-1].nil? ? l(:label_new_answer) : q.poll_answers[i-1][:answer_text]
  446. question_option = {
  447. :answer_position => i,
  448. :answer_text => answer
  449. }
  450. @poll_questions.poll_answers.new question_option
  451. end
  452. end
  453. @poll.save
  454. end
  455. @is_teacher = User.current.allowed_to?(:as_teacher,@course)
  456. if @is_teacher
  457. polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
  458. else
  459. polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
  460. end
  461. @polls = paginateHelper polls,20 #分页
  462. respond_to do |format|
  463. format.js
  464. end
  465. end
  466. private
  467. def find_poll_and_course
  468. @poll = Poll.find params[:id]
  469. @course = Course.find @poll.polls_group_id
  470. rescue Exception => e
  471. render_404
  472. end
  473. def find_container
  474. if params[:polls_type] && params[:polls_group_id]
  475. case params[:polls_type]
  476. when "Course"
  477. @course = Course.find_by_id params[:polls_group_id]
  478. when "Project"
  479. @project = Project.find_by_id params[:polls_group_id]
  480. end
  481. else
  482. render_404
  483. end
  484. end
  485. def is_logged
  486. redirect_to signin_path unless User.current.logged?
  487. end
  488. def is_member_of_course
  489. render_403 unless(@course && (User.current.member_of_course?(@course) || User.current.admin?))
  490. end
  491. def is_course_teacher
  492. @is_teacher = User.current.allowed_to?(:as_teacher,@course)
  493. render_403 unless(@course && @is_teacher)
  494. end
  495. #获取未完成的题目
  496. def get_uncomplete_question poll,user
  497. necessary_questions = poll.poll_questions.where("#{PollQuestion.table_name}.is_necessary = 1")
  498. uncomplete_question = []
  499. necessary_questions.each do |question|
  500. answers = get_user_answer(question,user)
  501. if answers.nil? || answers.count < 1
  502. uncomplete_question << question
  503. end
  504. end
  505. uncomplete_question
  506. end
  507. #获取用户对某个问题的答案
  508. def get_user_answer(question,user)
  509. user_answer = question.poll_votes.where("#{PollVote.table_name}.user_id = #{user.id}")
  510. user_answer
  511. end
  512. def get_complete_question(poll,user)
  513. questions = poll.poll_questions
  514. complete_question = []
  515. questions.each do |question|
  516. answers = get_user_answer(question,user)
  517. if !(answers.nil? || answers.count < 1)
  518. complete_question << question
  519. end
  520. end
  521. complete_question
  522. end
  523. def get_percent poll,user
  524. complete_count = get_complete_question(poll,user).count
  525. if poll.poll_questions.count == 0
  526. return 0
  527. else
  528. return (complete_count.to_f / poll.poll_questions.count.to_f)*100
  529. end
  530. end
  531. #PollUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个
  532. def get_poll_user poll_id,user_id
  533. pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
  534. if pu.nil?
  535. pu = PollUser.new
  536. end
  537. pu
  538. end
  539. #将poll中题目转换为Excel
  540. def poll_to_xls poll_questions
  541. xls_report = StringIO.new
  542. book = Spreadsheet::Workbook.new
  543. sheet1 = book.create_worksheet :name => "poll"
  544. blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
  545. count_row = 0
  546. poll_questions.each do |poll_question|
  547. if poll_question.question_type == 1 || poll_question.question_type == 2
  548. sheet1.row(count_row).default_format = blue
  549. sheet1[count_row,0]= l(:label_poll_question_num,:num => poll_question.question_number)
  550. sheet1[count_row + 1,0] = l(:label_poll_subtotal)
  551. sheet1[count_row + 2,0] = l(:label_poll_proportion)
  552. poll_question.poll_answers.each_with_index do |poll_answer,i|
  553. sheet1[count_row, i + 1] = poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/&nbsp;/," ")
  554. sheet1[count_row + 1, i + 1] = poll_answer.poll_votes.count
  555. sheet1[count_row + 2, i + 1] = statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)).to_s + "%"
  556. end
  557. sheet1[count_row + 3,0] = l(:label_poll_valid_commit)
  558. sheet1[count_row + 3,1] = total_answer(poll_question.id)
  559. count_row += 5
  560. else
  561. sheet1.row(count_row).default_format = blue
  562. sheet1[count_row,0] = l(:label_poll_question_num,:num => poll_question.question_number)
  563. sheet1[count_row,1] = poll_question.question_title
  564. count_row += 1
  565. poll_question.poll_votes.each do |poll_vote|
  566. sheet1[count_row,0] = poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/&nbsp;/," ")
  567. count_row += 1
  568. end
  569. count_row += 1
  570. end
  571. end
  572. sheet1.row(count_row).default_format = blue
  573. sheet1[count_row ,0] = l(:label_bidding_user_studentname)
  574. poll_questions.each_with_index do |poll_question, i|
  575. sheet1[count_row ,i + 1] = poll_question.question_title
  576. end
  577. count_row += 1
  578. @poll.users.each do |user|
  579. sheet1[count_row ,0] = user.show_name
  580. poll_questions.each_with_index do |poll_question, i|
  581. if poll_question.question_type == 1 || poll_question.question_type == 2
  582. sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/&nbsp;/," ") if poll_vote.poll_answer}.join(";")
  583. else
  584. sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/&nbsp;/," ")}.join(";")
  585. end
  586. end
  587. count_row += 1
  588. end
  589. book.write xls_report
  590. xls_report.string
  591. end
  592. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...