2015-01-15 09:41:19 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
module PollHelper
|
2015-01-15 11:54:30 +08:00
|
|
|
#判断选项是否被选中
|
|
|
|
def answer_be_selected?(answer,user)
|
|
|
|
pv = answer.poll_votes.where("#{PollVote.table_name}.user_id = #{user.id} ")
|
|
|
|
if !pv.nil? && pv.count > 0
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
2015-01-15 09:41:19 +08:00
|
|
|
end
|
|
|
|
end
|
2015-01-16 15:49:22 +08:00
|
|
|
|
2015-01-15 17:36:30 +08:00
|
|
|
#获取文本题答案
|
2016-10-13 10:17:09 +08:00
|
|
|
def get_anwser_vote_text(question_id,user_id,answer_id=0)
|
|
|
|
if answer_id != 0
|
|
|
|
pv = PollVote.find_by_poll_question_id_and_poll_answer_id_and_user_id(question_id,answer_id,user_id)
|
|
|
|
else
|
|
|
|
pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id)
|
|
|
|
end
|
|
|
|
if pv.blank?
|
2015-01-15 17:36:30 +08:00
|
|
|
''
|
|
|
|
else
|
2016-10-13 10:17:09 +08:00
|
|
|
pv.vote_text.nil? ? '' : pv.vote_text
|
2015-01-15 17:36:30 +08:00
|
|
|
end
|
|
|
|
end
|
2015-08-29 11:17:46 +08:00
|
|
|
|
|
|
|
#判断用户是否已经提交了问卷
|
|
|
|
def has_commit_poll?(poll_id,user_id)
|
|
|
|
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
|
|
|
|
if pu.nil?
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-17 10:14:07 +08:00
|
|
|
#统计答题百分比,统计结果保留两位小数
|
2015-01-16 15:49:22 +08:00
|
|
|
def statistics_result_percentage(e, t)
|
2015-01-16 16:48:20 +08:00
|
|
|
e = e.to_f
|
|
|
|
t = t.to_f
|
|
|
|
t == 0 ? 0 : format("%.2f", e*100/t)
|
2015-01-16 15:49:22 +08:00
|
|
|
end
|
|
|
|
|
2015-01-17 14:54:19 +08:00
|
|
|
#多选的时候查询去重
|
|
|
|
def total_answer id
|
|
|
|
total = PollVote.find_by_sql("SELECT distinct(user_id) FROM `poll_votes` where poll_question_id = #{id}").count
|
|
|
|
end
|
|
|
|
|
2015-01-17 10:14:07 +08:00
|
|
|
#页面体型显示
|
|
|
|
def options_show pq
|
|
|
|
case pq
|
2015-01-16 15:49:22 +08:00
|
|
|
when 1
|
2015-01-27 10:14:05 +08:00
|
|
|
l(:label_MC)
|
2015-01-16 15:49:22 +08:00
|
|
|
when 2
|
2015-01-27 10:14:05 +08:00
|
|
|
l(:label_MCQ)
|
2015-01-17 11:46:34 +08:00
|
|
|
when 3
|
2015-01-27 10:14:05 +08:00
|
|
|
l(:label_single)
|
2015-01-16 15:49:22 +08:00
|
|
|
else
|
2015-01-27 10:14:05 +08:00
|
|
|
l(:label_mulit)
|
2015-01-16 15:49:22 +08:00
|
|
|
end
|
|
|
|
end
|
2015-01-21 17:51:12 +08:00
|
|
|
|
2015-08-10 09:12:26 +08:00
|
|
|
#带勾选框的问卷列表
|
|
|
|
def poll_check_box_tags(name,polls,current_poll)
|
|
|
|
s = ''
|
|
|
|
polls.each do |poll|
|
2015-08-11 11:30:17 +08:00
|
|
|
s << "<label>#{ check_box_tag name, poll.id, false, :id => nil } #{h poll.polls_name.blank? ? l(:label_poll_new) : poll.polls_name } [#{ h Course.find(poll.polls_group_id).name}]</label><br/>"
|
2015-08-10 09:12:26 +08:00
|
|
|
end
|
|
|
|
s.html_safe
|
|
|
|
end
|
|
|
|
|
2016-10-28 15:42:45 +08:00
|
|
|
#问卷的多选题上下限
|
|
|
|
def min_or_max_choices_option pq
|
|
|
|
type = []
|
|
|
|
count = pq.poll_answers.count
|
|
|
|
option = []
|
|
|
|
option << '不限'
|
|
|
|
option << 0
|
|
|
|
type << option
|
|
|
|
for i in 1 .. count do
|
|
|
|
option = []
|
|
|
|
option << i
|
|
|
|
option << i
|
|
|
|
type << option
|
|
|
|
end
|
|
|
|
type
|
|
|
|
end
|
|
|
|
|
2015-01-15 09:41:19 +08:00
|
|
|
end
|