Bug 21038: Reserves should be holds
[koha.git] / Koha / Clubs.pm
blobeeaf4ef3373846b269f3ccc4db294fb9b42acaa9
1 package Koha::Clubs;
3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Carp;
24 use Koha::Database;
25 use Koha::DateUtils qw( dt_from_string );
27 use Koha::Club;
29 use base qw(Koha::Objects);
31 =head1 NAME
33 Koha::Clubs - Koha Clubs Object class
35 This object represents a collection of clubs a patron may enroll in.
37 =head1 API
39 =head2 Class Methods
41 =cut
43 =head3 get_enrollable
45 =cut
47 sub get_enrollable {
48 my ( $self, $params ) = @_;
50 # We need to filter out all the already enrolled in clubs
51 my $borrower = $params->{borrower};
52 if ($borrower) {
53 delete( $params->{borrower} );
54 my @enrollments = $borrower->get_club_enrollments();
55 if (@enrollments) {
56 $params->{'me.id'} = { -not_in => [ map { $_->club()->id() } @enrollments ] };
60 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
62 # Only clubs with no end date or an end date in the future can be enrolled in
63 $params->{'-and'} = [
64 -or => [
65 date_end => { '>=' => $dtf->format_datetime( dt_from_string() ) },
66 date_end => undef,
68 -or => [
69 'me.branchcode' => $borrower->branchcode,
70 'me.branchcode' => undef,
74 my $rs = $self->_resultset()->search( $params, { prefetch => 'club_template' } );
76 if (wantarray) {
77 my $class = ref($self) ? ref($self) : $self;
79 return $class->_wrap( $rs->all() );
82 else {
83 my $class = ref($self) ? ref($self) : $self;
85 return $class->_new_from_dbic($rs);
89 =head3 type
91 =cut
93 sub _type {
94 return 'Club';
97 sub object_class {
98 return 'Koha::Club';
101 =head1 AUTHOR
103 Kyle M Hall <kyle@bywatersolutions.com>
105 =cut