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 <januszop@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-08-11 14:16:12 +00:00 committed by Tomas Cohen Arazi
parent 1e56d4953a
commit 9d69ae986a
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
11 changed files with 78 additions and 26 deletions

View file

@ -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 <http://www.gnu.org/licenses>.
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 <nick@bywatersolutions.com>
=cut

View file

@ -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') ]
: []
),
);

View file

@ -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 %]

View file

@ -441,7 +441,7 @@
});
</script>
[% 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 %]

View file

@ -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' %]

View file

@ -77,7 +77,7 @@
});
</script>
[% 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 %]

View file

@ -1741,7 +1741,7 @@
table_settings = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %];
</script>
[% 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' %]
<script>
$(document).ready(function() {
$("#holds_patronsearch").on("submit", filter);

View file

@ -81,9 +81,6 @@ $template->param(
PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
do_not_defer_loading => !$defer_loading,
circsearch => $circsearch,
attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes')
? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ]
: [] ),
);
output_html_with_http_headers $input, $cookie, $template->output;

View file

@ -73,9 +73,6 @@ $template->param(
PatronAutoComplete => C4::Context->preference('PatronAutoComplete'),
patron_lists => [ GetPatronLists() ],
PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes')
? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ]
: [] ),
);
output_html_with_http_headers $query, $cookie, $template->output;

View file

@ -46,8 +46,5 @@ $template->param(
columns => \@columns,
filter => $filter,
selection_type => $selection_type,
attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes')
? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ]
: [] ),
);
output_html_with_http_headers( $input, $cookie, $template->output );

View file

@ -704,14 +704,6 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
}
$template->param( biblionumbers => \@biblionumbers );
$template->param(
attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes')
? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ]
: []
),
);
# pass the userenv branch if no pickup location selected
$template->param( pickup => $pickup || C4::Context->userenv->{branch} );