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 - Managment 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 my $schema = Koha
::Database
->new()->schema();
70 my @patron_lists = $schema->resultset('PatronList')->search($params);
72 return wantarray() ?
@patron_lists : \
@patron_lists;
77 DelPatronList( { patron_list_id => $list_id [, owner => $owner ] } );
84 $params->{owner
} ||= C4
::Context
->userenv->{'number'};
86 unless ( $params->{patron_list_id
} ) {
87 croak
("No patron list id passed in!");
89 unless ( $params->{owner
} ) {
90 carp
("No owner passed in or defined!");
94 delete( $params->{owner
} ) if ( C4
::Context
->IsSuperLibrarian() );
96 return Koha
::Database
->new()->schema()->resultset('PatronList')
97 ->search($params)->single()->delete();
102 AddPatronList( { name => $name [, owner => $owner ] } );
109 $params->{owner
} ||= C4
::Context
->userenv->{'number'};
111 unless ( $params->{owner
} ) {
112 carp
("No owner passed in or defined!");
116 unless ( $params->{name
} ) {
117 carp
("No list name passed in!");
121 return Koha
::Database
->new()->schema()->resultset('PatronList')
127 ModPatronList( { patron_list_id => $id, name => $name [, owner => $owner ] } );
134 unless ( $params->{patron_list_id
} ) {
135 carp
("No patron list id passed in!");
139 my ($list) = GetPatronLists
(
141 patron_list_id
=> $params->{patron_list_id
},
142 owner
=> $params->{owner
}
146 return $list->update($params);
149 =head2 AddPatronsToList
151 AddPatronsToList({ list => $list, cardnumbers => \@cardnumbers });
155 sub AddPatronsToList
{
158 my $list = $params->{list
};
159 my $cardnumbers = $params->{'cardnumbers'};
160 my $borrowernumbers = $params->{'borrowernumbers'};
162 return unless ( $list && ( $cardnumbers || $borrowernumbers ) );
168 Koha
::Database
->new()->schema()->resultset('Borrower')->search(
169 { cardnumber
=> { 'IN' => $cardnumbers } },
170 { columns
=> [qw
/ borrowernumber /] }
171 )->get_column('borrowernumber')->all();
174 @borrowernumbers = @
$borrowernumbers;
177 my $patron_list_id = $list->patron_list_id();
179 my $plp_rs = Koha
::Database
->new()->schema()->resultset('PatronListPatron');
182 foreach my $borrowernumber (@borrowernumbers) {
183 my $result = $plp_rs->update_or_create(
185 patron_list_id
=> $patron_list_id,
186 borrowernumber
=> $borrowernumber
189 push( @results, $result );
192 return wantarray() ?
@results : \
@results;
195 =head2 DelPatronsFromList
197 DelPatronsFromList({ list => $list, patron_list_patrons => \@patron_list_patron_ids });
201 sub DelPatronsFromList
{
204 my $list = $params->{list
};
205 my $patron_list_patrons = $params->{patron_list_patrons
};
207 return unless ( $list && $patron_list_patrons );
209 return Koha
::Database
->new()->schema()->resultset('PatronListPatron')
210 ->search( { patron_list_patron_id
=> { 'IN' => $patron_list_patrons } } )
216 Kyle M Hall, E<lt>kyle@bywatersolutions.comE<gt>