2014-10-06 05:55:25 +00:00
|
|
|
module Admin::SurveysHelper
|
2016-12-09 11:42:26 +00:00
|
|
|
require 'iconv' unless String.method_defined?(:encode)
|
2014-10-06 05:55:25 +00:00
|
|
|
def page_for_survey(survey=nil)
|
|
|
|
ann_page = nil
|
|
|
|
pages = Page.where(:module=>'survey')
|
|
|
|
|
|
|
|
# pages.each do |page|
|
|
|
|
# if page.categories.count ==1
|
|
|
|
# if page.categories.include?(bulletin.category.id.to_s)
|
|
|
|
# ann_page = page
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# break if !ann_page.nil?
|
|
|
|
# end
|
|
|
|
|
|
|
|
# if ann_page.nil?
|
|
|
|
# pages.each do |page|
|
|
|
|
# if page.categories.include?(bulletin.category.id.to_s)
|
|
|
|
# ann_page = page
|
|
|
|
# end
|
|
|
|
# break if !ann_page.nil?
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
ann_page = pages.first if ann_page.nil?
|
|
|
|
if !survey.blank?
|
|
|
|
request.protocol+(request.host_with_port+ann_page.url+'/'+survey.to_param).gsub('//','/') rescue "/"
|
|
|
|
else
|
|
|
|
request.protocol+(request.host_with_port+'/'+I18n.locale.to_s+ann_page.url+'/').gsub('//','/') rescue "/"
|
|
|
|
end
|
|
|
|
end
|
2016-12-09 11:42:26 +00:00
|
|
|
|
|
|
|
def remove_illegal_utf8(str)
|
|
|
|
if String.method_defined?(:encode)
|
|
|
|
str.encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
|
|
|
else
|
|
|
|
ic = Iconv.new('UTF-8', 'UTF-8//IGNORE')
|
|
|
|
str = ic.iconv(str)
|
|
|
|
end
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
2014-10-06 05:55:25 +00:00
|
|
|
end
|