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
use Koha::Database;
use Koha::Clubs;
+use Koha::Patrons;
use base qw(Koha::Object);
return Koha::Clubs->find( $self->club_id() );
}
+=head3 patron
+
+=cut
+
+sub patron {
+ my ( $self ) = @_;
+ return Koha::Patrons->find( $self->borrowernumber() );
+}
+
=head3 type
=cut
}
}
+ # 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) {
=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
=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
$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
--- /dev/null
+#!/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 );
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);
[% 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 %]
</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 -->
--- /dev/null
+[% USE KohaDates %]
+[% USE Branches %]
+[% USE Koha %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha › Tools › Patron clubs › 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> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › Patron clubs › 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> </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' %]
+[% 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> </th>
<th> </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 %]
[% 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>
</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 %]
<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>
[% 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>
[% 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 › Your library home</title>
[% INCLUDE 'doc-head-close.inc' %]
[% 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 %]
[% 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>
use Modern::Perl;
-use Test::More tests => 36;
+use Test::More tests => 37;
use Test::Warn;
use C4::Context;
club_template_id => $club_template->id,
name => "Test Club",
branchcode => $branchcode,
+ date_start => '1900-01-01',
+ date_end => '9999-01-01',
}
)->store();
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;