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

(-)a/Koha/List/Patron.pm (-27 / +133 lines)
Lines 36-64 BEGIN { Link Here
36
    require Exporter;
36
    require Exporter;
37
    @ISA    = qw(Exporter);
37
    @ISA    = qw(Exporter);
38
    @EXPORT_OK = qw(
38
    @EXPORT_OK = qw(
39
      GetPatronLists
39
      get_patron_list
40
      get_patron_lists
40
41
41
      DelPatronList
42
      del_patron_list
42
      AddPatronList
43
      add_patron_list
43
      ModPatronList
44
      mod_patron_list
44
45
45
      AddPatronsToList
46
      add_patrons_to_list
46
      DelPatronsFromList
47
      del_patrons_from_list
48
49
      grant_patrons_access_to_list
50
      revoke_patrons_access_from_list
47
    );
51
    );
48
}
52
}
49
53
50
=head2 GetPatronLists
54
=head2 get_patron_list
55
56
    my $list = get_patron_list( { patron_list_id => 2 } );
57
58
    Returns the patron list with patron_list_id.
59
=cut
60
61
sub get_patron_list {
62
    my ($params) = @_;
63
64
    unless ( $params->{'patron_list_id'} ) {
65
        carp("No list id passed in or defined!");
66
        return;
67
    }
68
69
    my $schema = Koha::Database->new()->schema();
70
71
    my $patron_list = $schema->resultset('PatronList')->find($params->{'patron_list_id'});
72
73
    return $patron_list;
74
}
75
76
=head2 get_patron_lists
51
77
52
    my @lists = GetPatronLists( $params );
78
    my @lists = get_patron_lists( $params );
53
79
54
    Returns an array of lists created by the the given user
80
    Returns an array of lists created by the the given user
55
    or the logged in user if none is passed in.
81
    or the logged in user if none is passed in.
