academic_advising/app/helpers/admin/personal_honors_helper.rb

65 lines
1.6 KiB
Ruby
Raw 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
2014-12-04 09:55:01 +00:00
end