From b929c980d538ce29737a1d5c6466c6d366f59996 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 7 Nov 2024 09:40:03 +0100 Subject: [PATCH] Bug 38130: Allow sorting and filtering on library id and name On the item list of the bib detail page and the patron search we want the library columns ('holding library', 'home library' and 'library') to be sorted by library names and to make them searchable on library id and name. Concerns about this approach (comment #8): """ If we do it for the library names on this view, we need to do it for all the library columns (thinking about patrons right now but I am sure there are others). And to be consistent, for all the other coded values: "special AVs" (item types, cn source), regular AVs, patron category codes, etc. We will introduce additional JOINs and so maybe performance problems. This needs to be investigated before we take this route IMO. """ --- Koha/Patron.pm | 2 +- Koha/Schema/Result/Borrower.pm | 7 +++++++ .../html_helpers/tables/items/catalogue_detail.inc | 4 ++-- .../intranet-tmpl/prog/en/includes/patron-search.inc | 9 ++++----- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index bc031f8bcf9..26ba7a24df2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -505,7 +505,7 @@ Returns a Koha::Library object representing the patron's home library. sub library { my ( $self ) = @_; - return Koha::Library->_new_from_dbic($self->_result->branchcode); + return Koha::Library->_new_from_dbic($self->_result->library); } =head3 sms_provider diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index bf8ba360308..fddaf77201c 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -2191,6 +2191,13 @@ __PACKAGE__->many_to_many("permissions", "user_permissions", "permission"); # Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-05-02 11:36:36 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jUOMoSonNmA3KwtZKVxqOA +__PACKAGE__->belongs_to( + "library", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" }, +); + __PACKAGE__->has_many( "restrictions", "Koha::Schema::Result::BorrowerDebarment", diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc index eb7ac8e0ea8..c115c12322a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc @@ -372,7 +372,7 @@ }, [% END %] { - data: "me.holding_library_id:holding_library.name", + data: "holding_library.name:me.holding_library_id", className: "location", searchable: true, orderable: true, @@ -381,7 +381,7 @@ } }, { - data: "me.home_library_id:home_library.name", + data: "home_library.name:me.home_library_id", className: "homebranch", searchable: true, orderable: true, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index d2eef529c7c..16fc58b7d1a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -575,15 +575,14 @@ } [% CASE 'branch' %] { - "data": "library_id", + "data": "library.name:me.library_id", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { - let library_name = libraries_map[data].branchname - if( !singleBranchMode && data == logged_in_library_id ) { - return "" + escape_str(library_name) + ""; + if( !singleBranchMode && row.library.library_id == logged_in_library_id ) { + return "" + escape_str(row.library.name) + ""; } else { - return escape_str(library_name); + return escape_str(row.library.name); } } } -- 2.34.1