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
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>.
24 use Koha::DateUtils qw( dt_from_string );
28 use base qw(Koha::Objects);
32 Koha::Clubs - Koha Clubs Object class
34 This object represents a collection of clubs a patron may enroll in.
47 my ( $self, $params ) = @_;
49 # We need to filter out all the already enrolled in clubs
50 my $borrower = $params->{borrower};
52 delete( $params->{borrower} );
53 my @enrollments = $borrower->get_club_enrollments();
55 $params->{'me.id'} = { -not_in => [ map { $_->club()->id() } @enrollments ] };
59 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
61 # Only clubs with no end date or an end date in the future can be enrolled in
64 date_end => { '>=' => $dtf->format_datetime( dt_from_string() ) },
68 'me.branchcode' => $borrower->branchcode,
69 'me.branchcode' => undef,
73 my $rs = $self->_resultset()->search( $params, { prefetch => 'club_template' } );
76 my $class = ref($self) ? ref($self) : $self;
78 return $class->_wrap( $rs->all() );
82 my $class = ref($self) ? ref($self) : $self;
84 return $class->_new_from_dbic($rs);
102 Kyle M Hall <kyle@bywatersolutions.com>