Bug 12461 [QA Followup]
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 27 Apr 2017 12:24:29 +0000 (08:24 -0400)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 28 Apr 2017 12:37:44 +0000 (08:37 -0400)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

15 files changed:
Koha/Club.pm
Koha/Club/Enrollment.pm
Koha/Clubs.pm
Koha/Patron.pm
clubs/club-enrollments.pl [new file with mode: 0755]
clubs/clubs-add-modify.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/clubs/club-enrollments.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/clubs/clubs.tt
koha-tmpl/intranet-tmpl/prog/en/modules/clubs/patron-enroll.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/clubs/clubs-tab.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/clubs/enroll.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
t/db_dependent/Clubs.t

index 89f9409..0d93f8c 100644 (file)
@@ -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
index f7489d0..788f956 100644 (file)
@@ -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
index fff88d8..a553314 100644 (file)
@@ -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) {
index 759d2d6..b97bceb 100644 (file)
@@ -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 (executable)
index 0000000..e3cd12d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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 );
index d1873d4..9d0ff08 100755 (executable)
@@ -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);
index c0a6572..e133b95 100644 (file)
@@ -895,12 +895,12 @@ No patron matched <span class="ex">[% message | html %]</span>
         [% END %]
     </li>
 
-    [% 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 ) %]
         <li>
             <a id="clubs-tab-link" href="#clubs-tab">
-                Clubs ([% enrollments %]/[% enrollable %])
+                Clubs ([% enrollments.count %]/[% enrollable.count %])
             </a>
         </li>
     [% END %]
@@ -923,7 +923,7 @@ No patron matched <span class="ex">[% message | html %]</span>
         </li>
     [% END %]
 
-    <li><a id="debarments-tab-link" href="#reldebarments">[% debarments.size %] Restrictions</a></li>
+    <li><a id="debarments-tab-link" href="#reldebarments">[% debarments.count %] Restrictions</a></li>
 </ul>
 
 <!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
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 (file)
index 0000000..72af5b8
--- /dev/null
@@ -0,0 +1,74 @@
+[% USE KohaDates %]
+[% USE Branches %]
+[% USE Koha %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Tools &rsaquo; Patron clubs &rsaquo; Club enrollments</title>
+[% INCLUDE 'doc-head-close.inc' %]
+
+<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
+[% INCLUDE 'datatables.inc' %]
+
+<script type="text/javascript">
+//<![CDATA[
+    $(document).ready(function() {
+        eTable = $('#enrollments-table').dataTable($.extend(true, {}, dataTablesDefaults, {
+            "sPaginationType": "four_button",
+            "sDom": 'C<"top pager"ilpf><"#filter_c">tr<"bottom pager"ip>',
+            "aoColumnDefs": [
+                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
+            ]
+        } ));
+    });
+//]]>
+</script>
+
+</head>
+
+<body id="club_enrollments" class="clubs">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'cat-search.inc' %]
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Patron clubs &rsaquo; Club enrollments</div>
+
+<div id="doc3" class="yui-t2">
+   <div id="bd">
+        <div id="yui-main">
+            <div class="yui-b">
+                <h1>Club enrollments for <i>[% club.name %]</i></h1>
+
+                <table id="enrollments-table">
+                    <thead>
+                        <tr>
+                            <th>Name</th>
+                            <th>Card number</th>
+                            <th>&nbsp;</th>
+                        </tr>
+                    </thead>
+
+                    <tbody>
+                        [% FOREACH e IN club.club_enrollments %]
+                            [% SET p = e.patron %]
+                            <tr>
+                                <td>
+                                    [% p.firstname %] [% p.surname %]
+                                </td>
+                                <td>
+                                    [% p.cardnumber %]
+                                </td>
+                                <td>
+                                    <a class="btn btn-sm" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% p.id %]">
+                                        <i class="fa fa-eye"></i>
+                                        View patron
+                                    </a>
+                                </td>
+                            </tr>
+                        [% END %]
+                    </tbody>
+                </table>
+            </div>
+        </div>
+        <div class="yui-b noprint">
+            [% INCLUDE 'tools-menu.inc' %]
+        </div>
+    </div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
index 15680bb..14fded1 100644 (file)
@@ -1,3 +1,4 @@
+[% USE KohaDates %]
 [% USE Branches %]
 [% USE Koha %]
 [% INCLUDE 'doc-head-open.inc' %]
                 [% IF CAN_user_clubs_edit_clubs %]
                     <div class="btn-toolbar">
                         <div class="btn-group">
-                            <button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i> New club <span class="caret"></span></button>
+                            [% IF club_templates %]
+                                <button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i> New club <span class="caret"></span></button>
+                            [% ELSE %]
+                                <button disabled="disabled" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i> New club <span class="caret"></span></button>
+                            [% END %]
                             <ul class="dropdown-menu">
                                 [% FOREACH t IN club_templates %]
                                     <li><a href="/cgi-bin/koha/clubs/clubs-add-modify.pl?club_template_id=[% t.id %]">[% t.name %]</a></li>
                             <th>Public enrollment</th>
                             <th>Email required</th>
                             <th>Library</th>
+                            <th>Start date</th>
+                            <th>End date</th>
+                            <th>Enrolled patrons</th>
                             <th>&nbsp;</th>
                             <th>&nbsp;</th>
                         </tr>
                                     </td>
                                     <td>[% Branches.GetName( c.branchcode ) %]</td>
                                     <td>
