socialforge/app/helpers/poll_helper.rb

86 lines
2.4 KiB
Ruby
Raw Normal View History

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
#获取文本题答案
def get_anwser_vote_text(question_id,user_id)
pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id)
if pv.nil?
''
else
pv.vote_text
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)
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
#带勾选框的问卷列表
def poll_check_box_tags(name,polls,current_poll)
s = ''
polls.each do |poll|
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/>"
end
s.html_safe
end
2015-01-15 09:41:19 +08:00
end