Bugzilla – Attachment 44252 Details for
Bug 14836
Move the patron categories related code to Koha::Patron::Categories - part 1
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 14836: Add Koha::PatronCategor[y|ies] classes
PASSED-QA-Bug-14836-Add-KohaPatronCategoryies-clas.patch (text/plain), 6.68 KB, created by
Kyle M Hall (khall)
on 2015-10-30 18:57:57 UTC
(
hide
)
Description:
[PASSED QA] Bug 14836: Add Koha::PatronCategor[y|ies] classes
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-10-30 18:57:57 UTC
Size:
6.68 KB
patch
obsolete
>From 54ac7ac89cd9d6d72b2737d6e203bc9076457828 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 16 Sep 2015 16:50:17 +0100 >Subject: [PATCH] [PASSED QA] Bug 14836: Add Koha::PatronCategor[y|ies] classes > >Note that some of the routines are retrieved from bug 10363 (branch >limitations). >They are not all used in these patch set, but they will permit to >replace the subroutines in C4::Form::MessagingPreferences, in the next >step. > >Signed-off-by: Frederic Demians <f.demians@tamil.fr> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/PatronCategories.pm | 50 ++++++++++++ > Koha/PatronCategory.pm | 188 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 238 insertions(+), 0 deletions(-) > create mode 100644 Koha/PatronCategories.pm > create mode 100644 Koha/PatronCategory.pm > >diff --git a/Koha/PatronCategories.pm b/Koha/PatronCategories.pm >new file mode 100644 >index 0000000..4ce65c3 >--- /dev/null >+++ b/Koha/PatronCategories.pm >@@ -0,0 +1,50 @@ >+package Koha::PatronCategories; >+ >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Carp; >+ >+use Koha::Database; >+ >+use Koha::PatronCategory; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::PatronCategories - Koha PatronCategory Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub type { >+ return 'Category'; >+} >+ >+sub object_class { >+ return 'Koha::PatronCategory'; >+} >+ >+1; >diff --git a/Koha/PatronCategory.pm b/Koha/PatronCategory.pm >new file mode 100644 >index 0000000..fbb9c8e >--- /dev/null >+++ b/Koha/PatronCategory.pm >@@ -0,0 +1,188 @@ >+package Koha::PatronCategory; >+ >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Carp; >+ >+use C4::Members::Messaging; >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::PatronCategory - Koha PatronCategory Object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 default_messaging >+ >+my $messaging = $category->default_messaging(); >+ >+=cut >+ >+sub default_messaging { >+ my ( $self ) = @_; >+ my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); >+ my @messaging; >+ foreach my $option (@$messaging_options) { >+ my $pref = C4::Members::Messaging::GetMessagingPreferences( >+ { >+ categorycode => $self->categorycode, >+ message_name => $option->{message_name} >+ } >+ ); >+ next unless $pref->{transports}; >+ my $brief_pref = { >+ message_attribute_id => $option->{message_attribute_id}, >+ message_name => $option->{message_name}, >+ $option->{'message_name'} => 1, >+ }; >+ foreach my $transport ( keys %{ $pref->{transports} } ) { >+ push @{ $brief_pref->{transports} }, { transport => $transport }; >+ } >+ push @messaging, $brief_pref; >+ } >+ return \@messaging; >+} >+ >+=head3 branch_limitations >+ >+my $limitations = $category->branch_limitations(); >+ >+$category->branch_limitations( \@branchcodes ); >+ >+=cut >+ >+sub branch_limitations { >+ my ( $self, $branchcodes ) = @_; >+ >+ if ($branchcodes) { >+ return $self->replace_branch_limitations($branchcodes); >+ } >+ else { >+ return $self->get_branch_limitations(); >+ } >+ >+} >+ >+=head3 get_branch_limitations >+ >+my $limitations = $category->get_branch_limitations(); >+ >+=cut >+ >+sub get_branch_limitations { >+ my ($self) = @_; >+ >+ my @branchcodes = >+ $self->_catb_resultset->search( { categorycode => $self->categorycode } ) >+ ->get_column('branchcode')->all(); >+ >+ return \@branchcodes; >+} >+ >+=head3 add_branch_limitation >+ >+$category->add_branch_limitation( $branchcode ); >+ >+=cut >+ >+sub add_branch_limitation { >+ my ( $self, $branchcode ) = @_; >+ >+ croak("No branchcode passed in!") unless $branchcode; >+ >+ my $limitation = $self->_catb_resultset->update_or_create( >+ { categorycode => $self->categorycode, branchcode => $branchcode } ); >+ >+ return $limitation ? 1 : undef; >+} >+ >+=head3 del_branch_limitation >+ >+$category->del_branch_limitation( $branchcode ); >+ >+=cut >+ >+sub del_branch_limitation { >+ my ( $self, $branchcode ) = @_; >+ >+ croak("No branchcode passed in!") unless $branchcode; >+ >+ my $limitation = >+ $self->_catb_resultset->find( >+ { categorycode => $self->categorycode, branchcode => $branchcode } ); >+ >+ unless ($limitation) { >+ my $categorycode = $self->categorycode; >+ carp( >+"No branch limit for branch $branchcode found for categorycode $categorycode to delete!" >+ ); >+ return; >+ } >+ >+ return $limitation->delete(); >+} >+ >+=head3 replace_branch_limitations >+ >+$category->replace_branch_limitations( \@branchcodes ); >+ >+=cut >+ >+sub replace_branch_limitations { >+ my ( $self, $branchcodes ) = @_; >+ >+ $self->_catb_resultset->search( { categorycode => $self->categorycode } )->delete; >+ >+ my @return_values = >+ map { $self->add_branch_limitation($_) } @$branchcodes; >+ >+ return \@return_values; >+} >+ >+=head3 Koha::Objects->_catb_resultset >+ >+Returns the internal resultset or creates it if undefined >+ >+=cut >+ >+sub _catb_resultset { >+ my ($self) = @_; >+ >+ $self->{_catb_resultset} ||= >+ Koha::Database->new->schema->resultset('CategoriesBranch'); >+ >+ return $self->{_catb_resultset}; >+} >+ >+=head3 type >+ >+=cut >+ >+sub type { >+ return 'Category'; >+} >+ >+1; >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14836
:
42616
|
42617
|
44059
|
44060
|
44061
|
44139
|
44140
|
44141
|
44142
|
44250
|
44251
| 44252 |
44253
|
44254
|
44255
|
44519