From a8a06acfb1ecef7418321746b3696579d0281546 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 11 Aug 2023 14:16:12 +0000 Subject: [PATCH] Bug 34519: Add a template plugin for fetch searchable patron attributes This patch moves code form scripts to a template plguin and unifies the calls To test: 1 - Add a searchable patron attribute type 2 - Add values to several patrons and test patron searching from Patrons home Patrons search results Holds request screen Article request screen Patron search sidebar 3 - Apply patch 4 - Confirm results are the same Signed-off-by: Janusz Kaczmarek Signed-off-by: Katrin Fischer --- .../Template/Plugin/ExtendedAttributeTypes.pm | 71 +++++++++++++++++++ circ/request-article.pl | 4 -- .../prog/en/includes/patron-search.inc | 4 +- .../prog/en/modules/circ/request-article.tt | 2 +- .../prog/en/modules/members/member.tt | 2 +- .../prog/en/modules/members/search.tt | 2 +- .../prog/en/modules/reserve/request.tt | 2 +- members/member.pl | 3 - members/members-home.pl | 3 - members/search.pl | 3 - reserve/request.pl | 8 --- 11 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 Koha/Template/Plugin/ExtendedAttributeTypes.pm diff --git a/Koha/Template/Plugin/ExtendedAttributeTypes.pm b/Koha/Template/Plugin/ExtendedAttributeTypes.pm new file mode 100644 index 0000000000..991666d164 --- /dev/null +++ b/Koha/Template/Plugin/ExtendedAttributeTypes.pm @@ -0,0 +1,71 @@ +package Koha::Template::Plugin::ExtendedAttributeTypes; + +# Copyright ByWater Solutions 2023 + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Template::Plugin; +use base qw( Template::Plugin ); + +use C4::Koha; +use C4::Context; +use Koha::Patron::Attribute::Types; + +sub all { + my ( $self, $params ) = @_; + return Koha::Patron::Attribute::Types->search($params); +} + +sub codes { + my ( $self, $params ) = @_; + return Koha::Patron::Attribute::Types->search($params)->get_column('code'); +} + +1; + +=head1 NAME + +Koha::Template::Plugin::ExtendedAttributeTypes - TT Plugin for retrieving patron attribute types + +=head1 SYNOPSIS + +[% USE ExtendedAttributeTypes %] + +[% ExtendedAttributeTypes.all() %] + +=head1 ROUTINES + +=head2 all + +In a template, you can get the searchable attribute types with +the following TT code: [% ExtendedAttributes.all( staff_searchable => 1 ) %] + +The function returns the Koha::Patron::Atribute::Type objects + +=head2 codes + +In a template, you can get the searchable attribute type codes with +the following TT code: [% ExtendedAttributes.codes( staff_searchable => 1 ) %] + +The function returns the Koha::Patron::Atribute::Type codes as an array + +=head1 AUTHOR + +Nick Clemens + +=cut diff --git a/circ/request-article.pl b/circ/request-article.pl index a9724749dc..051d13f9d6 100755 --- a/circ/request-article.pl +++ b/circ/request-article.pl @@ -123,10 +123,6 @@ $template->param( patron => $patron, subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber), C4::Search::enabled_staff_search_views, - attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes') - ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ] - : [] - ), ); 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 580a80f6a8..f752b88fbd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -1,6 +1,7 @@ [% USE Koha %] [% USE I18N %] [% USE Branches %] +[% USE ExtendedAttributeTypes %] [% USE raw %] [% USE Asset %] [% USE To %] @@ -231,7 +232,8 @@ return map; }, {}); - [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %] + [% IF Koha.Preference('ExtendedPatronAttributes') %] + [% SET extended_attribute_types = ExtendedAttributeTypes.codes( staff_searchable => 1 ) %] let extended_attribute_types = [% To.json(extended_attribute_types || []) | $raw %]; [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt index 652dc0418a..18c32347fd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt @@ -441,7 +441,7 @@ }); - [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber %] + [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt index 6e6a3bd92a..1fb3da1b0e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt @@ -390,7 +390,7 @@ [% ELSE %] [% SET redirect_url = '/cgi-bin/koha/members/moremember.pl' %] [% END %] - [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns,actions => ['edit', 'checkout'], redirect_if_one_result => 1, redirect_url => redirect_url, sticky_header => "searchheader", sticky_to => "searchresults", default_sort_column => 'name-address', display_search_description => 1, remember_selections => 1 %] + [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, columns => columns,actions => ['edit', 'checkout'], redirect_if_one_result => 1, redirect_url => redirect_url, sticky_header => "searchheader", sticky_to => "searchresults", default_sort_column => 'name-address', display_search_description => 1, remember_selections => 1 %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt index 4d6efc7d51..01adca73c5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt @@ -77,7 +77,7 @@ }); - [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns, filter => filter, actions => [selection_type], preview_on_name_click => 1, callback => callback %] + [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, columns => columns, filter => filter, actions => [selection_type], preview_on_name_click => 1, callback => callback %] [% END %] [% SET popup_window = 1 %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index a1e63a4fdb..c29439bf01 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1741,7 +1741,7 @@ table_settings = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %]; - [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_attribute_equal => 'cardnumber' %] + [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_attribute_equal => 'cardnumber' %]