parent
ce9f375221
commit
cbd05be1ea
|
@ -1,4 +1,9 @@
|
||||||
class PersonalBooksController < ApplicationController
|
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
|
def index
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
books = Book.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
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
|
end
|
||||||
if params[:selectbox] !=nil
|
if params[:selectbox] !=nil
|
||||||
books = Book.where(:is_hidden=>false)
|
books_temp = Book.where(:is_hidden=>false).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
|
||||||
books_count = books.count
|
|
||||||
books_temp = books.take(books_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
|
|
||||||
case params[:selectbox]
|
case params[:selectbox]
|
||||||
when "book_title", "extracted_chapters", "default"
|
when "book_title", "extracted_chapters", "default"
|
||||||
if page.custom_string_field == "table"
|
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
|
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
|
end
|
||||||
when "publish_date", "publication_date"
|
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"
|
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"
|
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
|
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
|
end
|
||||||
if params[:page_no].nil?
|
if params[:page_no].nil?
|
||||||
page_to_show = 1
|
page_to_show = 1
|
||||||
else
|
else
|
||||||
page_to_show = params[:page_no].to_i
|
page_to_show = params[:page_no].to_i
|
||||||
end
|
end
|
||||||
books_show_last = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
|
books = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
|
||||||
books = books_show_last
|
|
||||||
books_total_pages = (books_show.length/OrbitHelper.page_data_count.to_f).ceil
|
books_total_pages = (books_show.length/OrbitHelper.page_data_count.to_f).ceil
|
||||||
else
|
else
|
||||||
books_total_pages = books.total_pages
|
books_total_pages = books.total_pages
|
||||||
|
|
Loading…
Reference in New Issue