personal-honor/app/helpers/admin/personal_honors_helper.rb

119 lines
3.2 KiB
Ruby
Raw Permalink Normal View History

2014-12-04 09:55:01 +00:00
module Admin::PersonalHonorsHelper
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile
honors = Honor.where(:member_profile_id => user_profile.id)
honors = honors.collect do |h|
{
"id" => h.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/honors/#{h.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/honors/#{h.id.to_s}",
"paper_title" => h.award_name,
"keywords" => h.keywords,
"files" => []
}
end
honors
end
2015-12-14 07:18:27 +00:00
def import_this_honor(row,mp)
value = nil
honor = Honor.new
row.cells.each_with_index do |cell,index|
next if index < 2
next if cell.nil?
val = cell.value
next if val.nil? || val == ""
case index
when 2
value = {"en" => val}
when 3
2015-12-14 08:12:52 +00:00
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
2015-12-14 07:18:27 +00:00
honor.award_name_translations = value
when 4
value = {"en" => val}
when 5
2015-12-14 08:12:52 +00:00
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
2015-12-14 07:18:27 +00:00
honor.awarding_unit_translations = value
when 6
honor.year = val
when 7
honor.language = val
when 8
hts = HonorType.asc(:created_at).all.to_a
honor.honor_type = hts[val.to_i] if val.to_s.is_i? && val.to_i < hts.count
when 9
honor.url = val
when 10
honor.keywords = val
when 11
honor.note = val
end
end
honor.member_profile = mp
honor.save
end
2016-06-06 09:15:12 +00:00
def get_data_for_excel(year_start,year_end)
data = []
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
roles.each do |role|
d = {}
d["name"] = role.title
mps = role.member_profile_ids
# d1 = DateTime.new(year_start,1,1,0,0)
# d2 = DateTime.new(year_end,12,31,23,59)
d["data"] = Honor.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
data << d
end
return data
end
def get_chart_data(year_start,year_end,role,type)
case type
when "category"
jls = HonorType.all
end
finaldata = []
role = Role.find(role) rescue nil
mps = []
if !role.nil?
mps = role.member_profile_ids
end
jls.each do |jl|
data = {}
data["name"] = jl.title
data["data"] = {}
(year_start..year_end).each do |year|
# d1 = DateTime.new(year,1,1,0,0)
# d2 = DateTime.new(year,12,31,23,59)
t = jl.honors.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0
data["data"][year.to_s] = t
end
finaldata << data
end
data = {"name" => "N/A", "data" => {}}
(year_start..year_end).each do |year|
# d1 = DateTime.new(year,1,1,0,0)
# d2 = DateTime.new(year,12,31,23,59)
case type
when "category"
t = Honor.where(:year => year, :member_profile_id.in => mps, :honor_type_id => nil).count rescue 0
end
data["data"][year.to_s] = t
end
finaldata << data
finaldata
end
2014-12-04 09:55:01 +00:00
end