module Admin::PersonalPatentsHelper def get_authors_text(patent) (patent.authors.to_s.blank? ? get_member(patent).collect(&:name).join('/') : Nokogiri::HTML(patent.authors.to_s).text rescue '') end def get_authors_show(patent) (patent.authors.to_s.blank? ? get_type_authors_show(patent) : patent.authors.to_s rescue '') end def get_type_authors_show(patent) get_member(patent).collect{|member| "#{member.name}"}.join('/') end def get_member(patent) Array(MemberProfile.find(Array(patent).collect(&:member_profile_id))) end def get_year(patent) patent.year end def get_patent_organization(patent) patent[:patent_organization].collect{|key,value| value.to_s.blank? ? t('personal_patent.no_input') : value}.join('/') rescue '' end def get_patent_category(patent) patent.patent_types.collect(&:title).join(', ') rescue '' end def get_patent_country(patent) patent[:patent_country].collect{|key,value| value.to_s.blank? ? t('personal_patent.no_input') : value}.join('/') rescue '' end def get_paper_list user = current_user.nil? ? OrbitHelper.current_user : current_user user_profile = user.member_profile patents = Patent.where(:member_profile_id => user_profile.id) patents = patents.collect do |p| files = p.patent_files.collect do |pf| { "title" => pf.title, "description" => pf.description, "link" => pf.file.url, "extension" => (pf.file.url.split(".").last rescue "") } end { "id" => p.id.to_s, "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/patents/#{p.to_param}/edit", "delete_url" => "/#{I18n.locale.to_s}/admin/patents/#{p.id.to_s}", "paper_title" => p.patent_title, "keywords" => p.keywords, "abstract" => [], "files" => files } end patents end def import_this_patent(row,mp) value = nil patent = Patent.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 patent.patent_title_translations = value when 4 value = {"en" => val} when 5 begin value["zh_tw"] = val rescue value = {"zh_tw" => val} end patent.patent_country_translations = value when 6 value = {"en" => val} when 7 begin value["zh_tw"] = val rescue value = {"zh_tw" => val} end patent.authors_translations = value when 8 patent.year = val when 9 patent.language = val when 10 pts = PatentType.asc(:created_at).all.to_a ts = val.to_s.split(",") ts.each do |t| patent.patent_type_ids << pts[t.to_i].id if t.to_s.is_i? && t.to_i < pts.count end when 11 patent.patent_no = val when 12 patent.publish_date = val when 13 patent.url = val when 14 patent.keywords = val when 15 patent.note = val end end patent.member_profile = mp patent.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"] = Patent.where(:year.gte => year_start.to_s, :year.lte => year_end.to_s, :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 "category" jls = PatentType.all when "author_type" jls = PatentAuthorType.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.patents.where(:year => year.to_s, :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 "category" t = Patent.where(:year => year.to_s, :member_profile_id.in => mps, :patent_type_ids => nil).count rescue 0 when "author_type" t = Patent.where(:year => year.to_s, :member_profile_id.in => mps, :patent_author_type_ids => nil).count rescue 0 end data["data"][year.to_s] = t end finaldata << data finaldata end end