Skip to content

Commit

Permalink
Bug 34519: Add a template plugin for fetch searchable patron attributes
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Katrin Fischer <[email protected]>
Signed-off-by: Tomas Cohen Arazi <[email protected]>
  • Loading branch information
kidclamp authored and tomascohen committed Nov 8, 2023
1 parent 1e56d49 commit 9d69ae9
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 26 deletions.
71 changes: 71 additions & 0 deletions Koha/Template/Plugin/ExtendedAttributeTypes.pm
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
=cut
4 changes: 0 additions & 4 deletions circ/request-article.pl
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@
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') ]
: []
),
);


Expand Down
4 changes: 3 additions & 1 deletion koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[% USE Koha %]
[% USE I18N %]
[% USE Branches %]
[% USE ExtendedAttributeTypes %]
[% USE raw %]
[% USE Asset %]
[% USE To %]
Expand Down Expand Up @@ -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 %]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %]

Expand Down
2 changes: 1 addition & 1 deletion koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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' %]
2 changes: 1 addition & 1 deletion koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 %]
Expand Down
2 changes: 1 addition & 1 deletion koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions members/member.pl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
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;
3 changes: 0 additions & 3 deletions members/members-home.pl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
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;
3 changes: 0 additions & 3 deletions members/search.pl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@
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 );
8 changes: 0 additions & 8 deletions reserve/request.pl
Original file line number Diff line number Diff line change
Expand Up @@ -704,14 +704,6 @@ =head1 request.pl
}
$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} );

Expand Down

0 comments on commit 9d69ae9

Please sign in to comment.