Bugzilla – Attachment 139369 Details for
Bug 29144
Move branches.opac_info to AdditionalContents allowing multi language
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29144: Add $contents->find_best_match, $library->opac_info
Bug-29144-Add-contents-findbestmatch-library-opaci.patch (text/plain), 7.57 KB, created by
Martin Renvoize (ashimema)
on 2022-08-18 12:54:31 UTC
(
hide
)
Description:
Bug 29144: Add $contents->find_best_match, $library->opac_info
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-08-18 12:54:31 UTC
Size:
7.57 KB
patch
obsolete
>From 565e3739214f7503a9486a59d676e4095ca76e94 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Tue, 2 Aug 2022 11:54:59 +0000 >Subject: [PATCH] Bug 29144: Add $contents->find_best_match, > $library->opac_info > >Test plan: >Run t/db_dependent/Koha/AdditionalContents.t >Run t/db_dependent/Koha/Library.t > >Note: You may need to set ListOwnershipUponPatronDeletion to >delete to fix a pending issue in patron->delete with lists. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/AdditionalContents.pm | 35 +++++++++++++++++++++ > Koha/Library.pm | 20 ++++++++++++ > t/db_dependent/Koha/AdditionalContents.t | 29 ++++++++++++++++- > t/db_dependent/Koha/Library.t | 40 +++++++++++++++++++++++- > 4 files changed, 122 insertions(+), 2 deletions(-) > >diff --git a/Koha/AdditionalContents.pm b/Koha/AdditionalContents.pm >index a33152b3ee..3ed9f42f41 100644 >--- a/Koha/AdditionalContents.pm >+++ b/Koha/AdditionalContents.pm >@@ -110,6 +110,41 @@ sub search_for_display { > return $self->SUPER::search({%$search_params, lang => 'default'}, { order_by => 'number'}); > } > >+=head3 find_best_match >+ >+ Koha::AdditionalContents->find_best_match({ >+ category => , location => , lang => , library_id => >+ }); >+ >+ When choosing the best match, a match on lang and library is preferred. >+ Next a match on library and default lang. Then match on All libs and lang. >+ Finally a match with All libs and default lang. >+ >+=cut >+ >+sub find_best_match { >+ my ( $self, $params ) = @_; >+ my $library_id = $params->{library_id}; >+ my $lang = $params->{lang}; >+ >+ my $rs = $self->SUPER::search({ >+ category => $params->{category}, >+ location => $params->{location}, >+ lang => [ $lang, 'default' ], >+ branchcode => [ $library_id, undef ], >+ }); >+ >+ # Pick the best >+ my ( $alt1, $alt2, $alt3 ); >+ while( my $rec = $rs->next ) { >+ return $rec if $library_id && $rec->branchcode && $rec->branchcode eq $library_id && $lang && $rec->lang eq $lang; >+ $alt1 = $rec if !$alt1 && $library_id && $rec->branchcode && $rec->branchcode eq $library_id; >+ $alt2 = $rec if !$alt2 && $lang && $rec->lang eq $lang; >+ $alt3 = $rec if !$alt3; >+ } >+ return $alt1 // $alt2 // $alt3; >+} >+ > =head3 _type > > =cut >diff --git a/Koha/Library.pm b/Koha/Library.pm >index 48e125529b..20db2ca632 100644 >--- a/Koha/Library.pm >+++ b/Koha/Library.pm >@@ -313,6 +313,26 @@ sub to_api_mapping { > }; > } > >+=head3 opac_info >+ >+ $library->opac_info({ lang => $lang }); >+ >+Returns additional contents block OpacLibraryInfo for $lang or 'default'. >+ >+Note: This replaces the former branches.opac_info column. >+ >+=cut >+ >+sub opac_info { >+ my ( $self, $params ) = @_; >+ return Koha::AdditionalContents->find_best_match({ >+ category => 'html_customizations', >+ location => 'OpacLibraryInfo', >+ lang => $params->{lang}, >+ library_id => $self->branchcode, >+ }); >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/t/db_dependent/Koha/AdditionalContents.t b/t/db_dependent/Koha/AdditionalContents.t >index bf515b1af1..67094cd48b 100755 >--- a/t/db_dependent/Koha/AdditionalContents.t >+++ b/t/db_dependent/Koha/AdditionalContents.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > use Test::Exception; > > use Koha::AdditionalContents; >@@ -259,3 +259,30 @@ subtest '->search_for_display' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'find_best_match' => sub { >+ plan tests => 3; >+ $schema->storage->txn_begin; >+ >+ my $library01 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $html01 = $builder->build_object({ >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'default' }, >+ }); >+ my $params = { category => 'html_customizations', location => 'test_best_match', lang => 'nl-NL' }; >+ is( Koha::AdditionalContents->find_best_match($params)->idnew, $html01->idnew, 'Found all branches, lang default' ); >+ >+ my $html02 = $builder->build_object({ >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'nl-NL' }, >+ }); >+ is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found all branches, lang nl-NL' ); >+ >+ $params->{ library_id } = $library01->id; >+ $html02->branchcode( $library01->id )->store; >+ is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found library01, lang nl-NL' ); >+ >+ # Note: find_best_match is tested further via $libary->opac_info; see t/db_dependent/Koha/Library.t >+ >+ $schema->storage->txn_rollback; >+} >diff --git a/t/db_dependent/Koha/Library.t b/t/db_dependent/Koha/Library.t >index 23e88578b3..c6637ddfd9 100755 >--- a/t/db_dependent/Koha/Library.t >+++ b/t/db_dependent/Koha/Library.t >@@ -19,9 +19,10 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; > > use Koha::Database; >+use Koha::AdditionalContents; > use Koha::SMTP::Servers; > > use t::lib::TestBuilder; >@@ -93,3 +94,40 @@ subtest 'smtp_server() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'opac_info tests' => sub { >+ plan tests => 8; >+ $schema->storage->txn_begin; >+ my $library01 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library02 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ my $html01 = $builder->build_object({ >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'default', content => '1', expirationdate => undef }, >+ }); >+ my $html02 = $builder->build_object({ >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'default', content => '2', expirationdate => undef }, >+ }); >+ my $html03 = $builder->build_object({ >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => $library01->id, lang => 'nl-NL', content => '3', expirationdate => undef }, >+ }); >+ my $html04 = $builder->build_object({ >+ class => 'Koha::AdditionalContents', >+ value => { category => 'html_customizations', location => 'OpacLibraryInfo', branchcode => undef, lang => 'fr-FR', content => '4', expirationdate => undef }, >+ }); >+ >+ # Start testing >+ is( $library01->opac_info->content, '2', 'specific library, default language' ); >+ is( $library01->opac_info({ lang => 'nl-NL' })->content, '3', 'specific library, specific language' ); >+ is( $library01->opac_info({ lang => 'nl-BE' })->content, '2', 'specific library, unknown language' ); >+ is( $library02->opac_info->content, '1', 'unknown library, default language' ); >+ is( $library02->opac_info({ lang => 'fr-FR' })->content, '4', 'unknown library, specific language' ); >+ is( $library02->opac_info({ lang => 'de-DE' })->content, '1', 'unknown library, unknown language' ); >+ $html01->delete; >+ is( $library02->opac_info, undef, 'unknown library, default language (after removing html01)' ); >+ is( $library02->opac_info({ lang => 'de-DE' }), undef, 'unknown library, unknown language (after removing html01)' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >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 29144
:
138473
|
138474
|
138527
|
138528
|
138599
|
138600
|
138601
|
138602
|
138603
|
138604
|
138605
|
138606
|
138607
|
138608
|
138609
|
139182
|
139183
|
139184
|
139185
|
139186
|
139187
|
139188
|
139189
|
139190
|
139191
|
139192
|
139197
|
139198
|
139199
|
139200
|
139201
|
139202
|
139203
|
139204
|
139205
|
139206
|
139207
|
139208
|
139366
|
139367
|
139368
|
139369
|
139370
|
139371
|
139372
|
139373
|
139374
|
139375
|
139376
|
139377
|
140020
|
140021
|
140022
|
140023
|
140024
|
140025
|
140026
|
140027
|
140028
|
140029
|
140030
|
140707