From 8a874de3f42ef02d0eb9e7e8512f952da5a7152a Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 21 Jul 2020 11:43:55 +0200 Subject: [PATCH] Bug 26032: Add 'is new' filter in items search MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In items search, add a filter on value of items.new_status with a Ignore/Yes/No. Yes meaning != 0, No meaning = 0, with considering that NULL value is like 0. This patch adds 'isnull' option to filter, this may be reused on other fields. Test plan : 1) Define an item subfield on items.new_status with authorised values YES_NO (0 or 1) 2) Edit an item A to set new_status=1 3) Edit an item B to set new_status=0 4) Perform an item search with 'is new' = 'ignore' => you get all items 5) Perform an item search with 'is new' = 'yes' => you get item A 6) Perform an item search with 'is new' = 'no' => you get all items but A Signed-off-by: Emmi Takkinen Signed-off-by: Séverine QUEUNE Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/Items.pm | 9 +++++++++ catalogue/itemsearch.pl | 5 ++++- .../prog/en/modules/catalogue/itemsearch.tt | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/C4/Items.pm b/C4/Items.pm index b1e8de7029..55bae137f9 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1337,6 +1337,7 @@ sub _SearchItems_build_where_fragment { if ( (0 < grep { $_ eq $field } @columns) or (substr($field, 0, 5) eq 'marc:') ) { my $op = $filter->{operator}; my $query = $filter->{query}; + my $ifnull = $filter->{ifnull}; if (!$op or (0 == grep { $_ eq $op } @operators)) { $op = '='; # default operator @@ -1377,6 +1378,10 @@ sub _SearchItems_build_where_fragment { $column = $field; } + if ( defined $ifnull ) { + $column = "IFNULL($column, ?)"; + } + if (ref $query eq 'ARRAY') { if ($op eq '=') { $op = 'IN'; @@ -1393,6 +1398,10 @@ sub _SearchItems_build_where_fragment { args => [ $query ], }; } + + if ( defined $ifnull ) { + unshift @{ $where_fragment->{args} }, $ifnull; + } } } diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index 431786cb81..2ea32156ac 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -164,12 +164,15 @@ if (scalar keys %params > 0) { push @{ $filter->{filters} }, $f; # Yes/No parameters - foreach my $p (qw( damaged )) { + foreach my $p (qw( damaged new_status )) { my $v = $cgi->param($p) // ''; my $f = { field => $p, query => 0, }; + if ( $p eq 'new_status' ) { + $f->{ifnull} = 0; + } if ($v eq 'yes') { $f->{operator} = '!='; push @{ $filter->{filters} }, $f; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt index fe2639d2aa..06c1ed8723 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -29,6 +29,7 @@ [%- CASE 'damaged' %]Damaged [%- CASE 'itemlost' %]Lost [%- CASE 'withdrawn' %]Withdrawn + [%- CASE 'new_status' %]Is new [%- END -%] [%- END -%] @@ -194,6 +195,7 @@ (inclusive) [% INCLUDE form_field_radio_yes_no name="damaged" %] + [% INCLUDE form_field_radio_yes_no name="new_status" %]