View | Details | Raw Unified | Return to bug 32730
Collapse All | Expand All

(-)a/Koha/Patron.pm (+23 lines)
Lines 1475-1480 sub get_enrollable_clubs { Link Here
1475
    return Koha::Clubs->get_enrollable($params);
1475
    return Koha::Clubs->get_enrollable($params);
1476
}
1476
}
1477
1477
1478
1479
=head3 get_lists_with_patron
1480
1481
my @lists = $patron->get_lists_with_patron;
1482
1483
=cut
1484
1485
sub get_lists_with_patron {
1486
    my ( $self ) = @_;
1487
    my $borrowernumber = $self->borrowernumber;
1488
1489
    return Koha::Database->new()->schema()->resultset('PatronList')->search(
1490
        {
1491
            'patron_list_patrons.borrowernumber' => $borrowernumber,
1492
        },
1493
        {
1494
            join => 'patron_list_patrons',
1495
            collapse => 1,
1496
            order_by => 'name',
1497
        }
1498
    );
1499
}
1500
1478
=head3 account_locked
1501
=head3 account_locked
1479
1502
1480
my $is_locked = $patron->account_locked
1503
my $is_locked = $patron->account_locked
(-)a/circ/circulation.pl (-1 / +6 lines)
Lines 620-626 if ( C4::Context->preference("ExportCircHistory") ) { Link Here
620
    $template->param(csv_profiles => Koha::CsvProfiles->search({ type => 'marc' }));
620
    $template->param(csv_profiles => Koha::CsvProfiles->search({ type => 'marc' }));
621
}
621
}
622
622
623
my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
623
my ( $has_modifications, $patron_lists_count);
624
if ( $patron ) {
625
    $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
626
    $patron_lists_count = $patron->get_lists_with_patron->count();
627
}
624
$template->param(
628
$template->param(
625
    debt_confirmed            => $debt_confirmed,
629
    debt_confirmed            => $debt_confirmed,
626
    SpecifyDueDate            => $duedatespec_allow,
630
    SpecifyDueDate            => $duedatespec_allow,
Lines 628-633 $template->param( Link Here
628
    today_due_date_and_time   => dt_from_string()->set(hour => 23)->set(minute => 59),
632
    today_due_date_and_time   => dt_from_string()->set(hour => 23)->set(minute => 59),
629
    restriction_types         => scalar Koha::Patron::Restriction::Types->search(),
633
    restriction_types         => scalar Koha::Patron::Restriction::Types->search(),
630
    has_modifications         => $has_modifications,
634
    has_modifications         => $has_modifications,
635
    patron_lists_count        => $patron_lists_count,
631
    override_high_holds       => $override_high_holds,
636
    override_high_holds       => $override_high_holds,
632
    nopermission              => scalar $query->param('nopermission'),
637
    nopermission              => scalar $query->param('nopermission'),
633
    autoswitched              => $autoswitched,
638
    autoswitched              => $autoswitched,
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc (+12 lines)
Lines 77-82 Link Here
77
                <span>Clubs ([% enrollments.count | html %]/[% enrollable.count | html %])</span>
77
                <span>Clubs ([% enrollments.count | html %]/[% enrollable.count | html %])</span>
78
            [% END %]
78
            [% END %]
79
        [% END %]
79
        [% END %]
80
81
        [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %]
82
            [% WRAPPER tab_item tabname="pat_lists" %]
83
                <span>Patron lists ([% patron_lists_count | html %])</span>
84
            [% END %]
85
        [% END %]
80
    [% END # /WRAPPER tabs_nav %]
86
    [% END # /WRAPPER tabs_nav %]
81
87
82
88
Lines 130-135 Link Here
130
            [% END # /tab_panel# %]
136
            [% END # /tab_panel# %]
131
        [% END %]
137
        [% END %]
132
138
139
        [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %]
140
            [% WRAPPER tab_panel tabname="pat_lists" %]
141
                Loading...
142
            [% END # /tab_panel# %]
143
        [% END %]
144
133
        [% WRAPPER tab_panel tabname="reldebarments" %]
145
        [% WRAPPER tab_panel tabname="reldebarments" %]
134
            [% INCLUDE 'patron-restrictions-tab.inc' %]
146
            [% INCLUDE 'patron-restrictions-tab.inc' %]
135
        [% END # /tab_panel# %]
147
        [% END # /tab_panel# %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt (+136 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
3
[% IF no_access_to_patron %]
4
   <span class="blocker">Patron not in your library group</span>
5
[% END %]
6
7
[% IF in_lists %]
8
<div class="patroninfo-section">
9
    <h4>Patron lists with this patron</h4>
10
11
    <table id="table_inlists">
12
        <thead>
13
            <tr>
14
                <th>Name</th>
15
                <th>Patrons in list</th>
16
                <th>Shared</th>
17
                [% IF CAN_user_tools_manage_patron_lists %]
18
                    <th class="NoSort">Actions</th>
19
                [% END %]
20
            </tr>
21
        </thead>
22
23
        <tbody>
24
            [% FOREACH l IN in_lists %]
25
                [% SET shared_by_other = l.owner.id != logged_in_user.id %]
26
                <tr>
27
                    <td>
28
                        [% IF CAN_user_tools_manage_patron_lists %]
29
                            <a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id | uri %]">[% l.name | html %]</a>
30
                        [% ELSE %]
31
                            [% l.name | html %]
32
                        [% END %]
33
                    </td>
34
                    <td>[% l.patron_list_patrons_rs.count || 0 | html %]</td>
35
                    <td>
36
                        [% IF l.shared %]
37
                            [% IF shared_by_other %]
38
                                by <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% l.owner.id | uri %]">[% INCLUDE 'patron-title.inc' patron=l.owner %]</a>
39
                            [% ELSE %]
40
                                by you
41
                            [% END %]
42
                        [% END %]
43
                    </td>
44
                    [% IF CAN_user_tools_manage_patron_lists %]
45
                        <td>
46
                            <div class="btn-group dropup">
47
                                <a class="btn btn-default btn-xs dropdown-toggle" id="listactions[% l.patron_list_id | html %]" role="button" data-toggle="dropdown" href="#">
48
                                    Actions <b class="caret"></b>
49
                                </a>
50
                                <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="listactions[% l.patron_list_id | html %]">
51
                                    <li><a onclick="removeFromList('[% l.patron_list_id | html %]','[% list_id_lookup.${l.patron_list_id} | html %]')"><i class="fa fa-remove"></i> Remove patron from list</a></li>
52
                                    <li class="divider"></li>
53
                                    <li><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id | uri %]"><i class="fa fa-user"></i> Add patrons</a></li>
54
                                    [% UNLESS shared_by_other %]
55
                                        <li><a href="/cgi-bin/koha/patron_lists/add-modify.pl?patron_list_id=[% l.patron_list_id | uri %]"><i class="fa fa-pencil"></i> Edit list</a></li>
56
                                        <li><a class="delete_patron" href="/cgi-bin/koha/patron_lists/delete.pl?patron_list_id=[% l.patron_list_id | html %]" data-list-name="[% l.name | html %]"><i class="fa fa-trash"></i> Delete list</a></li>
57
                                    [% END %]
58
                                    [% IF ( l.patron_list_patrons_rs.count ) %]
59
                                        <li class="divider"></li>
60
                                        <li>
61
                                            <a class="print_cards" href="/cgi-bin/koha/patroncards/print.pl?patronlist_id=[% l.patron_list_id | html %]" data-patron_list_id="[% l.patron_list_id | html %]"><i class="fa fa-print"></i> Print patron cards</a>
62
                                        </li>
63
                                        [% IF CAN_user_tools_edit_patrons %]
64
                                            <li>
65
                                                <a href="/cgi-bin/koha/tools/modborrowers.pl?patron_list_id=[% l.patron_list_id | uri %]&op=show">
66
                                                    <i class="fa fa-pencil"></i> Batch edit patrons
67
                                                </a>
68
                                            </li>
69
                                        [% END %]
70
                                        [% IF CAN_user_tools_delete_anonymize_patrons %]
71
                                            <li>
72
                                                <a href="/cgi-bin/koha/tools/cleanborrowers.pl?step=2&patron_list_id=[% l.patron_list_id | uri %]&checkbox=borrower">
73
                                                    <i class="fa fa-trash"></i> Batch delete patrons
74
                                                </a>
75
                                            </li>
76
                                        [% END %]
77
                                    [% END %]
78
                                </ul>
79
                            </div>
80
                        </td>
81
                    [% END %]
82
                </tr>
83
            [% END %]
84
        </tbody>
85
    </table>
86
</div>
87
88
[% IF available_lists %]
89
<hr>
90
[% END %]
91
[% END %]
92
93
[% IF available_lists && CAN_user_tools_manage_patron_lists %]
94
<div class="h4">
95
    <span>Add patron to list</span>
96
    <select name="patron_list_id" id="add_to_patron_list_id_select">
97
        <option value=""></option>
98
    [%- FOREACH l IN available_lists %]
99
        <option value="[% l.patron_list_id | html %]">[% l.name | html %]</option>
100
    [%- END %]
101
    </select>
102
    <a onclick="addToList()"><i class="fa fa-plus"></i>
103
</div>
104
[% END %]
105
106
<script>
107
    $("#table_listnopatron, #table_inlists").dataTable($.extend(true, {}, dataTablesDefaults, {
108
        "columnDefs": [
109
            { 'sortable': false, "bSearchable": false, 'targets': [ 'NoSort' ] }
110
        ],
111
        "sPaginationType": "full"
112
    }));
113
114
    [% IF CAN_user_tools_manage_patron_lists %]
115
        function addToList() {
116
            var list_id = $("#add_to_patron_list_id_select").val();
117
            $('#pat_lists_panel').text(_("Loading..."));
118
            $("body").css("cursor", "progress");
119
            $('#pat_lists_panel').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=[% borrowernumber | html %]&patron_list_id=' + list_id + '&patrons_to_add=[% cardnumber | html %]', function() {
120
                $("body").css("cursor", "default");
121
            });
122
123
            return false;
124
        }
125
126
        function removeFromList( list_id, patron_list_patron_id ) {
127
            $('#pat_lists_panel').text(_("Loading..."));
128
            $("body").css("cursor", "progress");
129
            $('#pat_lists_panel').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=[% borrowernumber | html %]&patron_list_id=' + list_id + '&patrons_to_remove=' + patron_list_patron_id, function() {
130
                $("body").css("cursor", "default");
131
            });
132
133
            return false;
134
        }
135
    [% END %]
136
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/circulation.js (+7 lines)
Lines 103-108 $(document).ready(function() { Link Here
103
            $('#clubs_panel').load('/cgi-bin/koha/clubs/patron-clubs-tab.pl?borrowernumber=' + borrowernumber );
103
            $('#clubs_panel').load('/cgi-bin/koha/clubs/patron-clubs-tab.pl?borrowernumber=' + borrowernumber );
104
        });
104
        });
105
    }
