Bugzilla – Attachment 119504 Details for
Bug 23271
Koha::Patron::Category should use Koha::Object::Limit::Library
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23271: Use Koha::Object::Limit::Library for Koha::Patron::Categories
Bug-23271-Use-KohaObjectLimitLibrary-for-KohaPatro.patch (text/plain), 11.21 KB, created by
Jonathan Druart
on 2021-04-13 07:36:41 UTC
(
hide
)
Description:
Bug 23271: Use Koha::Object::Limit::Library for Koha::Patron::Categories
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-04-13 07:36:41 UTC
Size:
11.21 KB
patch
obsolete
>From 19725f70b99d3bf280845dc9153bc33981ba2ec4 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 16 Oct 2019 14:49:42 +0200 >Subject: [PATCH] Bug 23271: Use Koha::Object::Limit::Library for > Koha::Patron::Categories > >--- > Koha/Patron/Category.pm | 127 +++--------------- > admin/categories.pl | 23 +--- > .../prog/en/modules/admin/categories.tt | 32 +++-- > t/db_dependent/Koha/Patron/Categories.t | 7 +- > 4 files changed, 37 insertions(+), 152 deletions(-) > >diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm >index 7a4541ebc4c..713dcf92497 100644 >--- a/Koha/Patron/Category.pm >+++ b/Koha/Patron/Category.pm >@@ -25,7 +25,7 @@ use C4::Members::Messaging; > use Koha::Database; > use Koha::DateUtils; > >-use base qw(Koha::Object); >+use base qw(Koha::Object Koha::Object::Limit::Library); > > =head1 NAME > >@@ -103,117 +103,6 @@ sub default_messaging { > 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}; >-} >- > sub get_expiry_date { > my ($self, $date ) = @_; > if ( $self->enrolmentperiod ) { >@@ -299,6 +188,20 @@ sub override_hidden_items { > > =head2 Internal methods > >+=head3 _library_limits >+ >+ configure library limits >+ >+=cut >+ >+sub _library_limits { >+ return { >+ class => "CategoriesBranch", >+ id => "categorycode", >+ library => "branchcode", >+ }; >+} >+ > =head3 type > > =cut >diff --git a/admin/categories.pl b/admin/categories.pl >index 9bf5d365a1e..afc29504686 100755 >--- a/admin/categories.pl >+++ b/admin/categories.pl >@@ -48,26 +48,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > ); > > if ( $op eq 'add_form' ) { >- my ( $category, $selected_branches ); >- if ($categorycode) { >- $category = Koha::Patron::Categories->find($categorycode); >- $selected_branches = $category->branch_limitations; >- } >- >- my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; >- my @branches_loop; >- foreach my $branch ( @$branches ) { >- my $selected = ( grep { $_ eq $branch->{branchcode} } @$selected_branches ) ? 1 : 0; >- push @branches_loop, >- { branchcode => $branch->{branchcode}, >- branchname => $branch->{branchname}, >- selected => $selected, >- }; >- } > > $template->param( >- category => $category, >- branches_loop => \@branches_loop, >+ category => scalar Koha::Patron::Categories->find($categorycode), > ); > > if ( C4::Context->preference('EnhancedMessagingPreferences') ) { >@@ -138,7 +121,7 @@ elsif ( $op eq 'add_validate' ) { > $category->require_strong_password($require_strong_password); > eval { > $category->store; >- $category->replace_branch_limitations( \@branches ); >+ $category->replace_library_limits( \@branches ); > }; > if ( $@ ) { > push @messages, {type => 'error', code => 'error_on_update' }; >@@ -170,7 +153,7 @@ elsif ( $op eq 'add_validate' ) { > }); > eval { > $category->store; >- $category->replace_branch_limitations( \@branches ); >+ $category->replace_library_limits( \@branches ); > }; > > if ( $@ ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt >index 54831764e27..1a5faa0b6c2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt >@@ -1,6 +1,7 @@ > [% USE raw %] > [% USE Asset %] > [% USE Koha %] >+[% USE Branches %] > [% USE KohaDates %] > [% USE Price %] > [% USE TablesSettings %] >@@ -217,13 +218,7 @@ > <li><label for="branches">Library limitations: </label> > <select id="branches" name="branches" multiple size="10"> > <option value="">All libraries</option> >- [% FOREACH branch IN branches_loop %] >- [% IF branch.selected %] >- <option selected="selected" value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option> >- [% ELSE %] >- <option value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option> >- [% END %] >- [% END %] >+ [% PROCESS options_for_libraries libraries => Branches.all( selecteds => category.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %] > </select> > <span>Select <em>All libraries</em> if this category type must to be displayed all the time. Otherwise select libraries you want to associate with this value. > </span> >@@ -613,19 +608,22 @@ > </td> > [% END %] > <td> >- [% SET branch_limitations = category.branch_limitations %] >- [% IF branch_limitations.size > 0 %] >- [% branches_str = "" %] >- [% FOREACH branch IN branch_limitations %] >- [% branches_str = branches_str _ " " _ branch.branchname _ "(" _ branch.branchcode _ ")" %] >+ [% SET library_limits = category.library_limits %] >+ [% IF library_limits.count > 0 %] >+ [% library_str = "" %] >+ [% FOREACH library IN library_limits %] >+ [%- IF loop.first -%] >+ [% library_str = library.branchname _ " (" _ library.branchcode _ ")" %] >+ [% ELSE %] >+ [% library_str = library_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %] >+ [% END %] > [% END %] >- <span title="[% branches_str | html %]"> >- [% IF branch_limitations.size > 1 %] >- [% branch_limitations.size | html %] library limitations >+ <span class="library_limitation" title="[% library_str | html %]"> >+ [% IF library_limits.count > 1 %] >+ [% library_limits.count | html %] library limitations > [% ELSE %] >- [% branch_limitations.size | html %] library limitation >+ [% library_limits.count | html %] library limitation > [% END %] >- </span> > [% ELSE %] > No limitation > [% END %] >diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t >index 58882a493e7..112c6990660 100755 >--- a/t/db_dependent/Koha/Patron/Categories.t >+++ b/t/db_dependent/Koha/Patron/Categories.t >@@ -34,14 +34,15 @@ my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; > > my $builder = t::lib::TestBuilder->new; >-my $branch = $builder->build({ source => 'Branch', }); >+my $library_1 = $builder->build_object({ class => 'Koha::Libraries', }); >+my $library_2 = $builder->build_object({ class => 'Koha::Libraries', }); > my $nb_of_categories = Koha::Patron::Categories->search->count; > my $new_category_1 = Koha::Patron::Category->new({ > categorycode => 'mycatcodeX', > category_type => 'A', > description => 'mycatdescX', > })->store; >-$new_category_1->add_branch_limitation( $branch->{branchcode} ); >+$new_category_1->replace_library_limits( [ $library_1->branchcode, $library_2->branchcode ] ); > my $new_category_2 = Koha::Patron::Category->new({ > categorycode => 'mycatcodeY', > category_type => 'S', >@@ -53,7 +54,7 @@ is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'The 2 patro > > my $retrieved_category_1 = Koha::Patron::Categories->find( $new_category_1->categorycode ); > is( $retrieved_category_1->categorycode, $new_category_1->categorycode, 'Find a patron category by categorycode should return the correct category' ); >-is_deeply( $retrieved_category_1->branch_limitations, [ $branch->{branchcode} ], 'The branch limitation should have been stored and retrieved' ); >+is_deeply( [ $retrieved_category_1->library_limits->get_column('branchcode') ], [ $library_1->branchcode, $library_2->branchcode ], 'The branch limitation should have been stored and retrieved' ); > is_deeply( $retrieved_category_1->default_messaging, [], 'By default there is not messaging option' ); > > my $retrieved_category_2 = Koha::Patron::Categories->find( $new_category_2->categorycode ); >-- >2.20.1
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 23271
:
94292
|
94293
|
94294
|
119503
|
119504
|
119505
|
119529
|
119530
|
119531
|
119532
|
119533
|
119537
|
119579
|
119580
|
119581
|
119582
|
119583
|
119584
|
119772
|
119773
|
119774
|
119775
|
119776
|
119777
|
119939
|
119956
|
119957
|
120054