+                                        [% IF c.date_start %]
+                                            [% c.date_start | $KohaDates %]
+                                        [% END %]
+                                    </td>
+                                    <td>
+                                        [% IF c.date_end %]
+                                            [% c.date_end | $KohaDates %]
+                                        [% END %]
+                                    </td>
+                                    <td>
+                                        [% c.club_enrollments.count %]
+                                        <a class="btn btn-xs" href="club-enrollments.pl?id=[% c.id %]">
+                                            View enrollments
+                                        </a>
+                                    </td>
+                                    <td>
                                         [% IF CAN_user_clubs_edit_clubs %]
                                             <a class="btn btn-default" style="white-space:nowrap" href="clubs-add-modify.pl?id=[% c.id %]">
                                                 <i class="fa fa-edit"></i> Edit
                         [% ELSE %]
                             <tr>
                                 <td colspan="8">
-                                    No club templates defined.
+                                    No clubs defined.
                                 </td>
                             </td>
                         [% END %]
index 25ee4ca..5b938d8 100644 (file)
@@ -28,7 +28,7 @@
                 [% END %]
 
                 <li>
-                    <a href="#" class="btn btn-default" onclick="addEnrollment(); return false;"><i class="fa fa-plus"></i> Enroll</a>
+                    <a href="#" class="btn btn-default" onclick="addEnrollment(); return false;"><i class="fa fa-plus"></i> Finish enrollment</a>
                     <a href="#" onclick="showClubs(); return false;">Cancel</a>
                 </li>
             </ol>
index 1ae43de..bba77f0 100644 (file)
@@ -523,12 +523,13 @@ function validate1(date) {
             </li>
         [% END %]
         <li><a id="debarments-tab-link" href="#reldebarments">[% debarments.size %] Restrictions</a></li>
-        [% SET enrollments = borrower.get_club_enrollments.size || 0 %]
-        [% SET enrollable  = borrower.get_enrollable_clubs.size || 0 %]
-        [% IF CAN_user_clubs && ( enrollments || enrollable ) %]
+
+        [% SET enrollments = patron.get_club_enrollments(1) %]
+        [% SET enrollable  = patron.get_enrollable_clubs(0,1) %]
+        [% IF CAN_user_clubs && ( enrollable.count || enrollments.count ) %]
             <li>
                 <a id="clubs-tab-link" href="#clubs-tab">
-                    Clubs ([% enrollments %]/[% enrollable %])
+                    Clubs ([% enrollments.count %]/[% enrollable.count %])
                 </a>
             </li>
         [% END %]
index 76ed1fc..cc604b6 100644 (file)
@@ -56,7 +56,7 @@
                     <td>[% c.name %]</td>
                     <td>[% c.description %]</td>
                     <td>
-                        [% IF !c.club_template.is_email_required || ( c.club_template.is_email_required && borrower.FirstValidEmailAddress ) %]
+                        [% IF !c.club_template.is_email_required || ( c.club_template.is_email_required && borrower.first_valid_email_address ) %]
                             <a class="btn btn-xs" onclick="loadEnrollmentForm([% c.id %])">
                                 <i class="icon-plus"></i> Enroll
                             </a>
index 6ea5094..2c53918 100644 (file)
@@ -28,7 +28,7 @@
                 [% END %]
 
                 <li>
-                    <a href="#" class="btn btn-default" onclick="addEnrollment(); return false;"><i class="fa fa-plus"></i> Enroll</a>
+                    <a href="#" class="btn btn-default" onclick="addEnrollment(); return false;"><i class="fa fa-plus"></i> Finish enrollment</a>
                     <a href="#" onclick="showClubs(); return false;">Cancel</a>
                 </li>
             </ol>
index e45bcc5..48d145d 100644 (file)
@@ -4,6 +4,9 @@
 [% USE ItemTypes %]
 [% USE Price %]
 
+[% SET borrower_club_enrollments =  borrower.get_club_enrollments(1) %]
+[% SET borrower_enrollable_clubs = borrower.get_enrollable_clubs(1,1) %]
+
 [% INCLUDE 'doc-head-open.inc' %]
 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your library home</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -134,10 +137,10 @@ Using this account is not recommended because some parts of Koha will not functi
                                 [% IF ( BORROWER_INFO.amountlessthanzero ) %]<li><a href="#opac-user-fines">Credits ([% amountoutstanding | $Price %])</a></li>[% END %]
                             [% END %]
 
-                            [% IF borrower.get_club_enrollments.size || borrower.get_enrollable_clubs(1).size %]
+                            [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %]
                                 <li>
                                     <a id="opac-user-clubs-tab-link" href="#opac-user-clubs">
-                                        Clubs ([% borrower.get_club_enrollments.size %]/[% borrower.get_enrollable_clubs(1).size || 0 %])
+                                        Clubs ([% borrower_club_enrollments.count || 0 %]/[% borrower_enrollable_clubs.count || 0 %])
                                     </a>
                                 </li>
                             [% END %]
@@ -328,7 +331,7 @@ Using this account is not recommended because some parts of Koha will not functi
                             [% END # IF issues_count %]
                         </div> <!-- / .opac-user-checkouts -->
 
-                        [% IF borrower.get_club_enrollments_count.size || borrower.get_enrollable_clubs(1).size %]
+                        [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %]
                             <div id="opac-user-clubs">
                                 Loading...
                             </div>
index 1ca9321..ed426f9 100755 (executable)
@@ -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;