personal-conference/app/helpers/admin/personal_conferences_helper.rb

132 lines
3.6 KiB
Ruby
Raw Normal View History

2014-12-03 09:52:16 +00:00
module Admin::PersonalConferencesHelper
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile
conferences = WritingConference.where(:member_profile_id => user_profile.id)
conferences = conferences.collect do |c|
files = c.writing_conference_files.collect do |wcf|
{
"title" => wcf.title,
"description" => wcf.description,
"link" => wcf.file.url,
"extension" => (wcf.file.url.split(".").last rescue "")
}
end
{
"id" => c.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/writing_conferences/#{c.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/writing_conferences/#{c.id.to_s}",
"paper_title" => c.paper_title,
"conference_title" => c.conference_title,
"keywords" => c.keywords,
"abstract" => c.abstract,
"files" => files
}
end
conferences
end
2015-12-15 11:33:41 +00:00
def import_this_writing_conference(row, mp)
value = nil
conference = WritingConference.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
conference.paper_title_translations = value
when 4
value = {"en" => val}
when 5
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
conference.conference_title_translations = value
when 6
value = {"en" => val}
when 7
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
conference.location_translations = value
when 8
value = {"en" => val}
when 9
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
conference.sponsor_translations = value
when 10
value = {"en" => val}
when 11
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
conference.authors_translations = value
when 12
conference.year = val
when 13
conference.language = val
when 14
conference.period_start_date = val
when 15
conference.period_end_date = val
when 16
cpls = ConferencePaperLevel.asc(:created_at).all.to_a
ts = val.to_s.split(",")
ts.each do |t|
conference.conference_paper_level_ids << cpls[t.to_i].id if t.to_s.is_i? && t.to_i < cpls.count
end
when 17
cpls = ConferencePaperType.asc(:created_at).all.to_a
ts = val.to_s.split(",")
ts.each do |t|
conference.conference_paper_type_ids << cpls[t.to_i].id if t.to_s.is_i? && t.to_i < cpls.count
end
when 18
cpls = ConferenceAuthorType.asc(:created_at).all.to_a
ts = val.to_s.split(",")
ts.each do |t|
conference.conference_author_type_ids << cpls[t.to_i].id if t.to_s.is_i? && t.to_i < cpls.count
end
when 19
conference.number_of_authors = val
when 20
conference.isbn = val
when 21
conference.publication_date = val
when 22
conference.isi_number = val
when 23
conference.url = val
when 24
conference.keywords = val
when 25
conference.abstract = val
when 26
conference.note = val
end
end
conference.member_profile = mp
conference.save
end
2014-12-03 09:52:16 +00:00
end