From 67ac38882203d0b045286431644b933e03a74092 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 6 Dec 2021 19:34:09 +1300 Subject: [PATCH] Bug 17748: (follow-up) Fix sorting on new columns MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Confirm tests in t/db_dependent/Items.t still pass. Signed-off-by: Christian Stelzenmüller Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers --- C4/Items.pm | 16 ++++++++++++---- .../prog/en/modules/catalogue/itemsearch.tt | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 5f68c914fd..15f735edb5 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1451,6 +1451,7 @@ sub SearchItems { LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber + LEFT JOIN issues ON issues.itemnumber = items.itemnumber WHERE 1 }; if (defined $where_str and $where_str ne '') { @@ -1463,10 +1464,17 @@ sub SearchItems { my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns; push @columns, Koha::Database->new()->schema()->resultset('Biblio')->result_source->columns; push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns; - my $sortby = (0 < grep {$params->{sortby} eq $_} @columns) - ? $params->{sortby} : 'itemnumber'; - my $sortorder = (uc($params->{sortorder}) eq 'ASC') ? 'ASC' : 'DESC'; - $query .= qq{ ORDER BY $sortby $sortorder }; + push @columns, Koha::Database->new()->schema()->resultset('Issue')->result_source->columns; + + if ( $params->{sortby} eq 'availability' ) { + my $sortorder = (uc($params->{sortorder}) eq 'ASC') ? 'ASC' : 'DESC'; + $query .= qq{ ORDER BY onloan $sortorder, damaged $sortorder, withdrawn $sortorder, notforloan $sortorder, itemlost $sortorder }; + } else { + my $sortby = (0 < grep {$params->{sortby} eq $_} @columns) + ? $params->{sortby} : 'itemnumber'; + my $sortorder = (uc($params->{sortorder}) eq 'ASC') ? 'ASC' : 'DESC'; + $query .= qq{ ORDER BY $sortby $sortorder }; + } my $rows = $params->{rows}; my @limit_args; 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 c4aa698c85..42e94c5e0c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -337,7 +337,7 @@ + ' ' + _("Withdrawn status") + '' + ' ' + _("Checkouts") + '' + ' ' + _("Availability") + '' - + ' ' + _("Due date") + '' + + ' ' + _("Due date") + '' + ' ' + ' ' var table = '' @@ -495,7 +495,7 @@ { 'sName': 'withdrawn' }, { 'sName': 'issues' }, { 'sName': 'availability' }, - { 'sName': 'duedate' }, + { 'sName': 'date_due' }, { 'sName': 'actions', 'bSortable': false } ], "sPaginationType": "full_numbers", -- 2.39.5