Bug 12461 - (QA Followup)
[koha.git] / Koha / Clubs.pm
blob7d62d2299b62b7ff196f28524d527a2bb9b119a7
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;
26 use Koha::Club;
28 use base qw(Koha::Objects);
30 =head1 NAME
32 Koha::Clubs - Koha Clubs Object class
34 This object represents a collection of clubs a patron may enroll in.
36 =head1 API
38 =head2 Class Methods
40 =cut
42 =head3 get_enrollable
44 =cut
46 sub get_enrollable {
47 my ( $self, $params ) = @_;
49 # We need to filter out all the already enrolled in clubs
50 my $borrower = $params->{borrower};
51 if ($borrower) {
52 delete( $params->{borrower} );
53 my @enrollments = $borrower->get_club_enrollments();
54 if (@enrollments) {
55 $params->{'me.id'} = { -not_in => [ map { $_->club()->id() } @enrollments ] };
59 # Only clubs with no end date or an end date in the future can be enrolled in
60 $params->{'-and'} = [
61 -or => [ date_end => { '>=' => \'CURRENT_DATE()' }, date_end => undef],
62 -or => [ 'me.branchcode' => $borrower->branchcode, 'me.branchcode' => undef ]
65 my $rs = $self->_resultset()->search( $params, { prefetch => 'club_template' } );
67 if (wantarray) {
68 my $class = ref($self) ? ref($self) : $self;
70 return $class->_wrap( $rs->all() );
73 else {
74 my $class = ref($self) ? ref($self) : $self;
76 return $class->_new_from_dbic($rs);
80 =head3 type
82 =cut
84 sub _type {
85 return 'Club';
88 sub object_class {
89 return 'Koha::Club';
92 =head1 AUTHOR
94 Kyle M Hall <kyle@bywatersolutions.com>
96 =cut