parent
ce9f375221
commit
cbd05be1ea
|
@ -1,4 +1,9 @@
|
|||
class PersonalBooksController < ApplicationController
|
||||
def search_all_words(target,word)
|
||||
target=target.upcase
|
||||
words=word.upcase.split(' ')
|
||||
return words.select{|value| target.include? value}==words
|
||||
end
|
||||
def index
|
||||
params = OrbitHelper.params
|
||||
books = Book.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
||||
|
@ -21,32 +26,29 @@ class PersonalBooksController < ApplicationController
|
|||
]
|
||||
end
|
||||
if params[:selectbox] !=nil
|
||||
books = Book.where(:is_hidden=>false)
|
||||
books_count = books.count
|
||||
books_temp = books.take(books_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
|
||||
books_temp = Book.where(:is_hidden=>false).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
|
||||
case params[:selectbox]
|
||||
when "book_title", "extracted_chapters", "default"
|
||||
if page.custom_string_field == "table"
|
||||
books_show = books_temp.select {|value| value.send(params[:selectbox]).include? params[:keywords]}
|
||||
books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]), params[:keywords])}
|
||||
else
|
||||
books_show = books_temp.select {|value| value.create_link.include? params[:keywords]}
|
||||
books_show = books_temp.select {|value| search_all_words(value.create_link, params[:keywords])}
|
||||
end
|
||||
when "publish_date", "publication_date"
|
||||
books_show = books_temp.select {|value| value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s.include? params[:keywords]}
|
||||
books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s, params[:keywords])}
|
||||
when "author_type"
|
||||
books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]}
|
||||
books_show = books_temp.select {|value| search_all_words(value.book_author_types.collect{|bat| bat.title}.join(", "), params[:keywords])}
|
||||
when "language"
|
||||
books_show = books_temp.select {|value| (!value.language.nil? ? t("#{value.language}") : "").include? params[:keywords]}
|
||||
books_show = books_temp.select {|value| search_all_words((!value.language.nil? ? t("#{value.language}") : ""), params[:keywords])}
|
||||
else
|
||||
books_show = books_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]}
|
||||
books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords])}
|
||||
end
|
||||
if params[:page_no].nil?
|
||||
page_to_show = 1
|
||||
else
|
||||
page_to_show = params[:page_no].to_i
|
||||
end
|
||||
books_show_last = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
|
||||
books = books_show_last
|
||||
books = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
|
||||
books_total_pages = (books_show.length/OrbitHelper.page_data_count.to_f).ceil
|
||||
else
|
||||
books_total_pages = books.total_pages
|
||||
|
|
Loading…
Reference in New Issue