personal-research/app/helpers/admin/personal_researches_helper.rb

82 lines
2.0 KiB
Ruby

module Admin::PersonalResearchesHelper
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile
researchs = Research.where(:member_profile_id => user_profile.id)
researchs = researchs.collect do |r|
files = r.research_files.collect do |rf|
{
"title" => rf.title,
"description" => rf.description,
"link" => rf.file.url,
"extension" => (rf.file.url.split(".").last rescue "")
}
end
{
"id" => r.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/researchs/#{r.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/researchs/#{r.id.to_s}",
"paper_title" => r.research_title,
"keywords" => r.keywords,
"files" => files
}
end
researchs
end
def import_this_research(row,mp)
value = nil
research = Research.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
research.research_title_translations = value
when 4
value = {"en" => val}
when 5
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
research.extracted_chapters_translations = value
when 6
value = {"en" => val}
when 7
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
research.authors_translations = value
when 8
research.year = val
when 9
research.language = val
when 10
research.publish_date = val
when 11
research.url = val
when 12
research.keywords = val
when 13
research.note = val
end
end
research.member_profile = mp
research.save
end
end