2014-06-04 03:55:13 +00:00
|
|
|
|
module Admin::JournalPapersHelper
|
2019-11-05 13:39:46 +00:00
|
|
|
|
def get_authors_text(journal)
|
|
|
|
|
(journal.authors.to_s.blank? ? get_member(journal).collect(&:name).join('/') : Nokogiri::HTML(journal.authors.to_s).text rescue "")
|
|
|
|
|
end
|
|
|
|
|
def get_authors_show(journal)
|
2020-12-19 13:54:30 +00:00
|
|
|
|
begin
|
|
|
|
|
if journal.authors.to_s.blank?
|
|
|
|
|
get_member_show(journal)
|
|
|
|
|
else
|
|
|
|
|
members = get_member(journal)
|
|
|
|
|
if members.blank?
|
|
|
|
|
journal.authors.to_s
|
|
|
|
|
else
|
|
|
|
|
authors = journal.authors.to_s.split(/,|,/).collect{|v| v.strip}
|
|
|
|
|
authors_tp = authors.clone
|
|
|
|
|
locales = Site.first.enable_locales rescue I18n.available_locales
|
|
|
|
|
members_tp = members.select do |member|
|
|
|
|
|
flag = true
|
|
|
|
|
locales.each do |locale|
|
|
|
|
|
name_tp = I18n.with_locale(locale) do
|
|
|
|
|
member.name.strip
|
|
|
|
|
end
|
|
|
|
|
author_index = authors.index(name_tp)
|
|
|
|
|
if !author_index.nil?
|
|
|
|
|
author = authors[author_index]
|
|
|
|
|
authors_tp[author_index] = "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{author}'>#{author}</a>"
|
|
|
|
|
flag = false
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
flag
|
|
|
|
|
end
|
|
|
|
|
(get_a_tag_from_members(members_tp) + authors_tp).join('、')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
""
|
|
|
|
|
end
|
2019-11-05 13:39:46 +00:00
|
|
|
|
end
|
|
|
|
|
def get_member(journal)
|
2020-03-04 02:21:42 +00:00
|
|
|
|
Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) rescue []
|
2019-11-05 13:39:46 +00:00
|
|
|
|
end
|
2020-12-19 13:54:30 +00:00
|
|
|
|
def get_a_tag_from_members(members)
|
|
|
|
|
members.collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}
|
|
|
|
|
end
|
2019-11-13 05:11:47 +00:00
|
|
|
|
def get_member_show(journal)
|
2020-12-19 13:54:30 +00:00
|
|
|
|
get_a_tag_from_members(get_member(journal)).join('、')
|
2019-11-13 05:11:47 +00:00
|
|
|
|
end
|
2019-11-05 13:39:46 +00:00
|
|
|
|
def get_level_type(journal)
|
|
|
|
|
!journal.journal_levels.blank? ? "(#{journal.journal_levels.collect(&:title).join(', ')})" : nil
|
|
|
|
|
end
|
|
|
|
|
def get_author_type(journal)
|
|
|
|
|
journal.journal_paper_author_types.collect(&:title).join(', ') rescue ''
|
|
|
|
|
end
|
|
|
|
|
def get_paper_type(journal)
|
|
|
|
|
journal.journal_paper_type.title rescue ''
|
|
|
|
|
end
|
|
|
|
|
def get_publication_date(journal)
|
|
|
|
|
journal.publication_date.strftime('%Y/%m/%d') rescue ''
|
|
|
|
|
end
|
2014-07-03 14:39:01 +00:00
|
|
|
|
def page_for_journal_paper(journal_paper_object)
|
2014-06-25 06:20:22 +00:00
|
|
|
|
journal_paper_page = nil
|
2014-07-03 14:39:01 +00:00
|
|
|
|
pages = Page.where(:module=>"journal_paper")
|
2014-06-25 06:20:22 +00:00
|
|
|
|
|
|
|
|
|
journal_paper_page = pages.first if journal_paper_page.nil?
|
2014-07-03 14:39:01 +00:00
|
|
|
|
request.protocol+(request.host_with_port+journal_paper_page.url+'/'+journal_paper_object.to_param).gsub('//','/') rescue "/"
|
2014-06-25 06:20:22 +00:00
|
|
|
|
end
|
2014-11-26 11:39:19 +00:00
|
|
|
|
def get_paper_list
|
2015-01-09 07:30:13 +00:00
|
|
|
|
user = current_user.nil? ? OrbitHelper.current_user : current_user
|
|
|
|
|
user_profile = user.member_profile
|
|
|
|
|
journals = JournalPaper.where(:member_profile_id => user_profile.id)
|
|
|
|
|
journals = journals.collect do |j|
|
|
|
|
|
files = j.journal_paper_files.collect do |jpf|
|
2014-11-26 11:39:19 +00:00
|
|
|
|
{
|
2015-01-09 07:30:13 +00:00
|
|
|
|
"title" => jpf.title,
|
|
|
|
|
"description" => jpf.description,
|
|
|
|
|
"link" => jpf.journal_file.url,
|
|
|
|
|
"extension" => (jpf.journal_file.url.split(".").last rescue "")
|
2014-11-26 11:39:19 +00:00
|
|
|
|
}
|
|
|
|
|
end
|
2015-01-09 07:30:13 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"id" => j.id.to_s,
|
|
|
|
|
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/journal_papers/#{j.to_param}/edit",
|
|
|
|
|
"delete_url" => "/#{I18n.locale.to_s}/admin/journal_papers/#{j.id.to_s}",
|
|
|
|
|
"paper_title" => j.paper_title,
|
|
|
|
|
"journal_title" => j.journal_title,
|
|
|
|
|
"keywords" => j.keywords,
|
|
|
|
|
"abstract" => j.abstract,
|
|
|
|
|
"files" => files
|
|
|
|
|
}
|
2014-11-26 11:39:19 +00:00
|
|
|
|
end
|
2015-01-09 07:30:13 +00:00
|
|
|
|
journals
|
|
|
|
|
end
|
2015-12-11 11:06:33 +00:00
|
|
|
|
def import_this_journal_paper(row,mp)
|
|
|
|
|
value = nil
|
|
|
|
|
jp = JournalPaper.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
|
2020-01-20 02:25:26 +00:00
|
|
|
|
value["zh_tw"] = val
|
|
|
|
|
rescue
|
2015-12-11 11:06:33 +00:00
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
|
end
|
|
|
|
|
jp.paper_title_translations = value
|
|
|
|
|
when 4
|
|
|
|
|
value = {"en" => val}
|
|
|
|
|
when 5
|
|
|
|
|
begin
|
|
|
|
|
value["zh_tw"] = val
|
2020-01-20 02:25:26 +00:00
|
|
|
|
rescue
|
2015-12-11 11:06:33 +00:00
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
|
end
|
|
|
|
|
jp.journal_title_translations = value
|
|
|
|
|
when 6
|
|
|
|
|
value = {"en" => val}
|
|
|
|
|
when 7
|
|
|
|
|
begin
|
|
|
|
|
value["zh_tw"] = val
|
2020-01-20 02:25:26 +00:00
|
|
|
|
rescue
|
2015-12-11 11:06:33 +00:00
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
|
end
|
|
|
|
|
jp.authors_translations = value
|
|
|
|
|
when 8
|
|
|
|
|
jp.year = val
|
|
|
|
|
when 9
|
|
|
|
|
jp.language = val
|
|
|
|
|
when 10
|
|
|
|
|
jp.vol_no = val
|
2020-01-20 02:25:26 +00:00
|
|
|
|
when 11
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.issue_no = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 12
|
|
|
|
|
jp.form_to_start = val
|
|
|
|
|
when 13
|
|
|
|
|
jp.form_to_end = val
|
|
|
|
|
when 14
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.total_pages = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 15
|
2015-12-11 11:36:41 +00:00
|
|
|
|
jls = JournalLevel.asc(:created_at).all.to_a
|
2015-12-11 11:06:33 +00:00
|
|
|
|
ts = val.to_s.split(",")
|
2020-01-20 02:25:26 +00:00
|
|
|
|
ts.each do |t|
|
2015-12-14 07:17:28 +00:00
|
|
|
|
jp.journal_level_ids << jls[t.to_i].id if t.to_s.is_i? && t.to_i < jls.count
|
2015-12-11 11:06:33 +00:00
|
|
|
|
end
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 16
|
2015-12-11 11:36:41 +00:00
|
|
|
|
jpts = JournalPaperType.asc(:created_at).all.to_a
|
2016-01-11 12:35:44 +00:00
|
|
|
|
jp.journal_paper_type = jpts[val.to_i] if val.to_s.is_i? && val.to_i < jpts.count
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 17
|
2015-12-11 11:36:41 +00:00
|
|
|
|
jpas = JournalPaperAuthorType.asc(:created_at).all.to_a
|
2015-12-11 11:06:33 +00:00
|
|
|
|
ts = val.to_s.split(",")
|
|
|
|
|
ts.each do |t|
|
2015-12-14 07:17:28 +00:00
|
|
|
|
jp.journal_paper_author_type_ids << jpas[t.to_i].id if t.to_s.is_i? && t.to_i < jpas.count
|
2015-12-11 11:06:33 +00:00
|
|
|
|
end
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 18
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.number_of_authors = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 19
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.isbn = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 20
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.publication_date = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 21
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.url = val
|
2020-01-20 02:25:26 +00:00
|
|
|
|
when 22
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.keywords = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 23
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.abstract = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 24
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.note = val
|
2020-01-20 02:22:42 +00:00
|
|
|
|
when 25
|
2015-12-11 11:06:33 +00:00
|
|
|
|
jp.associated_project_translations = {"en" => val, "zh_tw" => val}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
jp.member_profile = mp
|
|
|
|
|
jp.save
|
|
|
|
|
end
|
2016-06-01 08:04:19 +00:00
|
|
|
|
|
2016-06-01 11:39:51 +00:00
|
|
|
|
def get_data_for_excel(year_start,year_end)
|
|
|
|
|
data = []
|
2016-06-02 06:50:10 +00:00
|
|
|
|
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
|
2016-06-01 11:39:51 +00:00
|
|
|
|
roles.each do |role|
|
|
|
|
|
d = {}
|
|
|
|
|
d["name"] = role.title
|
|
|
|
|
mps = role.member_profile_ids
|
|
|
|
|
d1 = DateTime.new(year_start,1,1,0,0)
|
2020-01-20 02:25:26 +00:00
|
|
|
|
d2 = DateTime.new(year_end,12,31,23,59)
|
2016-06-01 11:39:51 +00:00
|
|
|
|
d["data"] = JournalPaper.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps) rescue []
|
|
|
|
|
data << d
|
|
|
|
|
end
|
|
|
|
|
return data
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-01 08:04:19 +00:00
|
|
|
|
def get_chart_data(year_start,year_end,role,type)
|
|
|
|
|
case type
|
|
|
|
|
when "paper_type"
|
|
|
|
|
jls = JournalPaperType.all
|
|
|
|
|
when "level_type"
|
|
|
|
|
jls = JournalLevel.all
|
|
|
|
|
when "author_type"
|
|
|
|
|
jls = JournalPaperAuthorType.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|
|
2016-06-01 08:19:34 +00:00
|
|
|
|
d1 = DateTime.new(year,1,1,0,0)
|
2020-01-20 02:25:26 +00:00
|
|
|
|
d2 = DateTime.new(year,12,31,23,59)
|
2016-06-01 08:19:34 +00:00
|
|
|
|
t = jl.journal_papers.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps).count rescue 0
|
2016-06-01 08:04:19 +00:00
|
|
|
|
data["data"][year.to_s] = t
|
|
|
|
|
end
|
|
|
|
|
finaldata << data
|
|
|
|
|
end
|
|
|
|
|
data = {"name" => "N/A", "data" => {}}
|
|
|
|
|
(year_start..year_end).each do |year|
|
2016-06-01 08:19:34 +00:00
|
|
|
|
d1 = DateTime.new(year,1,1,0,0)
|
|
|
|
|
d2 = DateTime.new(year,12,31,23,59)
|
2016-06-01 08:04:19 +00:00
|
|
|
|
case type
|
|
|
|
|
when "paper_type"
|
2016-06-01 08:19:34 +00:00
|
|
|
|
t = JournalPaper.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps, :journal_paper_type_id => nil).count rescue 0
|
2016-06-01 08:04:19 +00:00
|
|
|
|
when "level_type"
|
2016-06-01 08:19:34 +00:00
|
|
|
|
t = JournalPaper.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps, :journal_level_ids => nil).count rescue 0
|
2016-06-01 08:04:19 +00:00
|
|
|
|
when "author_type"
|
2016-06-01 08:19:34 +00:00
|
|
|
|
t = JournalPaper.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps, :journal_paper_author_type_ids => nil).count rescue 0
|
2016-06-01 08:04:19 +00:00
|
|
|
|
end
|
2020-01-20 02:25:26 +00:00
|
|
|
|
|
2016-06-01 08:04:19 +00:00
|
|
|
|
data["data"][year.to_s] = t
|
|
|
|
|
end
|
|
|
|
|
finaldata << data
|
|
|
|
|
finaldata
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-04 03:55:13 +00:00
|
|
|
|
end
|
2015-12-11 11:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|