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

193 lines
5.8 KiB
Ruby

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
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
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"] = WritingConference.where(:publication_date.gte => d1, :publication_date.lte => d2, :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 "paper_type"
jls = ConferencePaperType.all
when "level_type"
jls = ConferencePaperLevel.all
when "author_type"
jls = ConferenceAuthorType.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.writing_conferences.where(:publication_date.gte => d1, :publication_date.lte => d2, :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 "paper_type"
t = WritingConference.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps, :conference_paper_type_id => nil).count rescue 0
when "level_type"
t = WritingConference.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps, :conference_paper_level_ids => nil).count rescue 0
when "author_type"
t = WritingConference.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps, :conference_paper_author_type_ids => nil).count rescue 0
end
data["data"][year.to_s] = t
end
finaldata << data
finaldata
end
end