From c9c5efe517983d1e0e4145825a78b1942061f120 Mon Sep 17 00:00:00 2001 From: Michael Hafen Date: Fri, 27 Jan 2023 11:14:32 -0700 Subject: [PATCH] Bug 32730: Add Patron Lists tab to patron details and circulation pages Content-Type: text/plain; charset="utf-8" Test Plan: 1. Apply patch 2. create a patron list if there aren't any 3. search for a patron 4. observe the Patron Lists tab showing the list that the patron is not in 5. try adding the patron to the list and removing them from the list to be sure the feature has full operation 6. click "Check Out" on the side bar menu to navigate to the circulation page for this patron 7. observe the Patron Lists tab, and verify it operates as it did on the patron details page Bug 32730: (follow-up) Minor corrections This patch corrects an instance of an incorrect capital letter ("Patron Lists" -> "Patron lists") and makes minor tweaks to indentation. Signed-off-by: Owen Leonard --- Koha/List/Patron.pm | 24 +++ circ/circulation.pl | 3 + .../prog/en/modules/circ/circulation.tt | 21 ++ .../prog/en/modules/members/moremember.tt | 21 ++ .../modules/patron_lists/patron-lists-tab.tt | 204 ++++++++++++++++++ members/moremember.pl | 3 + patron_lists/patron-lists-tab.pl | 91 ++++++++ 7 files changed, 367 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt create mode 100755 patron_lists/patron-lists-tab.pl diff --git a/Koha/List/Patron.pm b/Koha/List/Patron.pm index cb91275d85..c8ac51593e 100644 --- a/Koha/List/Patron.pm +++ b/Koha/List/Patron.pm @@ -42,6 +42,7 @@ BEGIN { AddPatronList ModPatronList + GetListsWithPatron AddPatronsToList DelPatronsFromList ); @@ -156,6 +157,29 @@ sub ModPatronList { return $list->update($params); } +=head2 GetListsWithPatron + + GetListsWithPatron({ borrowernumber => $borrowernumber }); + +=cut + +sub GetListsWithPatron { + my ($params) = @_; + + my $borrowernumber = $params->{'borrowernumber'}; + + return Koha::Database->new()->schema()->resultset('PatronList')->search( + { + 'patron_list_patrons.borrowernumber' => $borrowernumber, + }, + { + join => 'patron_list_patrons', + collapse => 1, + order_by => 'name', + } + ); +} + =head2 AddPatronsToList AddPatronsToList({ list => $list, cardnumbers => \@cardnumbers }); diff --git a/circ/circulation.pl b/circ/circulation.pl index 4bbc92b534..314c3586f2 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -54,6 +54,7 @@ use Koha::Items; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::Patron::Modifications; +use Koha::List::Patron qw( GetListsWithPatron ); use Koha::Token; use List::MoreUtils qw( uniq ); @@ -623,6 +624,7 @@ if ( C4::Context->preference("ExportCircHistory") ) { } my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count; +my $patron_lists_count = GetListsWithPatron({borrowernumber => $borrowernumber})->count(); $template->param( debt_confirmed => $debt_confirmed, SpecifyDueDate => $duedatespec_allow, @@ -631,6 +633,7 @@ $template->param( todaysdate => dt_from_string()->set(hour => 23)->set(minute => 59), restriction_types => scalar Koha::Patron::Restriction::Types->keyed_on_code(), has_modifications => $has_modifications, + patron_lists_count => $patron_lists_count, override_high_holds => $override_high_holds, nopermission => scalar $query->param('nopermission'), autoswitched => $autoswitched, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index c4c42aaea8..fc2e3dc50e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -893,6 +893,14 @@ [% END %] + + [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %] +
  • + + Patron Lists ([% patron_lists_count | html %]) + +
  • + [% END %]
    @@ -908,6 +916,12 @@
    [% END %] + [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %] +
    + Loading... +
    + [% END %] + [% INCLUDE borrower_debarments.inc %]
    @@ -1116,6 +1130,13 @@ }); } + if ( $('#pat_lists-tab').length ) { + $('#pat_lists-tab-link').on('click', function() { + $('#pat_lists-tab').text(_("Loading...")); + $('#pat_lists-tab').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=[% patron.borrowernumber | html %]'); + }); + } + // listen submit to trigger qslip on empty checkout $('#mainform').bind('submit',function() { if ($('#barcode').val() == '') { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index ef0a906c90..5f6b83cfbf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -725,6 +725,14 @@ [% END %] + + [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %] +
  • + + Patron Lists ([% patron_lists_count | html %]) + +
  • + [% END %]
    @@ -748,6 +756,12 @@
    [% END %] + [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %] +
    + Loading... +
    + [% END %] + [% INCLUDE borrower_debarments.inc %] [% IF ( CAN_user_circulate_circulate_remaining_permissions ) %] @@ -902,6 +916,13 @@ }); } + if ( $('#pat_lists-tab').length ) { + $('#pat_lists-tab-link').on('click', function() { + $('#pat_lists-tab').text(_("Loading...")); + $('#pat_lists-tab').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=[% patron.borrowernumber | html %]'); + }); + } + $("#finesholdsissues a[data-toggle='tab']").on("shown.bs.tab", function(e){ var oTable = $('div.dataTables_wrapper > table', $(e.target.hash) ).dataTable(); if ( oTable.length > 0 ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt new file mode 100644 index 0000000000..25176297e0 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt @@ -0,0 +1,204 @@ +[% USE KohaDates %] + +[% IF no_access_to_patron %] + Patron not in your library group +[% END %] + +[% IF in_lists %] +
    +

    Patron lists currently in

    + + + + + + + + [% IF CAN_user_tools_manage_patron_lists %] + + [% END %] + + + + + [% FOREACH l IN in_lists %] + [% SET shared_by_other = l.owner.id != logged_in_user.id %] + + + + + [% IF CAN_user_tools_manage_patron_lists %] + + [% END %] + + [% END %] + +
    NamePatrons in listSharedActions
    + [% IF CAN_user_tools_manage_patron_lists %] + [% l.name | html %] + [% ELSE %] + [% l.name | html %] + [% END %] + [% l.patron_list_patrons_rs.count || 0 | html %] + [% IF l.shared %] + [% IF shared_by_other %] + by [% INCLUDE 'patron-title.inc' patron=l.owner %] + [% ELSE %] + by you + [% END %] + [% END %] + +
    + + Actions + + +
    +
    +
    + +[% IF available_lists %] +
    +[% END %] +[% END %] + +[% IF available_lists %] +
    +

    Patron lists not in

    + + + + + + + + [% IF CAN_user_tools_manage_patron_lists %] + + [% END %] + + + + + [% FOREACH l IN available_lists %] + [% SET shared_by_other = l.owner.id != logged_in_user.id %] + + + + + [% IF CAN_user_tools_manage_patron_lists %] + + [% END %] + + [% END %] + +
    NamePatrons in listSharedActions
    + [% IF CAN_user_tools_manage_patron_lists %] + [% l.name | html %] + [% ELSE %] + [% l.name | html %] + [% END %] + [% l.patron_list_patrons_rs.count || 0 | html %] + [% IF l.shared %] + [% IF shared_by_other %] + by [% INCLUDE 'patron-title.inc' patron=l.owner %] + [% ELSE %] + by you + [% END %] + [% END %] + +
    + + Actions + + +
    +
    +
    +[% END %] + + diff --git a/members/moremember.pl b/members/moremember.pl index 0523d02831..fd566d8aba 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -43,6 +43,7 @@ use Koha::CsvProfiles; use Koha::Holds; use Koha::Patrons; use Koha::Patron::Files; +use Koha::List::Patron qw( GetListsWithPatron ); use Koha::Token; use Koha::Checkouts; @@ -266,6 +267,7 @@ elsif ( $patron->is_going_to_expire ) { my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count; +my $patron_lists_count = GetListsWithPatron({borrowernumber => $borrowernumber})->count(); $template->param( patron => $patron, @@ -283,6 +285,7 @@ $template->param( files => Koha::Patron::Files->new( borrowernumber => $borrowernumber ) ->GetFilesInfo(), #debarments => scalar GetDebarments({ borrowernumber => $borrowernumber }), has_modifications => $has_modifications, + patron_lists_count => $patron_lists_count, ); if ( C4::Context->preference('UseRecalls') ) { diff --git a/patron_lists/patron-lists-tab.pl b/patron_lists/patron-lists-tab.pl new file mode 100755 index 0000000000..f435b1e7fc --- /dev/null +++ b/patron_lists/patron-lists-tab.pl @@ -0,0 +1,91 @@ +#!/usr/bin/perl + +# Copyright 2013 ByWater Solutions +# +# 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 CGI; + +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); + +use Koha::Patrons; +use Koha::List::Patron qw( GetPatronLists GetListsWithPatron AddPatronsToList DelPatronsFromList ); + +my $cgi = CGI->new; + +my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( + { + template_name => "patron_lists/patron-lists-tab.tt", + query => $cgi, + type => "intranet", + flagsrequired => [ { circulate => 'circulate_remaining_permissions' }, { borrowers => '*' }, { tools => 'manage_patron_lists' } ], + } +); + +my $logged_in_user = Koha::Patrons->find( { borrowernumber => $loggedinuser } ); +my $patronnumber = $cgi->param('borrowernumber'); +my $patron = Koha::Patrons->find($patronnumber); +my ( @in_lists, %list_id_lookup, @available_lists ); + +my $list_id = $cgi->param('patron_list_id'); +my @patrons_to_add = $cgi->multi_param('patrons_to_add'); +my @patrons_to_remove = $cgi->multi_param('patrons_to_remove'); + +if ( ! $logged_in_user->can_see_patron_infos($patron) ) { + $template->param('no_access_to_patron' => 1); +} +else { + my $has_perms = C4::Auth::haspermission($logged_in_user->userid, {'tools'=>'manage_patron_lists'}); + if ( $list_id && $has_perms ) { + my ($list) = GetPatronLists( { patron_list_id => $list_id } ); + + if (@patrons_to_add) { + AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } ); + } + + if (@patrons_to_remove) { + DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } ); + } + } + + if ( $patron ) { + @in_lists = GetListsWithPatron({borrowernumber=>$patronnumber}); + foreach my $list ( @in_lists ) { + my @existing = $list->patron_list_patrons; + for my $plp ( @existing ) { + if ( $plp->borrowernumber->borrowernumber == $patronnumber ) { + $list_id_lookup{$list->patron_list_id} = $plp->patron_list_patron_id; + last; + } + } + } + } + @available_lists = GetPatronLists(); + @available_lists = grep { ! $list_id_lookup{$_->patron_list_id} } @available_lists; +} + +$template->param( + in_lists => \@in_lists, + list_id_lookup => \%list_id_lookup, + available_lists => \@available_lists, + borrowernumber => $patronnumber, + cardnumber => $patron->cardnumber, +); + +output_html_with_http_headers( $cgi, $cookie, $template->output ); -- 2.34.1