Fix authors show.

This commit is contained in:
BoHung Chiu 2021-12-16 10:21:24 +08:00
parent 3ecbccfe35
commit 3c474256a2
2 changed files with 28 additions and 6 deletions

View File

@ -1,12 +1,33 @@
module Admin::PersonalBooksHelper
def get_authors_text(book)
(book.authors.to_s.blank? ? get_member(book).collect(&:name).join('/') : Nokogiri::HTML(book.authors.to_s).text rescue '')
authors_text = Nokogiri::HTML(book.authors.to_s).text
split_text = authors_text.match(/[、,\/]/)
split_text = split_text.nil? ? '/' : split_text[0]
full_authors_names = get_member(book).collect(&:name)
if authors_text.present?
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(full_authors_names))}
full_authors_names += authors_names
end
full_authors_names.join(split_text)
end
def get_authors_show(book)
(book.authors.to_s.blank? ? get_member_show(book) : book.authors.to_s) rescue ''
authors_text = Nokogiri::HTML(book.authors.to_s).text
split_text = authors_text.match(/[、,\/]/)
split_text = split_text.nil? ? '/' : split_text[0]
full_authors_names = []
full_authors = get_member(book).collect{|member|
member_name = member.name
full_authors_names << member_name
"<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member_name}'>#{member_name}</a>"
}
if authors_text.present?
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(full_authors_names.strip()))}
full_authors += authors_names
end
full_authors.join(split_text)
end
def get_member(book)
Array(MemberProfile.find(Array(book).collect(&:member_profile_id)))
Array(MemberProfile.where(:id.in=>Array(book).collect(&:member_profile_id)))
end
def get_member_show(book)
get_member(book).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('/')

View File

@ -159,9 +159,10 @@ class Book
value = (self.book_author_types.collect{|type| type.title}.join(',') rescue "")
when "author_name"
value = []
name_translations = self.member_profile.name_translations rescue {}
([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale|
if self.member_profile.first_name_translations[locale] || self.member_profile.last_name_translations[locale]
value << "#{self.member_profile.first_name_translations[locale]} #{self.member_profile.last_name_translations[locale]}"
if name_translations[locale]
value << name_translations[locale]
end
end
value = value.join(" / ")
@ -180,7 +181,7 @@ class Book
when "url"
value = self.url.to_s.blank? ? "" : "<a href='#{self.url}'>#{self.url}</a>"
when "authors"
value = get_member_show(self) rescue "#"
value = get_authors_show(self) rescue ""
else
value = (self.send(field) rescue "")
end