Bugzilla – Attachment 88141 Details for
Bug 22284
Add ability to define groups of locations for hold pickup
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22284: New methods in Koha::Library::Groups and Koha::Library
Bug-22284-New-methods-in-KohaLibraryGroups-and-Koh.patch (text/plain), 7.75 KB, created by
Agustín Moyano
on 2019-04-17 06:24:40 UTC
(
hide
)
Description:
Bug 22284: New methods in Koha::Library::Groups and Koha::Library
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2019-04-17 06:24:40 UTC
Size:
7.75 KB
patch
obsolete
>From 4e752538ba6b676e7b1e0450d91965fdaaa904ed Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Sun, 24 Mar 2019 23:00:36 -0300 >Subject: [PATCH] Bug 22284: New methods in Koha::Library::Groups and > Koha::Library > >This patch adds new methods in Koha::Library::Groups and Koha::Library. >1) For Koha::Library::Groups adds get_root_ancestor that returns all root >groups for a given search parameters, for example >Koha::Library::Groups->get_root_ancestor( { id => $group_id } ) >2) For Koha::Library adds >2.1) get_hold_libraries: returns all libraries (including self) that >belongs to the same holdgroups. If $self belongs to several holdgroups >it will return a distinct list of all libraries belonging to them. >2.2) validate_hold_sibling: Returns 1 if the given parameters matches any of the >libraries that belong to any of the holdgroups this library belongs. For example >$library->validate_hold_sibling( { branchcode => $branchcode } ) > >To test: >1) apply this patch >2) prove t/db_dependent/Koha/Libraries.t t/db_dependent/LibraryGroups.t >SUCCESS => green letters :-D >3) Sign off > >Sponsored-by: VOKAL >--- > Koha/Library.pm | 53 +++++++++++++++++++++++++++++++++++++++++ > Koha/Library/Groups.pm | 17 +++++++++++++ > t/db_dependent/Koha/Libraries.t | 35 ++++++++++++++++++++++++++- > t/db_dependent/LibraryGroups.t | 23 +++++++++++++++++- > 4 files changed, 126 insertions(+), 2 deletions(-) > >diff --git a/Koha/Library.pm b/Koha/Library.pm >index f1a5597305..fffc05b775 100644 >--- a/Koha/Library.pm >+++ b/Koha/Library.pm >@@ -25,6 +25,9 @@ use C4::Context; > > use Koha::Database; > use Koha::StockRotationStages; >+use Koha::Libraries; >+ >+use Data::Dumper qw(Dumper); > > use base qw(Koha::Object); > >@@ -77,6 +80,56 @@ sub library_groups { > return Koha::Library::Groups->_new_from_dbic( $rs ); > } > >+=head3 get_hold_libraries >+ >+Return all libraries (including self) that belong to the same hold groups >+ >+=cut >+ >+sub get_hold_libraries { >+ my ( $self ) = @_; >+ my $library_groups = $self->library_groups; >+ my @hold_libraries; >+ while ( my $library_group = $library_groups->next ) { >+ my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id}); >+ if($root->ft_local_hold_group) { >+ push @hold_libraries, $root->all_libraries; >+ } >+ } >+ >+ my %seen; >+ @hold_libraries = >+ grep { !$seen{ $_->id }++ } @hold_libraries; >+ >+ return @hold_libraries; >+} >+ >+=head3 validate_hold_sibling >+ >+Return if given library is a valid hold group member >+ >+=cut >+ >+sub validate_hold_sibling { >+ my ( $self, $params ) = @_; >+ my @hold_libraries = $self->get_hold_libraries; >+ >+ foreach (@hold_libraries) { >+ my $hold_library = $_; >+ my $cond = 1; >+ foreach my $key (keys %$params) { >+ unless($hold_library->$key eq $params->{$key}) { >+ $cond=0; >+ last; >+ } >+ } >+ if($cond) { >+ return 1; >+ } >+ } >+ return 0; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/Koha/Library/Groups.pm b/Koha/Library/Groups.pm >index 1ce2cb019a..ac0b6dc2ad 100644 >--- a/Koha/Library/Groups.pm >+++ b/Koha/Library/Groups.pm >@@ -65,6 +65,23 @@ sub get_search_groups { > return $self->search( { $field => 1 } ); > } > >+ >+=head3 get_root_ancestor >+ >+my $root_ancestor = $self->get_root_ancestor( {id => $group_id } ) >+ >+Retrieve root ancestor group for a specified id. >+ >+=cut >+ >+sub get_root_ancestor { >+ my ( $self, $params ) = @_; >+ my $row = $self->find($params); >+ return $row unless $row->parent_id; >+ return $self->get_root_ancestor( { id => $row->parent_id } ); >+} >+ >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t >index 5c356c1998..0b2f7271dd 100644 >--- a/t/db_dependent/Koha/Libraries.t >+++ b/t/db_dependent/Koha/Libraries.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > > use C4::Biblio; > use C4::Context; >@@ -451,3 +451,36 @@ subtest '->get_effective_marcorgcode' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'get_hold_libraries and validate_hold_sibling' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ >+ my $root = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); >+ my $g1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root->id, branchcode => $library1->branchcode } } ); >+ my $g2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root->id, branchcode => $library2->branchcode } } ); >+ >+ my @hold_libraries = ($library1, $library2); >+ >+ my @result = $library1->get_hold_libraries(); >+ >+ ok(scalar(@result) == 2, 'get_hold_libraries returns 2 libraries'); >+ >+ my %map = map {$_->branchcode, 1} @result; >+ >+ foreach my $hold_library ( @hold_libraries ) { >+ ok(exists $map{$hold_library->branchcode}, 'library in hold group'); >+ } >+ >+ ok($library1->validate_hold_sibling( { branchcode => $library2->branchcode } ), 'Library 2 is a valid hold sibling'); >+ ok(!$library1->validate_hold_sibling( { branchcode => $library3->branchcode } ), 'Library 3 is not a valid hold sibling'); >+ >+ $schema->storage->txn_rollback; >+ >+} >\ No newline at end of file >diff --git a/t/db_dependent/LibraryGroups.t b/t/db_dependent/LibraryGroups.t >index 69f9e9d4b7..4b917f58b6 100644 >--- a/t/db_dependent/LibraryGroups.t >+++ b/t/db_dependent/LibraryGroups.t >@@ -4,11 +4,13 @@ use Modern::Perl; > > use List::MoreUtils 'any'; > >-use Test::More tests => 20; >+use Test::More tests => 21; > > use t::lib::TestBuilder; > use Koha::Database; > >+use Data::Dumper; >+ > BEGIN { > use FindBin; > use lib $FindBin::Bin; >@@ -144,3 +146,22 @@ is( ref($groupX->libraries), 'Koha::Libraries', '->libraries should return a Koh > @group_branchcodes = sort( map { $_->branchcode } $groupX->all_libraries ); > is_deeply( \@branchcodes, \@group_branchcodes, "Group all_libraries are returned correctly" ); > is( ref(($groupX->all_libraries)[0]), 'Koha::Library', '->all_libraries should return a list of Koha::Library - in the future it should be fixed to return a Koha::Libraries iterator instead'); # FIXME >+ >+subtest 'Koha::Library::Groups->get_root_ancestor' => sub { >+ plan tests => 2; >+ >+ my $groupY = Koha::Library::Group->new( { title => "Group Y" } )->store(); >+ my $groupY_library1 = Koha::Library::Group->new({ parent_id => $groupY->id, branchcode => $library1->{branchcode} })->store(); >+ my $groupY1 = Koha::Library::Group->new( { parent_id => $groupY->id, title => "Group Y1" } )->store(); >+ my $groupY1_library2 = Koha::Library::Group->new({ parent_id => $groupY1->id, branchcode => $library2->{branchcode} })->store(); >+ my $groupZ = Koha::Library::Group->new({ title => "Group Z" })->store(); >+ my $groupZ1 = Koha::Library::Group->new({ parent_id => $groupZ->id, title => "Group Z1" })->store(); >+ my $groupZ2 = Koha::Library::Group->new({ parent_id => $groupZ1->id, title => "Group Z2" })->store(); >+ my $groupZ2_library2 = Koha::Library::Group->new({ parent_id => $groupZ2->id, branchcode => $library2->{branchcode} })->store(); >+ >+ my $ancestor1 = Koha::Library::Groups->get_root_ancestor($groupY1_library2->unblessed); >+ my $ancestor2 = Koha::Library::Groups->get_root_ancestor($groupZ2_library2->unblessed); >+ >+ is($ancestor1->id, $groupY->id, "Get root ancestor should return group's root ancestor"); >+ ok($ancestor1->id ne $ancestor2->id, "Both root groups should have different ids"); >+}; >\ No newline at end of file >-- >2.11.0
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 22284
:
88138
|
88139
|
88140
|
88141
|
88142
|
88143
|
88144
|
88145
|
88369
|
88561
|
88793
|
88794
|
88795
|
88796
|
88797
|
88798
|
88799
|
88800
|
88801
|
88802
|
88939
|
88940
|
88941
|
88942
|
88943
|
88944
|
88945
|
88946
|
88947
|
88948
|
88949
|
88955
|
88956
|
88957
|
88958
|
88959
|
88960
|
88961
|
88962
|
88963
|
88964
|
88965
|
89060
|
89061
|
89062
|
89063
|
89064
|
89065
|
89066
|
89067
|
89068
|
89069
|
89070
|
89071
|
89072
|
89073
|
89074
|
89075
|
89076
|
89077
|
89078
|
89079
|
89080
|
89081
|
89082
|
89083
|
89084
|
89085
|
89122
|
89123
|
89124
|
89125
|
89126
|
89127
|
89128
|
89129
|
89130
|
89131
|
89132
|
89133
|
89134
|
89135
|
89523
|
89836
|
89837
|
89838
|
89839
|
89840
|
89841
|
89842
|
89843
|
89844
|
89845
|
89846
|
89847
|
89848
|
89849
|
90133
|
90134
|
90197
|
90198
|
90199
|
90200
|
90201
|
90469
|
90525
|
91261
|
91262
|
91263
|
91264
|
91265
|
91266
|
91267
|
91268
|
91269
|
91270
|
91271
|
91272
|
91273
|
91274
|
91275
|
91276
|
91277
|
91278
|
91279
|
91280
|
91282
|
91701
|
91702
|
91703
|
91704
|
91705
|
91706
|
91707
|
91708
|
91709
|
91710
|
91711
|
91712
|
91713
|
91714
|
91715
|
91716
|
91717
|
91718
|
91719
|
91720
|
91721
|
91750
|
91751
|
91752
|
91753
|
91754
|
91755
|
91756
|
91757
|
91758
|
92554
|
92555
|
92556
|
92557
|
92558
|
92559
|
92560
|
92561
|
92562
|
92563
|
92564
|
92565
|
92566
|
92567
|
92568
|
92569
|
92570
|
92571
|
92572
|
92573
|
92574
|
92752
|
92753
|
92754
|
92755
|
92756
|
92757
|
92758
|
92759
|
92760
|
92761
|
92762
|
92763
|
92764
|
92849
|
92850
|
92851
|
92852
|
92853
|
92854
|
92855
|
92856
|
92857
|
92858
|
92859
|
92860
|
92861
|
94483
|
94484
|
94485
|
94486
|
94487
|
94488
|
94489
|
94490
|
94491
|
94492
|
94493
|
94494
|
94495
|
96437
|
96438
|
96439
|
96440
|
96441
|
96442
|
96443
|
96444
|
96445
|
96446
|
96447
|
96448
|
96449
|
96450
|
96544
|
96545
|
96546
|
96547
|
96548
|
96549
|
96550
|
96551
|
96552
|
96553
|
96554
|
96555
|
96556
|
96557
|
96558
|
115202