module Admin::PersonalBooksHelper def get_paper_list user = current_user.nil? ? OrbitHelper.current_user : current_user user_profile = user.member_profile books = Book.where(:member_profile_id => user_profile.id) books = books.collect do |b| files = b.book_files.collect do |bf| { "title" => bf.title, "description" => bf.description, "link" => bf.member_book_file.url, "extension" => (bf.file.url.split(".").last rescue "") } end { "id" => b.id.to_s, "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/books/#{b.to_param}/edit", "delete_url" => "/#{I18n.locale.to_s}/admin/books/#{b.id.to_s}", "paper_title" => b.book_title, "keywords" => b.keywords, "files" => files } end books end def import_this_book(row, mp) value = nil book = Book.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 book.book_title_translations = value when 4 value = {"en" => val} when 5 begin value["zh_tw"] = val rescue value = {"zh_tw" => val} end book.extracted_chapters_translations = value when 6 value = {"en" => val} when 7 begin value["zh_tw"] = val rescue value = {"zh_tw" => val} end book.publisher_translations = value when 8 value = {"en" => val} when 9 begin value["zh_tw"] = val rescue value = {"zh_tw" => val} end book.editor_translations = value when 10 value = {"en" => val} when 11 begin value["zh_tw"] = val rescue value = {"zh_tw" => val} end book.authors_translations = value when 12 book.year = val when 13 book.language = val when 14 bts = BookType.asc(:created_at).all.to_a book.book_type = bts[val.to_i] if val.to_s.is_i? && val.to_i < bts.count when 15 book.pages = val when 16 bats = BookAuthorType.asc(:created_at).all.to_a ts = val.to_s.split(",") ts.each do |t| book.book_author_type_ids << bats[t.to_i].id if t.to_s.is_i? && t.to_i < bats.count end when 17 book.number_of_authors = val when 18 book.publish_date = val when 19 book.isbn = val when 20 book.url = val when 21 book.keywords = val when 22 book.note = val end end book.member_profile = mp book.save end end