From 01fc8897c33c9a924c718e43a3d65fce81949d2a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 27 Apr 2017 08:24:29 -0400 Subject: [PATCH] Bug 12461 [QA Followup] --- Koha/Club.pm | 12 ++++ Koha/Club/Enrollment.pm | 10 +++ Koha/Clubs.pm | 3 + Koha/Patron.pm | 16 +++-- clubs/club-enrollments.pl | 47 ++++++++++++++ clubs/clubs-add-modify.pl | 8 ++- .../prog/en/modules/circ/circulation.tt | 10 +-- .../prog/en/modules/clubs/club-enrollments.tt | 74 ++++++++++++++++++++++ .../intranet-tmpl/prog/en/modules/clubs/clubs.tt | 28 +++++++- .../prog/en/modules/clubs/patron-enroll.tt | 2 +- .../prog/en/modules/members/moremember.tt | 9 +-- .../bootstrap/en/modules/clubs/clubs-tab.tt | 2 +- .../opac-tmpl/bootstrap/en/modules/clubs/enroll.tt | 2 +- .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 9 ++- t/db_dependent/Clubs.t | 5 +- 15 files changed, 214 insertions(+), 23 deletions(-) create mode 100755 clubs/club-enrollments.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/clubs/club-enrollments.tt diff --git a/Koha/Club.pm b/Koha/Club.pm index 89f9409..0d93f8c 100644 --- a/Koha/Club.pm +++ b/Koha/Club.pm @@ -63,6 +63,18 @@ sub club_fields { return Koha::Club::Fields->search( { club_id => $self->id() } ); } +=head3 club_enrollments + +=cut + +sub club_enrollments { + my ($self) = @_; + + return unless $self->id(); + + return scalar Koha::Club::Enrollments->search( { club_id => $self->id() } ); +} + =head3 club_fields =cut diff --git a/Koha/Club/Enrollment.pm b/Koha/Club/Enrollment.pm index f7489d0..788f956 100644 --- a/Koha/Club/Enrollment.pm +++ b/Koha/Club/Enrollment.pm @@ -23,6 +23,7 @@ use Carp; use Koha::Database; use Koha::Clubs; +use Koha::Patrons; use base qw(Koha::Object); @@ -61,6 +62,15 @@ sub club { return Koha::Clubs->find( $self->club_id() ); } +=head3 patron + +=cut + +sub patron { + my ( $self ) = @_; + return Koha::Patrons->find( $self->borrowernumber() ); +} + =head3 type =cut diff --git a/Koha/Clubs.pm b/Koha/Clubs.pm index fff88d8..a553314 100644 --- a/Koha/Clubs.pm +++ b/Koha/Clubs.pm @@ -56,6 +56,9 @@ sub get_enrollable { } } + # Only clubs with no end date or an end date in the future can be enrolled in + $params->{'-or'} = [ date_end => { '>=' => \'CURRENT_DATE()' }, date_end => undef ]; + my $rs = $self->_resultset()->search( $params, { prefetch => 'club_template' } ); if (wantarray) { diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 759d2d6..b97bceb 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -600,9 +600,13 @@ sub first_valid_email_address { =cut sub get_club_enrollments { - my ($self) = @_; + my ( $self, $return_scalar ) = @_; + + my $e = Koha::Club::Enrollments->search( { borrowernumber => $self->borrowernumber(), date_canceled => undef } ); + + return $e if $return_scalar; - return Koha::Club::Enrollments->search( { borrowernumber => $self->borrowernumber(), date_canceled => undef } ); + return wantarray ? $e->as_list : $e; } =head3 get_enrollable_clubs @@ -610,7 +614,7 @@ sub get_club_enrollments { =cut sub get_enrollable_clubs { - my ( $self, $is_enrollable_from_opac ) = @_; + my ( $self, $is_enrollable_from_opac, $return_scalar ) = @_; my $params; $params->{is_enrollable_from_opac} = $is_enrollable_from_opac @@ -619,7 +623,11 @@ sub get_enrollable_clubs { $params->{borrower} = $self; - return Koha::Clubs->get_enrollable($params); + my $e = Koha::Clubs->get_enrollable($params); + + return $e if $return_scalar; + + return wantarray ? $e->as_list : $e; } =head3 type diff --git a/clubs/club-enrollments.pl b/clubs/club-enrollments.pl new file mode 100755 index 0000000..e3cd12d --- /dev/null +++ b/clubs/club-enrollments.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +# Copyright 2013 ByWater Solutions +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use CGI; + +use C4::Auth; +use C4::Output; +use Koha::Clubs; + +my $cgi = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => 'clubs/club-enrollments.tt', + query => $cgi, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { clubs => 'edit_clubs' }, + } +); + +my $id = $cgi->param('id'); +my $club = Koha::Clubs->find($id); + +$template->param( + club => $club, +); + +output_html_with_http_headers( $cgi, $cookie, $template->output ); diff --git a/clubs/clubs-add-modify.pl b/clubs/clubs-add-modify.pl index d1873d4..9d0ff08 100755 --- a/clubs/clubs-add-modify.pl +++ b/clubs/clubs-add-modify.pl @@ -44,7 +44,13 @@ my $schema = Koha::Database->new()->schema(); my $id = $cgi->param('id'); my $club = $id ? Koha::Clubs->find($id) : Koha::Club->new(); -my $stored = $cgi->param('name') ? $id ? 'updated' : 'stored' : undef; + +my $stored = + $cgi->param('name') + ? $id + ? 'updated' + : 'stored' + : undef; my $club_template_id = $cgi->param('club_template_id'); my $club_template = $club->club_template() || Koha::Club::Templates->find($club_template_id); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index c0a6572..e133b95 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -895,12 +895,12 @@ No patron matched [% message | html %] [% END %] - [% SET enrollments = patron.get_club_enrollments.size || 0 %] - [% SET enrollable = patron.get_enrollable_clubs.size || 0 %] - [% IF CAN_user_clubs && ( enrollable || enrollments ) %] + [% SET enrollments = patron.get_club_enrollments(1) %] + [% SET enrollable = patron.get_enrollable_clubs(0,1) %] + [% IF CAN_user_clubs && ( enrollable.count || enrollments.count ) %]
  • - Clubs ([% enrollments %]/[% enrollable %]) + Clubs ([% enrollments.count %]/[% enrollable.count %])
  • [% END %] @@ -923,7 +923,7 @@ No patron matched [% message | html %] [% END %] -
  • [% debarments.size %] Restrictions
  • +
  • [% debarments.count %] Restrictions
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/club-enrollments.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/club-enrollments.tt new file mode 100644 index 0000000..72af5b8 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/club-enrollments.tt @@ -0,0 +1,74 @@ +[% USE KohaDates %] +[% USE Branches %] +[% USE Koha %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Tools › Patron clubs › Club enrollments +[% INCLUDE 'doc-head-close.inc' %] + + +[% INCLUDE 'datatables.inc' %] + + + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + +
    +
    +
    +
    +

    Club enrollments for [% club.name %]

    + + + + + + + + + + + + [% FOREACH e IN club.club_enrollments %] + [% SET p = e.patron %] + + + + + + [% END %] + +
    NameCard number 
    + [% p.firstname %] [% p.surname %] + + [% p.cardnumber %] + + + + View patron + +
    +
    +
    +
    + [% INCLUDE 'tools-menu.inc' %] +
    +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/clubs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/clubs.tt index 15680bb..14fded1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/clubs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/clubs.tt @@ -1,3 +1,4 @@ +[% USE KohaDates %] [% USE Branches %] [% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] @@ -171,7 +172,11 @@ [% IF CAN_user_clubs_edit_clubs %]
    - + [% IF club_templates %] + + [% ELSE %] + + [% END %]
    - [% IF borrower.get_club_enrollments_count.size || borrower.get_enrollable_clubs(1).size %] + [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %]
    Loading...
    diff --git a/t/db_dependent/Clubs.t b/t/db_dependent/Clubs.t index 1ca9321..ed426f9 100755 --- a/t/db_dependent/Clubs.t +++ b/t/db_dependent/Clubs.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 36; +use Test::More tests => 37; use Test::Warn; use C4::Context; @@ -129,6 +129,8 @@ my $club = Koha::Club->new( club_template_id => $club_template->id, name => "Test Club", branchcode => $branchcode, + date_start => '1900-01-01', + date_end => '9999-01-01', } )->store(); @@ -216,6 +218,7 @@ is( $patron->get_club_enrollments->count, 1, 'Got 1 club enrollment for patron' ); is( $patron->get_enrollable_clubs->count, 0, 'No more enrollable clubs for patron' ); +is( $club->club_enrollments->count, 1, 'There is 1 enrollment for club' ); $schema->storage->txn_rollback(); 1; -- 2.10.2