From 2110e545b247f1b6a488c448534c08b83a1309c1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 May 2017 15:49:51 -0300 Subject: [PATCH] Bug 18559: Koha::Clubs - Remove $return_scalar from parameters --- Koha/Clubs.pm | 20 ++++---------------- Koha/Patron.pm | 17 +++++------------ clubs/patron-clubs-tab.pl | 8 ++++---- .../prog/en/modules/circ/circulation.tt | 10 +++++----- .../prog/en/modules/clubs/patron-clubs-tab.tt | 4 ++-- .../prog/en/modules/members/moremember.tt | 6 +++--- .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 10 +++++----- opac/clubs/clubs-tab.pl | 8 ++++---- 8 files changed, 32 insertions(+), 51 deletions(-) diff --git a/Koha/Clubs.pm b/Koha/Clubs.pm index 7d62d2299b..9817af7195 100644 --- a/Koha/Clubs.pm +++ b/Koha/Clubs.pm @@ -50,9 +50,9 @@ sub get_enrollable { my $borrower = $params->{borrower}; if ($borrower) { delete( $params->{borrower} ); - my @enrollments = $borrower->get_club_enrollments(); - if (@enrollments) { - $params->{'me.id'} = { -not_in => [ map { $_->club()->id() } @enrollments ] }; + my $enrollments = $borrower->get_club_enrollments(); + if ($enrollments->count) { + $params->{'me.id'} = { -not_in => [ $enrollments->get_column('id') ] }; } } @@ -62,19 +62,7 @@ sub get_enrollable { -or => [ 'me.branchcode' => $borrower->branchcode, 'me.branchcode' => undef ] ]; - my $rs = $self->_resultset()->search( $params, { prefetch => 'club_template' } ); - - if (wantarray) { - my $class = ref($self) ? ref($self) : $self; - - return $class->_wrap( $rs->all() ); - - } - else { - my $class = ref($self) ? ref($self) : $self; - - return $class->_new_from_dbic($rs); - } + return $self->search( $params, { prefetch => 'club_template' } ); } =head3 type diff --git a/Koha/Patron.pm b/Koha/Patron.pm index b97bceb258..b6de71496f 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -600,13 +600,10 @@ sub first_valid_email_address { =cut sub get_club_enrollments { - my ( $self, $return_scalar ) = @_; - - my $e = Koha::Club::Enrollments->search( { borrowernumber => $self->borrowernumber(), date_canceled => undef } ); - - return $e if $return_scalar; + my ( $self ) = @_; - return wantarray ? $e->as_list : $e; + my $club_rs = $self->_result->club_enrollments->search( { date_canceled => undef } ); + return Koha::Club::Enrollments->_new_from_dbic($club_rs); } =head3 get_enrollable_clubs @@ -614,7 +611,7 @@ sub get_club_enrollments { =cut sub get_enrollable_clubs { - my ( $self, $is_enrollable_from_opac, $return_scalar ) = @_; + my ( $self, $is_enrollable_from_opac ) = @_; my $params; $params->{is_enrollable_from_opac} = $is_enrollable_from_opac @@ -623,11 +620,7 @@ sub get_enrollable_clubs { $params->{borrower} = $self; - my $e = Koha::Clubs->get_enrollable($params); - - return $e if $return_scalar; - - return wantarray ? $e->as_list : $e; + return Koha::Clubs->get_enrollable($params); } =head3 type diff --git a/clubs/patron-clubs-tab.pl b/clubs/patron-clubs-tab.pl index f50da65a5a..7c4fbf2f01 100755 --- a/clubs/patron-clubs-tab.pl +++ b/clubs/patron-clubs-tab.pl @@ -43,12 +43,12 @@ my $patronnumber = $cgi->param('borrowernumber'); my $patron = Koha::Patrons->find($patronnumber); -my @enrollments = $patron->get_club_enrollments(); -my @clubs = $patron->get_enrollable_clubs(); +my $enrollments = $patron->get_club_enrollments(); +my $clubs = $patron->get_enrollable_clubs(); $template->param( - enrollments => \@enrollments, - clubs => \@clubs, + enrollments => $enrollments, + clubs => $clubs, borrowernumber => $patronnumber ); 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 adfe9c02dd..7ae3669dcd 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(1) %] - [% SET enrollable = patron.get_enrollable_clubs(0,1) %] - [% IF CAN_user_clubs && ( enrollable.count || enrollments.count ) %] + [% SET nb_enrollments = patron.get_club_enrollments.count %] + [% SET nb_enrollable = patron.get_enrollable_clubs.count %] + [% IF CAN_user_clubs && ( nb_enrollable || nb_enrollments ) %]
  • - Clubs ([% enrollments.count %]/[% enrollable.count %]) + Clubs ([% nb_enrollments %]/[% nb_enrollable %])
  • [% END %] @@ -953,7 +953,7 @@ No patron matched [% message | html %] [% END %] -[% IF CAN_user_clubs && ( enrollable.count || enrollments.count ) %] +[% IF CAN_user_clubs && ( nb_enrollable|| nb_enrollments ) %]
    Loading...
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/patron-clubs-tab.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/patron-clubs-tab.tt index 30cb710724..df8ad4add4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/patron-clubs-tab.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/clubs/patron-clubs-tab.tt @@ -1,6 +1,6 @@ [% USE KohaDates %] -[% IF enrollments %] +[% IF enrollments.count %] @@ -35,7 +35,7 @@
    [% END %] -[% IF clubs %] +[% IF clubs.count %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index dc4ff75125..dc1e3ea643 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -524,9 +524,9 @@ function validate1(date) { [% END %]
  • [% debarments.size %] Restrictions
  • - [% SET enrollments = patron.get_club_enrollments(1) %] - [% SET enrollable = patron.get_enrollable_clubs(0,1) %] - [% IF CAN_user_clubs && ( enrollable.count || enrollments.count ) %] + [% SET nb_enrollments = patron.get_club_enrollments.count %] + [% SET nb_enrollable = patron.get_enrollable_clubs.count %] + [% IF CAN_user_clubs && ( nb_enrollable || nb_enrollments ) %]
  • Clubs ([% enrollments.count %]/[% enrollable.count %]) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index cded80d2e5..ffa872310a 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -4,8 +4,8 @@ [% USE ItemTypes %] [% USE Price %] -[% SET borrower_club_enrollments = borrower.get_club_enrollments(1) %] -[% SET borrower_enrollable_clubs = borrower.get_enrollable_clubs(1,1) %] +[% SET nb_club_enrollments = borrower.get_club_enrollments.count %] +[% SET nb_enrollable_clubs = borrower.get_enrollable_clubs(1).count %] [% INCLUDE 'doc-head-open.inc' %] [% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your library home @@ -139,10 +139,10 @@ Using this account is not recommended because some parts of Koha will not functi [% IF ( BORROWER_INFO.amountlessthanzero ) %]
  • Credits ([% amountoutstanding | $Price %])
  • [% END %] [% END %] - [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %] + [% IF nb_club_enrollments || borrower_enrollable_clubs %]
  • - Clubs ([% borrower_club_enrollments.count || 0 %]/[% borrower_enrollable_clubs.count || 0 %]) + Clubs ([% nb_club_enrollments %]/[% nb_enrollable_clubs %])
  • [% END %] @@ -343,7 +343,7 @@ Using this account is not recommended because some parts of Koha will not functi [% END # IF issues_count %] - [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %] + [% IF nb_club_enrollments || nb_enrollable_clubs %]
    Loading...
    diff --git a/opac/clubs/clubs-tab.pl b/opac/clubs/clubs-tab.pl index 82a4be0f54..4efb6e096b 100755 --- a/opac/clubs/clubs-tab.pl +++ b/opac/clubs/clubs-tab.pl @@ -40,12 +40,12 @@ my $borrowernumber = $cgi->param('borrowernumber'); my $borrower = Koha::Patrons->find($borrowernumber); -my @enrollments = $borrower->get_club_enrollments(); -my @clubs = $borrower->get_enrollable_clubs( my $opac = 1 ); +my $enrollments = $borrower->get_club_enrollments(); +my $clubs = $borrower->get_enrollable_clubs( my $opac = 1 ); $template->param( - enrollments => \@enrollments, - clubs => \@clubs, + enrollments => $enrollments, + clubs => $clubs, borrower => $borrower, ); -- 2.11.0