forked from saurabh/personal-honor
65 lines
1.6 KiB
Ruby
65 lines
1.6 KiB
Ruby
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
|
|
|
|
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
|
|
begin
|
|
value["zh_tw"] = val
|
|
rescue
|
|
value = {"zh_tw" => val}
|
|
end
|
|
honor.award_name_translations = value
|
|
when 4
|
|
value = {"en" => val}
|
|
when 5
|
|
begin
|
|
value["zh_tw"] = val
|
|
rescue
|
|
value = {"zh_tw" => val}
|
|
end
|
|
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
|
|
end |