105
    }
106
107
    if ( $('#pat_lists_panel').length ) {
108
        $('#pat_lists-tab').on('click', function() {
109
            $('#pat_lists_panel').text(_("Loading..."));
110
            $('#pat_lists_panel').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=' + borrowernumber );
111
        });
112
    }
106
});
113
});
107
114
108
function export_checkouts(format) {
115
function export_checkouts(format) {
(-)a/members/moremember.pl (+2 lines)
Lines 283-288 elsif ( $patron->is_going_to_expire ) { Link Here
283
283
284
284
285
my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
285
my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
286
my $patron_lists_count = $patron->get_lists_with_patron->count();
286
287
287
$template->param(
288
$template->param(
288
    patron          => $patron,
289
    patron          => $patron,
Lines 299-304 $template->param( Link Here
299
    logged_in_user => $logged_in_user,
300
    logged_in_user => $logged_in_user,
300
    files => Koha::Patron::Files->new( borrowernumber => $borrowernumber ) ->GetFilesInfo(),
301
    files => Koha::Patron::Files->new( borrowernumber => $borrowernumber ) ->GetFilesInfo(),
301
    has_modifications         => $has_modifications,
302
    has_modifications         => $has_modifications,
303
    patron_lists_count => $patron_lists_count,
302
);
304
);
303
305
304
if ( C4::Context->preference('UseRecalls') ) {
306
if ( C4::Context->preference('UseRecalls') ) {
(-)a/patron_lists/patron-lists-tab.pl (+91 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2023 Washington County School District
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI;
23
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output qw( output_html_with_http_headers );
26
27
use Koha::Patrons;
28
use Koha::List::Patron qw( GetPatronLists AddPatronsToList DelPatronsFromList );
29
30
my $cgi = CGI->new;
31
32
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
33
    {
34
        template_name   => "patron_lists/patron-lists-tab.tt",
35
        query           => $cgi,
36
        type            => "intranet",
37
        flagsrequired   => [ { circulate => 'circulate_remaining_permissions' }, { borrowers => '*' }, { tools => 'manage_patron_lists' } ],
38
    }
39
);
40
41
my $logged_in_user = Koha::Patrons->find( { borrowernumber =>  $loggedinuser } );
42
my $patronnumber = $cgi->param('borrowernumber');
43
my $patron = Koha::Patrons->find($patronnumber);
44
my ( @in_lists, %list_id_lookup, @available_lists );
45
46
my $list_id = $cgi->param('patron_list_id');
47
my @patrons_to_add = $cgi->multi_param('patrons_to_add');
48
my @patrons_to_remove = $cgi->multi_param('patrons_to_remove');
49
50
if ( ! $logged_in_user->can_see_patron_infos($patron) ) {
51
    $template->param('no_access_to_patron' => 1);
52
}
53
else {
54
    my $has_perms = C4::Auth::haspermission($logged_in_user->userid, {'tools'=>'manage_patron_lists'});
55
    if ( $list_id && $has_perms ) {
56
        my ($list) = GetPatronLists( { patron_list_id => $list_id } );
57
58
        if (@patrons_to_add) {
59
            AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } );
60
        }
61
62
        if (@patrons_to_remove) {
63
            DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } );
64
        }
65
    }
66
67
    if ( $patron ) {
68
        @in_lists = $patron->get_lists_with_patron;
69
        foreach my $list ( @in_lists ) {
70
            my @existing = $list->patron_list_patrons;
71
            for my $plp ( @existing ) {
72
                if ( $plp->borrowernumber->borrowernumber == $patronnumber ) {
73
                    $list_id_lookup{$list->patron_list_id} = $plp->patron_list_patron_id;
74
                    last;
75
                }
76
            }
77
        }
78
    }
79
    @available_lists = GetPatronLists();
80
    @available_lists = grep { ! $list_id_lookup{$_->patron_list_id} } @available_lists;
81
}
82
83
$template->param(
84
    in_lists => \@in_lists,
85
    list_id_lookup => \%list_id_lookup,
86
    available_lists => \@available_lists,
87
    borrowernumber => $patronnumber,
88
    cardnumber => $patron->cardnumber,
89
);
90
91
output_html_with_http_headers( $cgi, $cookie, $template->output );
(-)a/t/db_dependent/PatronLists.t (-2 / +7 lines)
Lines 17-29 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 11;
20
use Test::More tests => 12;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
use t::lib::Mocks;
22
use t::lib::Mocks;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::List::Patron
25
use Koha::List::Patron
26
    qw( AddPatronList AddPatronsToList DelPatronList DelPatronsFromList GetPatronLists ModPatronList );
26
    qw( AddPatronList AddPatronsToList DelPatronList DelPatronsFromList GetPatronLists ModPatronList );
27
use Koha::Patrons;
27
28
28
my $schema = Koha::Database->schema;
29
my $schema = Koha::Database->schema;
29
$schema->storage->txn_begin;
30
$schema->storage->txn_begin;
Lines 98-103 DelPatronsFromList( Link Here
98
$list1->discard_changes();
99
$list1->discard_changes();
99
is( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' );
100
is( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' );
100
101
102
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
103
AddPatronsToList({list => $list2,borrowernumbers => [ $patron->borrowernumber ]});
104
@lists = $patron->get_lists_with_patron;
105
is( scalar @lists, 1, 'get_lists_with_patron works' );
106
101
@lists = GetPatronLists( { owner => $owner } );
107
@lists = GetPatronLists( { owner => $owner } );
102
is( scalar @lists, $list_count_original + 2, 'GetPatronLists works' );
108
is( scalar @lists, $list_count_original + 2, 'GetPatronLists works' );
103
109
104
- 

Return to bug 32730