56
=cut
82
=cut
57
83
58
sub GetPatronLists {
84
sub get_patron_lists {
59
    my ($params) = @_;
85
    my ($params) = @_;
60
86
61
    $params->{owner} ||= C4::Context->userenv->{'number'};
87
    $params->{owner} ||= C4::Context->userenv->{'number'};
88
    my $user_branch = C4::Context->userenv->{'branch'};
89
    my $search_attrs = {};
62
90
63
    unless ( $params->{owner} ) {
91
    unless ( $params->{owner} ) {
64
        carp("No owner passed in or defined!");
92
        carp("No owner passed in or defined!");
Lines 72-94 sub GetPatronLists { Link Here
72
        $params->{'-or'} = [
100
        $params->{'-or'} = [
73
            owner => $owner,
101
            owner => $owner,
74
            shared => 1,
102
            shared => 1,
103
            '-and' => [
104
                shared => 2,
105
                branchcode => $user_branch,
106
            ],
107
            '-and' => [
108
                shared => { 'IN' => [2,3] },
109
                'patron_list_users.borrowernumber' => $owner,
110
            ],
75
        ];
111
        ];
112
        $search_attrs = {
113
            join => [ 'owner', 'patron_list_users' ],
114
            group_by => 'patron_list_id',
115
        };
76
    }
116
    }
77
117
78
    my $schema = Koha::Database->new()->schema();
118
    my $schema = Koha::Database->new()->schema();
79
119
80
    my @patron_lists = $schema->resultset('PatronList')->search($params);
120
    my @patron_lists = $schema->resultset('PatronList')->search($params, $search_attrs);
81
121
82
    return wantarray() ? @patron_lists : \@patron_lists;
122
    return wantarray() ? @patron_lists : \@patron_lists;
83
}
123
}
84
124
85
=head2 DelPatronList
125
=head2 del_patron_list
86
126
87
    DelPatronList( { patron_list_id => $list_id [, owner => $owner ] } );
127
    del_patron_list( { patron_list_id => $list_id [, owner => $owner ] } );
88
128
89
=cut
129
=cut
90
130
91
sub DelPatronList {
131
sub del_patron_list {
92
    my ($params) = @_;
132
    my ($params) = @_;
93
133
94
    $params->{owner} ||= C4::Context->userenv->{'number'};
134
    $params->{owner} ||= C4::Context->userenv->{'number'};
Lines 107-119 sub DelPatronList { Link Here
107
      ->search($params)->single()->delete();
147
      ->search($params)->single()->delete();
108
}
148
}
109
149
110
=head2 AddPatronList
150
=head2 add_patron_list
111
151
112
    AddPatronList( { name => $name [, owner => $owner ] } );
152
    add_patron_list( { name => $name [, owner => $owner ] } );
113
153
114
=cut
154
=cut
115
155
116
sub AddPatronList {
156
sub add_patron_list {
117
    my ($params) = @_;
157
    my ($params) = @_;
118
158
119
    $params->{owner} ||= C4::Context->userenv->{'number'};
159
    $params->{owner} ||= C4::Context->userenv->{'number'};
Lines 132-144 sub AddPatronList { Link Here
132
      ->create($params);
172
      ->create($params);
133
}
173
}
134
174
135
=head2 ModPatronList
175
=head2 mod_patron_list
136
176
137
    ModPatronList( { patron_list_id => $id, name => $name [, owner => $owner ] } );
177
    mod_patron_list( { patron_list_id => $id, name => $name [, owner => $owner ] } );
138
178
139
=cut
179
=cut
140
180
141
sub ModPatronList {
181
sub mod_patron_list {
142
    my ($params) = @_;
182
    my ($params) = @_;
143
183
144
    unless ( $params->{patron_list_id} ) {
184
    unless ( $params->{patron_list_id} ) {
Lines 146-168 sub ModPatronList { Link Here
146
        return;
186
        return;
147
    }
187
    }
148
188
149
    my ($list) = GetPatronLists(
189
    my $list = get_patron_list(
150
        {
190
        {
151
            patron_list_id => $params->{patron_list_id},
191
            patron_list_id => $params->{patron_list_id},
152
            owner          => $params->{owner}
153
        }
192
        }
154
    );
193
    );
155
194
156
    return $list->update($params);
195
    return $list->update($params);
157
}
196
}
158
197
159
=head2 AddPatronsToList
198
=head2 add_patrons_to_list
160
199
161
    AddPatronsToList({ list => $list, cardnumbers => \@cardnumbers });
200
    add_patrons_to_list({ list => $list, cardnumbers => \@cardnumbers });
162
201
163
=cut
202
=cut
164
203
165
sub AddPatronsToList {
204
sub add_patrons_to_list {
166
    my ($params) = @_;
205
    my ($params) = @_;
167
206
168
    my $list            = $params->{list};
207
    my $list            = $params->{list};
Lines 204-216 sub AddPatronsToList { Link Here
204
    return wantarray() ? @results : \@results;
243
    return wantarray() ? @results : \@results;
205
}
244
}
206
245
207
=head2 DelPatronsFromList
246
=head2 del_patrons_from_list
208
247
209
    DelPatronsFromList({ list => $list, patron_list_patrons => \@patron_list_patron_ids });
248
    del_patrons_from_list({ list => $list, patron_list_patrons => \@patron_list_patron_ids });
210
249
211
=cut
250
=cut
212
251
213
sub DelPatronsFromList {
252
sub del_patrons_from_list {
214
    my ($params) = @_;
253
    my ($params) = @_;
215
254
216
    my $list                = $params->{list};
255
    my $list                = $params->{list};
Lines 223-228 sub DelPatronsFromList { Link Here
223
      ->delete();
262
      ->delete();
224
}
263
}
225
264
265
=head2 grant_patrons_access_to_list
266
267
    grant_patrons_access_to_list({ list => $list, cardnumbers => \@cardnumbers });
268
269
=cut
270
271
sub grant_patrons_access_to_list {
272
    my ($params) = @_;
273
274
    my $list            = $params->{list};
275
    my $cardnumbers     = $params->{'cardnumbers'};
276
    my $borrowernumbers = $params->{'borrowernumbers'};
277
278
    return unless ( $list && ( $cardnumbers || $borrowernumbers ) );
279
280
    my @borrowernumbers;
281
282
    my %search_param;
283
    if ($cardnumbers) {
284
        $search_param{cardnumber} = { 'IN' => $cardnumbers };
285
    } else {
286
        $search_param{borrowernumber} = { 'IN' => $borrowernumbers };
287
    }
288
289
    @borrowernumbers =
290
      Koha::Database->new()->schema()->resultset('Borrower')->search(
291
        \%search_param,
292
        { columns    => [qw/ borrowernumber /] }
293
      )->get_column('borrowernumber')->all();
294
295
    my $patron_list_id = $list->patron_list_id();
296
297
    my $plu_rs = Koha::Database->new()->schema()->resultset('PatronListUser');
298
299
    my @results;
300
    foreach my $borrowernumber (@borrowernumbers) {
301
        my $result = $plu_rs->update_or_create(
302
            {
303
                patron_list_id => $patron_list_id,
304
                borrowernumber => $borrowernumber
305
            }
306
        );
307
        push( @results, $result );
308
    }
309
310
    return wantarray() ? @results : \@results;
311
}
312
313
=head2 revoke_patrons_access_from_list
314
315
    revoke_patrons_access_from_list({ list => $list, patron_list_users => \@patron_list_user_ids });
316
317
=cut
318
319
sub revoke_patrons_access_from_list {
320
    my ($params) = @_;
321
322
    my $list              = $params->{list};
323
    my $patron_list_users = $params->{patron_list_users};
324
325
    return unless ( $list && $patron_list_users );
326
327
    return Koha::Database->new()->schema()->resultset('PatronListUser')
328
      ->search( { patron_list_user_id => { 'IN' => $patron_list_users } } )
329
      ->delete();
330
}
331
226
=head1 AUTHOR
332
=head1 AUTHOR
227
333
228
Kyle M Hall, E<lt>kyle@bywatersolutions.comE<gt>
334
Kyle M Hall, E<lt>kyle@bywatersolutions.comE<gt>
(-)a/Koha/Schema/Result/PatronList.pm (+152 lines)
Lines 23-28 __PACKAGE__->table("patron_lists"); Link Here
23
23
24
=head1 ACCESSORS
24
=head1 ACCESSORS
25
25
26
=head2 patron_list_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 name
33
34
  data_type: 'varchar'
35
  is_nullable: 0
36
  size: 255
37
38
=head2 owner
39
40
  data_type: 'integer'
41
  is_foreign_key: 1
42
  is_nullable: 0
43
44
=head2 shared
45
46
  data_type: 'tinyint'
47
  default_value: 0
48
  is_nullable: 1
49
50
=cut
51
52
__PACKAGE__->add_columns(
53
  "patron_list_id",
54
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
55
  "name",
56
  { data_type => "varchar", is_nullable => 0, size => 255 },
57
  "owner",
58
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
59
  "shared",
60
  { data_type => "tinyint", default_value => 0, is_nullable => 1 },
61
);
62
63
=head1 PRIMARY KEY
64
65
=over 4
66
67
=item * L</patron_list_id>
68
69
=back
70
71
=cut
72
73
__PACKAGE__->set_primary_key("patron_list_id");
74
75
=head1 RELATIONS
76
77
=head2 owner
78
79
Type: belongs_to
80
81
Related object: L<Koha::Schema::Result::Borrower>
82
83
=cut
84
85
__PACKAGE__->belongs_to(
86
  "owner",
87
  "Koha::Schema::Result::Borrower",
88
  { borrowernumber => "owner" },
89
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
90
);
91
92
=head2 patron_list_patrons
93
94
Type: has_many
95
96
Related object: L<Koha::Schema::Result::PatronListPatron>
97
98
=cut
99
100
__PACKAGE__->has_many(
101
  "patron_list_patrons",
102
  "Koha::Schema::Result::PatronListPatron",
103
  { "foreign.patron_list_id" => "self.patron_list_id" },
104
  { cascade_copy => 0, cascade_delete => 0 },
105
);
106
107
=head2 patron_list_users
108
109
Type: has_many
110
111
Related object: L<Koha::Schema::Result::PatronListUser>
112
113
=cut
114
115
__PACKAGE__->has_many(
116
  "patron_list_users",
117
  "Koha::Schema::Result::PatronListUser",
118
  { "foreign.patron_list_id" => "self.patron_list_id" },
119
  { cascade_copy => 0, cascade_delete => 0 },
120
);
121
122
123
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-02-28 16:35:34
124
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YepHXHQHtxjorkGhef0rmQ
125
# These lines were loaded from './Koha/Schema/Result/PatronList.pm' found in @INC.
126
# They are now part of the custom portion of this file
127
# for you to hand-edit.  If you do not either delete
128
# this section or remove that file from @INC, this section
129
# will be repeated redundantly when you re-create this
130
# file again via Loader!  See skip_load_external to disable
131
# this feature.
132
133
use utf8;
134
package Koha::Schema::Result::PatronList;
135
136
# Created by DBIx::Class::Schema::Loader
137
# DO NOT MODIFY THE FIRST PART OF THIS FILE
138
139
=head1 NAME
140
141
Koha::Schema::Result::PatronList
142
143
=cut
144
145
use strict;
146
use warnings;
147
148
use base 'DBIx::Class::Core';
149
150
=head1 TABLE: C<patron_lists>
151
152
=cut
153
154
__PACKAGE__->table("patron_lists");
155
156
=head1 ACCESSORS
157
26
=head2 patron_list_id
158
=head2 patron_list_id
27
159
28
  data_type: 'integer'
160
  data_type: 'integer'
Lines 114-119 __PACKAGE__->has_many( Link Here
114
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
246
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
115
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+gAlf5GQ7YSgAtFIXgqVWw
247
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+gAlf5GQ7YSgAtFIXgqVWw
116
248
249
=head2 patron_list_patrons
250
251
Type: has_many
252
253
Related object: L<Koha::Schema::Result::PatronListPatron>
254
255
=cut
256
257
__PACKAGE__->has_many(
258
  "patron_list_users",
259
  "Koha::Schema::Result::PatronListUser",
260
  { "foreign.patron_list_id" => "self.patron_list_id" },
261
  { cascade_copy => 0, cascade_delete => 0 },
262
);
263
117
264
118
# You can replace this text with custom content, and it will be preserved on regeneration
265
# You can replace this text with custom content, and it will be preserved on regeneration
119
1;
266
1;
267
# End of lines loaded from './Koha/Schema/Result/PatronList.pm'
268
269
270
# You can replace this text with custom code or comments, and it will be preserved on regeneration
271
1;
(-)a/Koha/Schema/Result/PatronListUser.pm (+113 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::PatronListUser;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::PatronListUser
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<patron_list_users>
19
20
=cut
21
22
__PACKAGE__->table("patron_list_users");
23
24
=head1 ACCESSORS
25
26
=head2 patron_list_user_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 patron_list_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 borrowernumber
39
40
  data_type: 'integer'
41
  is_foreign_key: 1
42
  is_nullable: 0
43
44
=head2 can_edit
45
46
  data_type: 'tinyint'
47
  default_value: 0
48
  is_nullable: 1
49
50
=cut
51
52
__PACKAGE__->add_columns(
53
  "patron_list_user_id",
54
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
55
  "patron_list_id",
56
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
57
  "borrowernumber",
58
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
59
  "can_edit",
60
  { data_type => "tinyint", default_value => 0, is_nullable => 1 },
61
);
62
63
=head1 PRIMARY KEY
64
65
=over 4
66
67
=item * L</patron_list_user_id>
68
69
=back
70
71
=cut
72
73
__PACKAGE__->set_primary_key("patron_list_user_id");
74
75
=head1 RELATIONS
76
77
=head2 borrowernumber
78
79
Type: belongs_to
80
81
Related object: L<Koha::Schema::Result::Borrower>
82
83
=cut
84
85
__PACKAGE__->belongs_to(
86
  "borrowernumber",
87
  "Koha::Schema::Result::Borrower",
88
  { borrowernumber => "borrowernumber" },
89
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
90
);
91
92
=head2 patron_list
93
94
Type: belongs_to
95
96
Related object: L<Koha::Schema::Result::PatronList>
97
98
=cut
99
100
__PACKAGE__->belongs_to(
101
  "patron_list",
102
  "Koha::Schema::Result::PatronList",
103
  { patron_list_id => "patron_list_id" },
104
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
105
);
106
107
108
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-02-28 16:35:34
109
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3K+501CuiCeq6Jk7W6TE2w
110
111
112
# You can replace this text with custom code or comments, and it will be preserved on regeneration
113
1;
(-)a/installer/data/mysql/atomicupdate/bug_32105-add_patron_list_users_table.pl (+27 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "32105",
5
    description => "Add patron list users table",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        unless ( TableExists('patron_list_users') ) {
10
            $dbh->do(q{CREATE TABLE `patron_list_users` (
11
  `patron_list_user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
12
  `patron_list_id` int(11) NOT NULL COMMENT 'the list this entry is part of',
13
  `borrowernumber` int(11) NOT NULL COMMENT 'the borrower that is given access to this list',
14
  `can_edit` tinyint(1) NOT NULL DEFAULt 0 COMMENT 'whether this borrower can edit the list and it''s patrons',
15
  PRIMARY KEY (`patron_list_user_id`),
16
  KEY `patron_list_id` (`patron_list_id`),
17
  KEY `borrowernumber` (`borrowernumber`),
18
  CONSTRAINT `patron_list_users_ibfk_1` FOREIGN KEY (`patron_list_id`) REFERENCES `patron_lists` (`patron_list_id`) ON DELETE CASCADE ON UPDATE CASCADE,
19
  CONSTRAINT `patron_list_users_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
20
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci});
21
            say $out "Added new table 'patron_list_users'";
22
23
            $dbh->do(q{ALTER TABLE patron_lists MODIFY shared tinyint DEFAULT 0 COMMENT '1 for everyone, 2 for library and individuals, 3 for individuals'});
24
            say $out "Add additional share modes to patron_lists table comment";
25
        }
26
    },
27
};
(-)a/installer/data/mysql/kohastructure.sql (-1 / +21 lines)
Lines 5003-5008 CREATE TABLE `patron_list_patrons` ( Link Here
5003
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5003
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5004
/*!40101 SET character_set_client = @saved_cs_client */;
5004
/*!40101 SET character_set_client = @saved_cs_client */;
5005
5005
5006
--
5007
-- Table structure for table `patron_list_users`
5008
--
5009
5010
DROP TABLE IF EXISTS `patron_list_users`;
5011
/*!40101 SET @saved_cs_client     = @@character_set_client */;
5012
/*!40101 SET character_set_client = utf8 */;
5013
CREATE TABLE `patron_list_users` (
5014
  `patron_list_user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
5015
  `patron_list_id` int(11) NOT NULL COMMENT 'the list this entry is part of',
5016
  `borrowernumber` int(11) NOT NULL COMMENT 'the borrower that is given access to this list',
5017
  `can_edit` tinyint(1) NOT NULL DEFAULt 0 COMMENT 'whether this borrower can edit the list and it''s patrons',
5018
  PRIMARY KEY (`patron_list_user_id`),
5019
  KEY `patron_list_id` (`patron_list_id`),
5020
  KEY `borrowernumber` (`borrowernumber`),
5021
  CONSTRAINT `patron_list_users_ibfk_1` FOREIGN KEY (`patron_list_id`) REFERENCES `patron_lists` (`patron_list_id`) ON DELETE CASCADE ON UPDATE CASCADE,
5022
  CONSTRAINT `patron_list_users_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
5023
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5024
/*!40101 SET character_set_client = @saved_cs_client */;
5025
5006
--
5026
--
5007
-- Table structure for table `patron_lists`
5027
-- Table structure for table `patron_lists`
5008
--
5028
--
Lines 5014-5020 CREATE TABLE `patron_lists` ( Link Here
5014
  `patron_list_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
5034
  `patron_list_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier',
5015
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'the list''s name',
5035
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'the list''s name',
5016
  `owner` int(11) NOT NULL COMMENT 'borrowernumber of the list creator',
5036
  `owner` int(11) NOT NULL COMMENT 'borrowernumber of the list creator',
5017
  `shared` tinyint(1) DEFAULT 0,
5037
  `shared` tinyint(1) DEFAULT 0 COMMENT '1 for everyone, 2 for library and individuals, 3 for individuals',
5018
  PRIMARY KEY (`patron_list_id`),
5038
  PRIMARY KEY (`patron_list_id`),
5019
  KEY `owner` (`owner`),
5039
  KEY `owner` (`owner`),
5020
  CONSTRAINT `patron_lists_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
5040
  CONSTRAINT `patron_lists_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/add-modify.tt (-7 / +121 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% PROCESS 'i18n.inc' %]
3
[% PROCESS 'i18n.inc' %]
4
[% USE Branches %]
5
[% USE Categories %]
4
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
6
<title>[% FILTER collapse %]
8
<title>[% FILTER collapse %]
Lines 13-18 Link Here
13
    [% t("Tools") | html %] &rsaquo;
15
    [% t("Tools") | html %] &rsaquo;
14
    [% t("Koha") | html %]
16
    [% t("Koha") | html %]
15
[% END %]</title>
17
[% END %]</title>
18
  [% SET libraries = Branches.all %]
19
[% SET categories = Categories.all.unblessed %]
16
[% INCLUDE 'doc-head-close.inc' %]
20
[% INCLUDE 'doc-head-close.inc' %]
17
</head>
21
</head>
18
22
Lines 62-77 Link Here
62
                    </li>
66
                    </li>
63
67
64
                    <li>
68
                    <li>
65
                        <label for="list-shared">Shared:</label>
69
                        <label for="list-shared">Sharing mode:</label>
66
                        [% IF list.shared %]
70
                        <select name="shared" id="list-shared">
67
                            <input id="list-shared" name="shared" type="checkbox" checked="checked" />
71
                            <option value="0">Not shared</option>
68
                        [% ELSE %]
72
                            [% IF list.shared == 1 %]
69
                            <input id="list-shared" name="shared" type="checkbox" />
73
                                <option value="1" selected="selected">Everyone</option>
70
                        [% END %]
74
                            [% ELSE %]
75
                                <option value="1">Everyone</option>
76
                            [% END %]
77
                            [% IF list.shared == 2 %]
78
                                <option value="2" selected="selected">Library staff and individuals</option>
79
                            [% ELSE %]
80
                                <option value="2">Library staff and individuals</option>
81
                            [% END %]
82
                            [% IF list.shared == 3 %]
83
                                <option value="3" selected="selected">Individuals</option>
84
                            [% ELSE %]
85
                                <option value="3">Individuals</option>
86
                            [% END %]
87
                        </select>
71
                    </li>
88
                    </li>
72
89
73
                    <li>
90
                    <li>
74
                        <span class="label">Owner: </span>[% logged_in_user.userid | html %]
91
                        <span class="label">Owner: </span>[% INCLUDE 'patron-title.inc' patron=list.owner %]
75
                    </li>
92
                    </li>
76
                </ol>
93
                </ol>
77
94
Lines 83-93 Link Here
83
                <a href="lists.pl" class="cancel">Cancel</a>
100
                <a href="lists.pl" class="cancel">Cancel</a>
84
            </fieldset>
101
            </fieldset>
85
        </form>
102
        </form>
103
104
            <fieldset class="rows[% IF !list.shared || list.shared == 0 || list.shared == 1 %] hidden[% END %]" id="list-users">
105
106
                <legend>
107
                    Manage individuals with access to list
108
                </legend>
109
                <span class="label">Users: </span>
110
                <table id="patron_list_users">
111
                    <thead>
112
                        <tr><th>Name</th><th>Library</th><th>Category</th><th></th></tr>
113
                    </thead>
114
                    <tbody>
115
                    [% FOREACH u IN list.patron_list_users %]
116
                        <tr>
117
                            <td>[% INCLUDE 'patron-title.inc' patron=u.borrowernumber | html %]</td>
118
                            <td>[% u.borrowernumber.library_id.name | html %]</td>
119
                            <td>[% u.borrowernumber.category_id.name | html %]</td>
120
                            <td><a href="add-modify.pl?patron_list_id=[% list.patron_list_id | html %]&revoke_list_users_id=[% u.patron_list_user_id | html %]">Remove</a>
121
                        </tr>
122
                    [% END %]
123
                    </tbody>
124
                </table>
125
                <div id="searchform">
126
                    [% PROCESS patron_search_filters_simple %]
127
                </div>
128
                <div id="searchresults">
129
                     <div class="searchheader fh-fixedHeader" id="searchheader" style="display:none">
130
                         <div>
131
                             <a href="#" class="btn btn-link" id="select_all"><i class="fa fa-check"></i> Select all</a>
132
                             |
133
                             <a href="#" class="btn btn-link" id="clear_all"><i class="fa fa-remove"></i> Clear all</a>
134
                             <button id="add-patrons" class="btn btn-sm btn-default disabled" disabled="disabled"><i class="fa fa-compress" aria-hidden="true"></i> Add selected patrons to list</button>
135
                         </div>
136
                         [% PROCESS patron_search_table table_id => 'memberresultst' columns => ['checkbox','cardnumber','name','branch','category'] %]
137
                    </div>
138
                </li>
139
            </fieldset>
140
86
            </div>
141
            </div>
87
        </div>
142
        </div>
88
143
89
[% MACRO jsinclude BLOCK %]
144
[% MACRO jsinclude BLOCK %]
145
    [% INCLUDE 'datatables.inc' %]
90
    [% Asset.js("js/tools-menu.js") | $raw %]
146
    [% Asset.js("js/tools-menu.js") | $raw %]
147
    <script>
148
        var patron_search_selections = [];
149
150
        $('#add-patrons').on('click', function() {
151
            var merge_patrons_url = 'add-modify.pl?patron_list_id=[% list.patron_list_id | html %]&grant_borrowernumber=' + patron_search_selections.join("&grant_borrowernumber=");
152
            window.location.href = merge_patrons_url;
153
        });
154
155
        $(document).ready(function() {
156
            $(".browse").hide();
157
158
            $('#memberresultst').on('change', 'input.selection', function() {
159
                var borrowernumber = $(this).val();
160
                if( $(this).prop("checked") ){
161
                    patron_search_selections.push( $(this).val() );
162
                    $('#add-patrons').prop('disabled', false).removeClass("disabled");
163
                } else {
164
                    var filtered = patron_search_selections.filter(function( value ){
165
                        return value !== borrowernumber;
166
                    });
167
                    if( filtered.length > 0 ){
168
                        patron_search_selections = filtered;
169
                        $('#add-patrons').prop('disabled', false).removeClass("disabled");
170
                    } else {
171
                        patron_search_selections = [];
172
                        $('#add-patrons').prop('disabled', true).addClass("disabled");
173
                    }
174
                }
175
            });
176
177
            $("#select_all").on("click",function(e){
178
                e.preventDefault();
179
                patron_search_selections = [];
180
                $(".selection").each(function(){
181
                    if( $(this).prop("checked") == false ){
182
                        $(this).prop( "checked", true ).change();
183
                    }
184
                    patron_search_selections.push( $(this).val() );
185
                });
186
                $('#add-patrons').removeClass("disabled").prop('disabled', false);
187
            });
188
            $("#clear_all").on("click",function(e){
189
                e.preventDefault();
190
                $(".selection").each(function(){
191
                    if( $(this).prop("checked") ){
192
                        $(this).prop("checked", false ).change();
193
                    }
194
                });
195
                patron_search_selections = [];
196
                $('#add-patrons').prop('disabled', true).addClass("disabled");
197
            });
198
199
            $("#searchheader").hide();
200
            $("#patron_search_form").on('submit', function(){$("#searchheader").show();});
201
        });
202
    </script>
203
    [% PROCESS patron_search_js table_id => 'memberresultst', columns => ['checkbox','cardnumber','name','branch','category'], default_sort_column => 'name-address', display_search_description => 1, libraries => libraries, categories => categories %]
204
91
[% END %]
205
[% END %]
92
206
93
[% INCLUDE 'intranet-bottom.inc' %]
207
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/members/member.pl (-2 / +2 lines)
Lines 27-33 use Modern::Perl; Link Here
27
use C4::Auth qw( get_template_and_user );
27
use C4::Auth qw( get_template_and_user );
28
use C4::Output qw( output_html_with_http_headers );
28
use C4::Output qw( output_html_with_http_headers );
29
use CGI qw( -utf8 );
29
use CGI qw( -utf8 );
30
use Koha::List::Patron qw( GetPatronLists );
30
use Koha::List::Patron qw( get_patron_lists );
31
use Koha::Patrons;
31
use Koha::Patrons;
32
use Koha::Patron::Attribute::Types;
32
use Koha::Patron::Attribute::Types;
33
33
Lines 72-78 $template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', Link Here
72
my $defer_loading = $input->request_method() eq "GET"  && !$circsearch ? 1 : 0;
72
my $defer_loading = $input->request_method() eq "GET"  && !$circsearch ? 1 : 0;
73
73
74
$template->param(
74
$template->param(
75
    patron_lists => [ GetPatronLists() ],
75
    patron_lists => [ get_patron_lists() ],
76
    searchmember        => $searchmember,
76
    searchmember        => $searchmember,
77
    branchcode_filter   => scalar $input->param('branchcode_filter'),
77
    branchcode_filter   => scalar $input->param('branchcode_filter'),
78
    categorycode_filter => scalar $input->param('categorycode_filter'),
78
    categorycode_filter => scalar $input->param('categorycode_filter'),
(-)a/members/members-home.pl (-2 / +2 lines)
Lines 25-31 use C4::Context; Link Here
25
use C4::Members;
25
use C4::Members;
26
use Koha::Patron::Modifications;
26
use Koha::Patron::Modifications;
27
use Koha::Libraries;
27
use Koha::Libraries;
28
use Koha::List::Patron qw( GetPatronLists );
28
use Koha::List::Patron qw( get_patron_lists );
29
use Koha::Patron::Categories;
29
use Koha::Patron::Categories;
30
use Koha::Patron::Attribute::Types;
30
use Koha::Patron::Attribute::Types;
31
31
Lines 71-77 $template->param( Link Here
71
$template->param(
71
$template->param(
72
    alphabet => C4::Context->preference('alphabet') || join (' ', 'A' .. 'Z'),
72
    alphabet => C4::Context->preference('alphabet') || join (' ', 'A' .. 'Z'),
73
    PatronAutoComplete => C4::Context->preference('PatronAutoComplete'),
73
    PatronAutoComplete => C4::Context->preference('PatronAutoComplete'),
74
    patron_lists => [ GetPatronLists() ],
74
    patron_lists => [ get_patron_lists() ],
75
    PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
75
    PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
76
);
76
);
77
77
(-)a/patron_lists/add-modify.pl (-8 / +29 lines)
Lines 23-29 use CGI qw ( -utf8 ); Link Here
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output qw( output_html_with_http_headers );
25
use C4::Output qw( output_html_with_http_headers );
26
use Koha::List::Patron qw( AddPatronList GetPatronLists ModPatronList );
26
use Koha::List::Patron qw( get_patron_list add_patron_list mod_patron_list grant_patrons_access_to_list revoke_patrons_access_from_list );
27
27
28
my $cgi = CGI->new;
28
my $cgi = CGI->new;
29
29
Lines 38-61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
38
38
39
my $id   = $cgi->param('patron_list_id');
39
my $id   = $cgi->param('patron_list_id');
40
my $name = $cgi->param('name');
40
my $name = $cgi->param('name');
41
my $shared = $cgi->param('shared') ? 1 : 0;
41
my $shared = $cgi->param('shared');
42
my @grant_user = $cgi->multi_param('grant_borrowernumber');
43
my @revoke_user = $cgi->multi_param('revoke_list_users_id');
42
44
43
if ($id) {
45
if ($id) {
44
    my ($list) = GetPatronLists( { patron_list_id => $id } );
46
    my $list = get_patron_list( { 'patron_list_id' => $id } );
45
    $template->param( list => $list );
47
    $template->param( list => $list );
46
}
48
}
47
49
48
if ($name) {
50
if ($name) {
51
    my $list;
49
    if ($id) {
52
    if ($id) {
50
        ModPatronList( { patron_list_id => $id, name => $name, shared => $shared } );
53
        mod_patron_list( { patron_list_id => $id, name => $name, shared => $shared } );
51
        print $cgi->redirect('lists.pl');
54
        $list = get_patron_list( { 'patron_list_id' => $id } );
52
    }
55
    }
53
    else {
56
    else {
54
        my $list = AddPatronList( { name => $name, shared => $shared } );
57
        $list = add_patron_list( { name => $name, shared => $shared } );
55
        print $cgi->redirect(
56
            "list.pl?patron_list_id=" . $list->patron_list_id() );
57
    }
58
    }
58
59
60
    $template->param( list => $list );
61
}
62
63
if (@grant_user) {
64
    my $list = get_patron_list( { 'patron_list_id' => $id } );
65
    my $results = grant_patrons_access_to_list({
66
        list => $list,
67
        borrowernumbers => \@grant_user,
68
    });
69
    print $cgi->redirect("add-modify.pl?patron_list_id=" . $list->patron_list_id() );
70
    exit;
71
}
72
73
if (@revoke_user) {
74
    my $list = get_patron_list( { 'patron_list_id' => $id } );
75
    my $results = revoke_patrons_access_from_list({
76
        list => $list,
77
        patron_list_users => \@revoke_user,
78
    });
79
    print $cgi->redirect("add-modify.pl?patron_list_id=" . $list->patron_list_id() );
59
    exit;
80
    exit;
60
}
81
}
61
82
(-)a/patron_lists/delete.pl (-3 / +3 lines)
Lines 23-29 use CGI qw ( -utf8 ); Link Here
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output;
25
use C4::Output;
26
use Koha::List::Patron qw( DelPatronList );
26
use Koha::List::Patron qw( del_patron_list );
27
27
28
my $cgi = CGI->new;
28
my $cgi = CGI->new;
29
29
Lines 40-50 my $id = $cgi->param('patron_list_id'); Link Here
40
my @lists_ids = $cgi->multi_param('patron_lists_ids');
40
my @lists_ids = $cgi->multi_param('patron_lists_ids');
41
41
42
if ( defined $id && $id ne '' ) {
42
if ( defined $id && $id ne '' ) {
43
    DelPatronList( { patron_list_id => $id } );
43
    del_patron_list( { patron_list_id => $id } );
44
}
44
}
45
if (@lists_ids) {
45
if (@lists_ids) {
46
    foreach my $list_id (@lists_ids) {
46
    foreach my $list_id (@lists_ids) {
47
        DelPatronList( { patron_list_id => $list_id } );
47
        del_patron_list( { patron_list_id => $list_id } );
48
    }
48
    }
49
}
49
}
50
50
(-)a/patron_lists/list.pl (-7 / +7 lines)
Lines 24-32 use CGI qw ( -utf8 ); Link Here
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output qw( output_html_with_http_headers );
25
use C4::Output qw( output_html_with_http_headers );
26
use Koha::List::Patron qw(
26
use Koha::List::Patron qw(
27
    AddPatronsToList
27
    get_patron_list
28
    DelPatronsFromList
28
    add_patrons_to_list
29
    GetPatronLists
29
    del_patrons_from_list
30
);
30
);
31
use List::MoreUtils qw( uniq );
31
use List::MoreUtils qw( uniq );
32
32
Lines 42-48 my ( $template, $logged_in_user, $cookie ) = get_template_and_user( Link Here
42
);
42
);
43
43
44
my ($list) =
44
my ($list) =
45
  GetPatronLists( { patron_list_id => scalar $cgi->param('patron_list_id') } );
45
  get_patron_list( { patron_list_id => scalar $cgi->param('patron_list_id') } );
46
46
47
my @existing = $list->patron_list_patrons;
47
my @existing = $list->patron_list_patrons;
48
48
Lines 54-60 if ( $patrons_by_id ){ Link Here
54
    my %add_params;
54
    my %add_params;
55
    $add_params{list} = $list;
55
    $add_params{list} = $list;
56
    $add_params{ $id_column } = \@patrons_list;
56
    $add_params{ $id_column } = \@patrons_list;
57
    my @results = AddPatronsToList(\%add_params);
57
    my @results = add_patrons_to_list(\%add_params);
58
    my $id = $id_column eq 'borrowernumbers' ? 'borrowernumber' : 'cardnumber';
58
    my $id = $id_column eq 'borrowernumbers' ? 'borrowernumber' : 'cardnumber';
59
    my %found = map { $_->borrowernumber->$id => 1 } @results;
59
    my %found = map { $_->borrowernumber->$id => 1 } @results;
60
    my %exist = map { $_->borrowernumber->$id => 1 } @existing;
60
    my %exist = map { $_->borrowernumber->$id => 1 } @existing;
Lines 72-83 if ( $patrons_by_id ){ Link Here
72
72
73
my @patrons_to_add = $cgi->multi_param('patrons_to_add');
73
my @patrons_to_add = $cgi->multi_param('patrons_to_add');
74
if (@patrons_to_add) {
74
if (@patrons_to_add) {
75
    AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } );
75
    add_patrons_to_list( { list => $list, cardnumbers => \@patrons_to_add } );
76
}
76
}
77
77
78
my @patrons_to_remove = $cgi->multi_param('patrons_to_remove');
78
my @patrons_to_remove = $cgi->multi_param('patrons_to_remove');
79
if (@patrons_to_remove) {
79
if (@patrons_to_remove) {
80
    DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } );
80
    del_patrons_from_list( { list => $list, patron_list_patrons => \@patrons_to_remove } );
81
}
81
}
82
82
83
$template->param( list => $list );
83
$template->param( list => $list );
(-)a/patron_lists/lists.pl (-2 / +2 lines)
Lines 23-29 use CGI qw ( -utf8 ); Link Here
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output qw( output_html_with_http_headers );
25
use C4::Output qw( output_html_with_http_headers );
26
use Koha::List::Patron qw( GetPatronLists );
26
use Koha::List::Patron qw( get_patron_lists );
27
27
28
my $cgi = CGI->new;
28
my $cgi = CGI->new;
29
29
Lines 36-42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
36
    }
36
    }
37
);
37
);
38
38
39
my @lists = GetPatronLists();
39
my @lists = get_patron_lists();
40
40
41
$template->param( lists => \@lists );
41
$template->param( lists => \@lists );
42
42
(-)a/patron_lists/patron-lists-tab.pl (-6 / +6 lines)
Lines 25-31 use C4::Auth qw( get_template_and_user ); Link Here
25
use C4::Output qw( output_html_with_http_headers );
25
use C4::Output qw( output_html_with_http_headers );
26
26
27
use Koha::Patrons;
27
use Koha::Patrons;
28
use Koha::List::Patron qw( GetPatronLists AddPatronsToList DelPatronsFromList );
28
use Koha::List::Patron qw( get_patron_lists get_patron_list add_patrons_to_list del_patrons_from_list );
29
29
30
my $cgi = CGI->new;
30
my $cgi = CGI->new;
31
31
Lines 54-67 if ( !$logged_in_user->can_see_patron_infos($patron) ) { Link Here
54
} else {
54
} else {
55
    my $has_perms = C4::Auth::haspermission( $logged_in_user->userid, { 'tools' => 'manage_patron_lists' } );
55
    my $has_perms = C4::Auth::haspermission( $logged_in_user->userid, { 'tools' => 'manage_patron_lists' } );
56
    if ( $list_id && $has_perms ) {
56
    if ( $list_id && $has_perms ) {
57
        my ($list) = GetPatronLists( { patron_list_id => $list_id } );
57
        my ($list) = get_patron_list( { patron_list_id => $list_id } );
58
58
59
        if (@patrons_to_add) {
59
        if (@patrons_to_add) {
60
            AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } );
60
            add_patrons_to_list( { list => $list, cardnumbers => \@patrons_to_add } );
61
        }
61
        }
62
62
63
        if (@patrons_to_remove) {
63
        if (@patrons_to_remove) {
64
            DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } );
64
            del_patrons_from_list( { list => $list, patron_list_patrons => \@patrons_to_remove } );
65
        }
65
        }
66
    }
66
    }
67
67
Lines 77-84 if ( !$logged_in_user->can_see_patron_infos($patron) ) { Link Here
77
            }
77
            }
78
        }
78
        }
79
    }
