Add "author like" as book search criterion.
This commit is contained in:
parent
e74686dd34
commit
3ef9852367
|
@ -13,6 +13,7 @@ sub books ($self) {
|
|||
my $book_page = $book_model->get_page(
|
||||
$page_number,
|
||||
$self->param('title_like'),
|
||||
$self->param('author_like'),
|
||||
);
|
||||
my $pager = $book_page->pager;
|
||||
if ($page_number > $pager->last_page) {
|
||||
|
|
|
@ -9,10 +9,12 @@ sub count_all ($self) {
|
|||
return $book_count;
|
||||
}
|
||||
|
||||
sub get_page ($self, $page_number = 1, $title_like = undef) {
|
||||
my $search_condition = (defined $title_like)
|
||||
? { "me.title" => { ilike => "\%$title_like\%" } }
|
||||
: undef;
|
||||
sub get_page ($self, $page_number = 1, $title_like = undef, $author_like = undef) {
|
||||
my $search_condition = {};
|
||||
$search_condition->{ "me.title" } = { ilike => "\%$title_like\%" }
|
||||
if (defined $title_like);
|
||||
$search_condition->{ "author.name" } = { ilike => "\%$author_like\%" }
|
||||
if (defined $author_like);
|
||||
my $rs = $self->schema->resultset('Book')->search_rs(
|
||||
$search_condition,
|
||||
{ prefetch => [ "author" ],
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
%= form_for books => { page_number => 1 } => begin
|
||||
%= label_for title_like => 'Title like'
|
||||
%= text_field title_like => flash('title_like')
|
||||
%= label_for author_like => 'Author like'
|
||||
%= text_field author_like => flash('author_like')
|
||||
%= submit_button "Search"
|
||||
%= end
|
||||
|
||||
|
|
Loading…
Reference in New Issue