1 package Koha
::List
::Patron
;
3 # Copyright 2013 ByWater Solutions
5 # This file is part of Koha.
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.
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.
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>.
22 Koha::List::Patron - Management of lists of patrons
50 my @lists = GetPatronLists( $params );
52 Returns an array of lists created by the the given user
53 or the logged in user if none is passed in.
59 $params->{owner
} ||= C4
::Context
->userenv->{'number'};
61 unless ( $params->{owner
} ) {
62 carp
("No owner passed in or defined!");
66 delete $params->{owner
} if C4
::Context
->IsSuperLibrarian();
68 if ( my $owner = $params->{owner
} ) {
69 delete $params->{owner
};
76 my $schema = Koha
::Database
->new()->schema();
78 my @patron_lists = $schema->resultset('PatronList')->search($params);
80 return wantarray() ?
@patron_lists : \
@patron_lists;
85 DelPatronList( { patron_list_id => $list_id [, owner => $owner ] } );
92 $params->{owner
} ||= C4
::Context
->userenv->{'number'};
94 unless ( $params->{patron_list_id
} ) {
95 croak
("No patron list id passed in!");
97 unless ( $params->{owner
} ) {
98 carp
("No owner passed in or defined!");
102 delete( $params->{owner
} ) if ( C4
::Context
->IsSuperLibrarian() );
104 return Koha
::Database
->new()->schema()->resultset('PatronList')
105 ->search($params)->single()->delete();
110 AddPatronList( { name => $name [, owner => $owner ] } );
117 $params->{owner
} ||= C4
::Context
->userenv->{'number'};
119 unless ( $params->{owner
} ) {
120 carp
("No owner passed in or defined!");
124 unless ( $params->{name
} ) {
125 carp
("No list name passed in!");
129 return Koha
::Database
->new()->schema()->resultset('PatronList')
135 ModPatronList( { patron_list_id => $id, name => $name [, owner => $owner ] } );
142 unless ( $params->{patron_list_id
} ) {
143 carp
("No patron list id passed in!");
147 my ($list) = GetPatronLists
(
149 patron_list_id
=> $params->{patron_list_id
},
150 owner
=> $params->{owner
}
154 return $list->update($params);
157 =head2 AddPatronsToList
159 AddPatronsToList({ list => $list, cardnumbers => \@cardnumbers });
163 sub AddPatronsToList
{
166 my $list = $params->{list
};
167 my $cardnumbers = $params->{'cardnumbers'};
168 my $borrowernumbers = $params->{'borrowernumbers'};
170 return unless ( $list && ( $cardnumbers || $borrowernumbers ) );
176 Koha
::Database
->new()->schema()->resultset('Borrower')->search(
177 { cardnumber
=> { 'IN' => $cardnumbers } },
178 { columns
=> [qw
/ borrowernumber /] }
179 )->get_column('borrowernumber')->all();
182 @borrowernumbers = @
$borrowernumbers;
185 my $patron_list_id = $list->patron_list_id();
187 my $plp_rs = Koha
::Database
->new()->schema()->resultset('PatronListPatron');
190 foreach my $borrowernumber (@borrowernumbers) {
191 my $result = $plp_rs->update_or_create(
193 patron_list_id
=> $patron_list_id,
194 borrowernumber
=> $borrowernumber
197 push( @results, $result );
200 return wantarray() ?
@results : \
@results;
203 =head2 DelPatronsFromList
205 DelPatronsFromList({ list => $list, patron_list_patrons => \@patron_list_patron_ids });
209 sub DelPatronsFromList
{
212 my $list = $params->{list
};
213 my $patron_list_patrons = $params->{patron_list_patrons
};
215 return unless ( $list && $patron_list_patrons );
217 return Koha
::Database
->new()->schema()->resultset('PatronListPatron')
218 ->search( { patron_list_patron_id
=> { 'IN' => $patron_list_patrons } } )
224 Kyle M Hall, E<lt>kyle@bywatersolutions.comE<gt>