79
    }
80
    @available_lists = GetPatronLists();
80
    @available_lists = get_patron_lists();
81
    @available_lists = grep { !$list_id_lookup{ $_->patron_list_id } } @available_lists;
81
    @available_lists = grep { ! $list_id_lookup{$_->patron_list_id} } @available_lists;
82
}
82
}
83
83
84
$template->param(
84
$template->param(
(-)a/patron_lists/patrons.pl (-4 / +4 lines)
Lines 23-29 use CGI qw ( -utf8 ); Link Here
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output qw( output_html_with_http_headers );
25
use C4::Output qw( output_html_with_http_headers );
26
use Koha::List::Patron qw( AddPatronList GetPatronLists ModPatronList );
26
use Koha::List::Patron qw( get_patron_list add_patron_list mod_patron_list );
27
27
28
my $cgi = CGI->new;
28
my $cgi = CGI->new;
29
29
Lines 40-55 my $id = $cgi->param('patron_list_id'); Link Here
40
my $name = $cgi->param('name');
40
my $name = $cgi->param('name');
41
41
42
if ($id) {
42
if ($id) {
43
    my ($list) = GetPatronLists( { patron_list_id => $id } );
43
    my ($list) = get_patron_list( { patron_list_id => $id } );
44
    $template->param( list => $list );
44
    $template->param( list => $list );
45
}
45
}
46
46
47
if ($name) {
47
if ($name) {
48
    if ($id) {
48
    if ($id) {
49
        ModPatronList( { patron_list_id => $id, name => $name } );
49
        mod_patron_list( { patron_list_id => $id, name => $name } );
50
    }
50
    }
51
    else {
51
    else {
52
        AddPatronList( { name => $name } );
52
        add_patron_list( { name => $name } );
53
    }
53
    }
54
54
55
    print $cgi->redirect('lists.pl');
55
    print $cgi->redirect('lists.pl');
(-)a/patroncards/create-pdf.pl (-3 / +3 lines)
Lines 29-35 use autouse 'Data::Dumper' => qw(Dumper); Link Here
29
use C4::Context;
29
use C4::Context;
30
use C4::Creators;
30
use C4::Creators;
31
use C4::Patroncards;
31
use C4::Patroncards;
32
use Koha::List::Patron qw( GetPatronLists );
32
use Koha::List::Patron qw( get_patron_list );
33
use Koha::Patrons;
33
use Koha::Patrons;
34
use Koha::Patron::Images;
34
use Koha::Patron::Images;
35
35
Lines 61-67 my $cardscount = 0; Link Here
61
61
62
#Note fo bug 14138: Indenting follows in separate patch to ease review
62
#Note fo bug 14138: Indenting follows in separate patch to ease review
63
eval {
63
eval {
64
$pdf_file = (@label_ids || @borrower_numbers ? "card_single_" . scalar(@label_ids || @borrower_numbers) : "card_batch_$batch_id");
64
$pdf_file = (@label_ids || @borrower_numbers || $patronlist_id ? "card_single_" . scalar(@label_ids || @borrower_numbers || $patronlist_id) : "card_batch_$batch_id");
65
65
66
$pdf = C4::Creators::PDF->new(InitVars => 0);
66
$pdf = C4::Creators::PDF->new(InitVars => 0);
67
my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
67
my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
Lines 96-102 elsif (@borrower_numbers) { Link Here
96
    } @borrower_numbers;
96
    } @borrower_numbers;
97
}
97
}
98
elsif ( $patronlist_id  ) {
98
elsif ( $patronlist_id  ) {
99
    my ($list) = GetPatronLists( { patron_list_id => $patronlist_id } );
99
    my $list = get_patron_list( { patron_list_id => $patronlist_id } );
100
    my @borrowerlist = $list->patron_list_patrons()->search_related('borrowernumber')
100
    my @borrowerlist = $list->patron_list_patrons()->search_related('borrowernumber')
101
    ->get_column('borrowernumber')->all();
101
    ->get_column('borrowernumber')->all();
102
    grep {
102
    grep {
(-)a/patroncards/manage.pl (-2 / +2 lines)
Lines 33-39 use C4::Creators qw( Link Here
33
    html_table
33
    html_table
34
);
34
);
35
use C4::Labels;
35
use C4::Labels;
36
use Koha::List::Patron qw( GetPatronLists );
36
use Koha::List::Patron qw( get_patron_lists );
37
37
38
my $cgi = CGI->new;
38
my $cgi = CGI->new;
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 117-123 else { # trap unsupported operations here Link Here
117
my $table = html_table($display_columns->{$card_element}, $db_rows);
117
my $table = html_table($display_columns->{$card_element}, $db_rows);
118
118
119
$template->param(print => 1) if ($card_element eq 'batch');
119
$template->param(print => 1) if ($card_element eq 'batch');
120
$template->param( patron_lists => [ GetPatronLists() ] ) if ($card_element eq 'batch');
120
$template->param( patron_lists => [ get_patron_lists() ] ) if ($card_element eq 'batch');
121
121
122
$template->param(
122
$template->param(
123
                error           => $errstr,
123
                error           => $errstr,
(-)a/svc/members/add_to_list (-4 / +4 lines)
Lines 22-28 use CGI; Link Here
22
22
23
use C4::Auth qw( check_cookie_auth );
23
use C4::Auth qw( check_cookie_auth );
24
use JSON qw( to_json );
24
use JSON qw( to_json );
25
use Koha::List::Patron qw( AddPatronList GetPatronLists AddPatronsToList );
25
use Koha::List::Patron qw( add_patron_list get_patron_lists add_patrons_to_list );
26
26
27
my $input = CGI->new;
27
my $input = CGI->new;
28
28
Lines 41-54 if ($add_to_patron_list) { Link Here
41
    my $patron_list = [];
41
    my $patron_list = [];
42
42
43
    if ( $add_to_patron_list eq 'new' ) {
43
    if ( $add_to_patron_list eq 'new' ) {
44
        $patron_list = AddPatronList( { name => $new_patron_list } );
44
        $patron_list = add_patron_list( { name => $new_patron_list } );
45
    }
45
    }
46
    else {
46
    else {
47
        $patron_list =
47
        $patron_list =
48
          [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0];
48
          [ get_patron_lists( { patron_list_id => $add_to_patron_list } ) ]->[0];
49
    }
49
    }
50
50
51
    my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
51
    my @patrons_added_to_list = add_patrons_to_list( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
52
52
53
    $response->{patron_list} = { patron_list_id => $patron_list->patron_list_id, name => $patron_list->name };
53
    $response->{patron_list} = { patron_list_id => $patron_list->patron_list_id, name => $patron_list->name };
54
    $response->{patrons_added_to_list} = scalar( @patrons_added_to_list );
54
    $response->{patrons_added_to_list} = scalar( @patrons_added_to_list );
(-)a/t/db_dependent/Members.t (-4 / +4 lines)
Lines 25-31 use Data::Dumper qw/Dumper/; Link Here
25
use C4::Context;
25
use C4::Context;
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Holds;
27
use Koha::Holds;
28
use Koha::List::Patron qw( AddPatronList AddPatronsToList );
28
use Koha::List::Patron qw( add_patron_list add_patrons_to_list );
29
use Koha::Patrons;
29
use Koha::Patrons;
30
use Koha::Patron::Relationship;
30
use Koha::Patron::Relationship;
31
31
Lines 214-227 my $anonymous_patron = Koha::Patron->new({ categorycode => 'CIVILIAN', branchcod Link Here
214
t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_patron);
214
t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_patron);
215
215
216
my $owner = Koha::Patron->new({ categorycode => 'STAFFER', branchcode => $library2->{branchcode} })->store->borrowernumber;
216
my $owner = Koha::Patron->new({ categorycode => 'STAFFER', branchcode => $library2->{branchcode} })->store->borrowernumber;
217
my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
217
my $list1 = add_patron_list( { name => 'Test List 1', owner => $owner } );
218
218
219
AddPatronsToList( { list => $list1, borrowernumbers => [$anonymous_patron] } );
219
add_patrons_to_list( { list => $list1, borrowernumbers => [$anonymous_patron] } );
220
my $patstodel = GetBorrowersToExpunge( { patron_list_id => $list1->patron_list_id() } );
220
my $patstodel = GetBorrowersToExpunge( { patron_list_id => $list1->patron_list_id() } );
221
is( scalar(@$patstodel), 0, 'Anonymous Patron not deleted from list' );
221
is( scalar(@$patstodel), 0, 'Anonymous Patron not deleted from list' );
222
222
223
my @listpatrons = ($bor1inlist, $bor2inlist);
223
my @listpatrons = ($bor1inlist, $bor2inlist);
224
AddPatronsToList(  { list => $list1, borrowernumbers => \@listpatrons });
224
add_patrons_to_list(  { list => $list1, borrowernumbers => \@listpatrons });
225
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
225
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
226
is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
226
is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
227
Koha::Patrons->find($bor2inlist)->set({ categorycode => 'CIVILIAN' })->store;
227
Koha::Patrons->find($bor2inlist)->set({ categorycode => 'CIVILIAN' })->store;
(-)a/t/db_dependent/PatronLists.t (-31 / +62 lines)
Lines 17-37 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 12;
20
use Test::More tests => 16;
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( add_patron_list add_patrons_to_list del_patron_list del_patrons_from_list get_patron_list get_patron_lists mod_patron_list grant_patrons_access_to_list revoke_patrons_access_from_list );
27
use Koha::Patrons;
27
use Koha::Patrons;
28
28
29
my $schema = Koha::Database->schema;
29
my $schema = Koha::Database->schema;
30
$schema->storage->txn_begin;
30
$schema->storage->txn_begin;
31
31
32
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
33
my $branchcode   = $builder->build( { source => 'Branch' } )->{branchcode};
33
34
34
t::lib::Mocks::mock_userenv();
35
t::lib::Mocks::mock_userenv({branchcode => $branchcode});
35
36
36
# Create 10 sample borrowers
37
# Create 10 sample borrowers
37
my @borrowers = ();
38
my @borrowers = ();
Lines 42-56 foreach (1..10) { Link Here
42
my $owner  = $borrowers[0]->{borrowernumber};
43
my $owner  = $borrowers[0]->{borrowernumber};
43
my $owner2 = $borrowers[1]->{borrowernumber};
44
my $owner2 = $borrowers[1]->{borrowernumber};
44
45
45
my @lists = GetPatronLists( { owner => $owner } );
46
my $owner3 = Koha::Patron->new(
47
    {
48
        surname      => 'Test 1',
49
        branchcode   => $branchcode,
50
        categorycode => $borrowers[0]->{categorycode}
51
    }
52
);
53
$owner3->store();
54
55
my @lists = get_patron_lists( { owner => $owner } );
46
my $list_count_original = @lists;
56
my $list_count_original = @lists;
47
57
48
my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
58
my $list1 = add_patron_list( { name => 'Test List 1', owner => $owner } );
49
is( $list1->name(), 'Test List 1', 'AddPatronList works' );
59
is( $list1->name(), 'Test List 1', 'add_patron_list works' );
50
60
51
my $list2 = AddPatronList( { name => 'Test List 2', owner => $owner } );
61
my $list2 = add_patron_list( { name => 'Test List 2', owner => $owner } );
52
62
53
ModPatronList(
63
mod_patron_list(
54
    {
64
    {
55
        patron_list_id => $list2->patron_list_id(),
65
        patron_list_id => $list2->patron_list_id(),
56
        name           => 'Test List 3',
66
        name           => 'Test List 3',
Lines 58-75 ModPatronList( Link Here
58
    }
68
    }
59
);
69
);
60
$list2->discard_changes();
70
$list2->discard_changes();
61
is( $list2->name(), 'Test List 3', 'ModPatronList works' );
71
is( $list2->name(), 'Test List 3', 'mod_patron_list works' );
72
73
$list1 =
74
  get_patron_list( { patron_list_id => $list1->patron_list_id() } );
75
is( $list1->name(), 'Test List 1', 'get_patron_list works' );
62
76
63
AddPatronsToList(
77
add_patrons_to_list(
64
    { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
78
    { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
65
);
79
);
66
is(
80
is(
67
    scalar @borrowers,
81
    scalar @borrowers,
68
      $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
82
      $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
69
    'AddPatronsToList works for cardnumbers'
83
    'add_patrons_to_list works for cardnumbers'
70
);
84
);
71
85
72
AddPatronsToList(
86
add_patrons_to_list(
73
    {
87
    {
74
        list            => $list2,
88
        list            => $list2,
75
        borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
89
        borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
Lines 78-126 AddPatronsToList( Link Here
78
is(
92
is(
79
    scalar @borrowers,
93
    scalar @borrowers,
80
      $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
94
      $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
81
    'AddPatronsToList works for borrowernumbers'
95
    'add_patrons_to_list works for borrowernumbers'
82
);
96
);
83
97
84
my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' });
98
my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' });
85
$deleted_patron->delete;
99
$deleted_patron->delete;
86
my @result = AddPatronsToList({list => $list2,borrowernumbers => [ $deleted_patron->borrowernumber ]});
100
my @result = add_patrons_to_list({list => $list2,borrowernumbers => [ $deleted_patron->borrowernumber ]});
87
is( scalar @result, 0,'Invalid borrowernumber not added');
101
is( scalar @result, 0,'Invalid borrowernumber not added');
88
@result = AddPatronsToList({list => $list2,cardnumbers => [ $deleted_patron->cardnumber ]});
102
@result = add_patrons_to_list({list => $list2,cardnumbers => [ $deleted_patron->cardnumber ]});
89
is( scalar @result, 0,'Invalid cardnumber not added');
103
is( scalar @result, 0,'Invalid cardnumber not added');
90
104
91
my @ids =
105
my @ids =
92
  $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
106
  $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
93
DelPatronsFromList(
107
del_patrons_from_list(
94
    {
108
    {
95
        list                => $list1,
109
        list                => $list1,
96
        patron_list_patrons => \@ids,
110
        patron_list_patrons => \@ids,
97
    }
111
    }
98
);
112
);
99
$list1->discard_changes();
113
$list1->discard_changes();
100
is( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' );
114
is( $list1->patron_list_patrons()->count(), 0, 'del_patrons_from_list works.' );
101
115
102
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
116
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
103
AddPatronsToList({list => $list2,borrowernumbers => [ $patron->borrowernumber ]});
117
add_patrons_to_list({list => $list2,borrowernumbers => [ $patron->borrowernumber ]});
104
@lists = $patron->get_lists_with_patron;
118
@lists = $patron->get_lists_with_patron;
105
is( scalar @lists, 1, 'get_lists_with_patron works' );
119
is( scalar @lists, 1, 'get_lists_with_patron works' );
106
120
107
@lists = GetPatronLists( { owner => $owner } );
121
@lists = get_patron_lists( { owner => $owner } );
108
is( scalar @lists, $list_count_original + 2, 'GetPatronLists works' );
122
is( scalar @lists, $list_count_original + 2, 'get_patron_lists works' );
123
124
my $list3 = add_patron_list( { name => 'Test List 3', owner => $owner2, shared => 0 } );
125
@lists = get_patron_lists( { owner => $owner } );
126
is( scalar @lists, $list_count_original + 2, 'get_patron_lists does not return non-shared list' );
127
128
my $list4 = add_patron_list( { name => 'Test List 4', owner => $owner2, shared => 1 } );
129
@lists = get_patron_lists( { owner => $owner } );
130
is( scalar @lists, $list_count_original + 3, 'get_patron_lists does return shared list' );
131
132
del_patron_list( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
133
del_patron_list( { patron_list_id => $list2->patron_list_id(), owner => $owner } );
134
135
$list1 =
136
  get_patron_list( { patron_list_id => $list1->patron_list_id() } );
137
is( $list1, undef, 'del_patron_list works' );
109
138
110
my $list3 = AddPatronList( { name => 'Test List 3', owner => $owner2, shared => 0 } );
139
@lists = get_patron_lists();
111
@lists = GetPatronLists( { owner => $owner } );
140
my $lib_list_count = @lists;
112
is( scalar @lists, $list_count_original + 2, 'GetPatronLists does not return non-shared list' );
141
my $list5 = add_patron_list( { name => 'Test List 5', owner => $owner3->borrowernumber, shared => 2 } );
142
my $list6 = add_patron_list( { name => 'Test List 6', owner => $owner3->borrowernumber, shared => 3 } );
143
@lists = get_patron_lists();
144
is( scalar @lists, $lib_list_count + 1, 'get_patron_lists returns list shared with library' );
113
145
114
my $list4 = AddPatronList( { name => 'Test List 4', owner => $owner2, shared => 1 } );
146
grant_patrons_access_to_list( { list => $list6, borrowernumbers => [ $patron->borrowernumber ] } );
115
@lists = GetPatronLists( { owner => $owner } );
116
is( scalar @lists, $list_count_original + 3, 'GetPatronLists does return shared list' );
117
147
118
DelPatronList( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
148
@lists = get_patron_lists({ owner => $patron->borrowernumber });
119
DelPatronList( { patron_list_id => $list2->patron_list_id(), owner => $owner } );
149
is( scalar @lists, $lib_list_count + 2, 'get_patron_lists returns list shared with individual, grant_patrons_access_to_list works' );
120
150
121
@lists =
151
my @list_users = $list6->patron_list_users->get_column('patron_list_user_id')->all();
122
  GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
152
revoke_patrons_access_from_list({ list => $list6, patron_list_users => \@list_users });
123
is( scalar @lists, 0, 'DelPatronList works' );
153
@lists = get_patron_lists();
154
is( scalar @lists, $lib_list_count + 1, 'revoke_patrons_access_from_list works' );
124
155
125
$schema->storage->txn_rollback;
156
$schema->storage->txn_rollback;
126
157
(-)a/tools/cleanborrowers.pl (-2 / +2 lines)
Lines 40-46 use C4::Members qw( GetBorrowersToExpunge ); Link Here
40
use Koha::Old::Checkouts;
40
use Koha::Old::Checkouts;
41
use Koha::Patron::Categories;
41
use Koha::Patron::Categories;
42
use Koha::Patrons;
42
use Koha::Patrons;
43
use Koha::List::Patron qw( GetPatronLists );
43
use Koha::List::Patron qw( get_patron_lists );
44
44
45
my $cgi = CGI->new;
45
my $cgi = CGI->new;
46
46
Lines 161-167 elsif ( $step == 3 ) { Link Here
161
        testrun => ( $radio eq "testrun" ) ? 1: 0,
161
        testrun => ( $radio eq "testrun" ) ? 1: 0,
162
    );
162
    );
163
} else { # $step == 1
163
} else { # $step == 1
164
    my @all_lists = GetPatronLists();
164
    my @all_lists = get_patron_lists();
165
    my @non_empty_lists;
165
    my @non_empty_lists;
166
    foreach my $list (@all_lists){
166
    foreach my $list (@all_lists){
167
    my @patrons = $list->patron_list_patrons();
167
    my @patrons = $list->patron_list_patrons();
(-)a/tools/import_borrowers.pl (-3 / +3 lines)
Lines 45-51 use Koha::Token; Link Here
45
use Koha::Libraries;
45
use Koha::Libraries;
46
use Koha::Patron::Categories;
46
use Koha::Patron::Categories;
47
use Koha::Patron::Attribute::Types;
47
use Koha::Patron::Attribute::Types;
48
use Koha::List::Patron qw( AddPatronList AddPatronsToList );
48
use Koha::List::Patron qw( add_patron_list add_patrons_to_list );
49
49
50
use Koha::Patrons::Import;
50
use Koha::Patrons::Import;
51
my $Import = Koha::Patrons::Import->new();
51
my $Import = Koha::Patrons::Import->new();
Lines 139-146 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
139
    my $imported_borrowers = $return->{imported_borrowers};
139
    my $imported_borrowers = $return->{imported_borrowers};
140
140
141
    if ( $imported && $createpatronlist ) {
141
    if ( $imported && $createpatronlist ) {
142
        my $patronlist = AddPatronList({ name => $patronlistname });
142
        my $patronlist = add_patron_list({ name => $patronlistname });
143
        AddPatronsToList({ list => $patronlist, borrowernumbers => $imported_borrowers });
143
        add_patrons_to_list({ list => $patronlist, borrowernumbers => $imported_borrowers });
144
        $template->param('patronlistname' => $patronlistname);
144
        $template->param('patronlistname' => $patronlistname);
145
    }
145
    }
146
146
(-)a/tools/modborrowers.pl (-4 / +3 lines)
Lines 32-38 use C4::Koha qw( GetAuthorisedValues ); Link Here
32
use C4::Members;
32
use C4::Members;
33
use C4::Output qw( output_html_with_http_headers );
33
use C4::Output qw( output_html_with_http_headers );
34
use Koha::DateUtils qw( dt_from_string );
34
use Koha::DateUtils qw( dt_from_string );
35
use Koha::List::Patron qw( GetPatronLists );
35
use Koha::List::Patron qw( get_patron_lists );
36
use Koha::Libraries;
36
use Koha::Libraries;
37
use Koha::Patron::Categories;
37
use Koha::Patron::Categories;
38
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
38
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
Lines 89-95 if ( $op eq 'show' ) { Link Here
89
        }
89
        }
90
    } elsif ( my $patron_list_id = $input->param('patron_list_id') ){
90
    } elsif ( my $patron_list_id = $input->param('patron_list_id') ){
91
        # User selected a patron list
91
        # User selected a patron list
92
        my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } );
92
        my ($list) = get_patron_lists( { patron_list_id => $patron_list_id } );
93
        @patronidnumbers =
93
        @patronidnumbers =
94
          $list->patron_list_patrons()->search_related('borrowernumber')
94
          $list->patron_list_patrons()->search_related('borrowernumber')
95
          ->get_column('cardnumber')->all();
95
          ->get_column('cardnumber')->all();
Lines 459-465 if ( $op eq 'do' ) { Link Here
459
    $template->param( errors => \@errors );
459
    $template->param( errors => \@errors );
460
} else {
460
} else {
461
461
462
    $template->param( patron_lists => [ GetPatronLists() ] );
462
    $template->param( patron_lists => [ get_patron_lists() ] );
463
}
463
}
464
464
465
$template->param(
465
$template->param(
466
- 

Return to bug 32105