View | Details | Raw Unified | Return to bug 28709
Collapse All | Expand All

(-)a/C4/Search.pm (+19 lines)
Lines 2045-2050 sub searchResults { Link Here
2045
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
2045
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
2046
        }
2046
        }
2047
2047
2048
        if (
2049
            (
2050
                   C4::Context->preference('CustomCoverImages')
2051
                || C4::Context->preference('OPACCustomCoverIMages')
2052
            )
2053
            && C4::Context->preference('CustomCoverImagesURL')
2054
          )
2055
        {
2056
            $oldbiblio->{custom_cover_image_url} =
2057
              Koha::Biblio->custom_cover_image_url(
2058
                {
2059
                    isbn            => $oldbiblio->{isbn} // "",
2060
                    normalized_isbn => $oldbiblio->{normalized_isbn} // "",
2061
                    issn            => $oldbiblio->{issn} // "",
2062
                    record          => $marcrecord
2063
                }
2064
              );
2065
        }
2066
2048
        push( @newresults, $oldbiblio );
2067
        push( @newresults, $oldbiblio );
2049
    }
2068
    }
2050
2069
(-)a/Koha/Biblio.pm (-5 / +7 lines)
Lines 859-878 It is built regaring the value of the system preference CustomCoverImagesURL Link Here
859
=cut
859
=cut
860
860
861
sub custom_cover_image_url {
861
sub custom_cover_image_url {
862
    my ( $self ) = @_;
862
    my ( $self, $params ) = @_;
863
    return unless (ref $self || $params);
864
863
    my $url = C4::Context->preference('CustomCoverImagesURL');
865
    my $url = C4::Context->preference('CustomCoverImagesURL');
864
    if ( $url =~ m|{isbn}| ) {
866
    if ( $url =~ m|{isbn}| ) {
865
        my $isbn = $self->biblioitem->isbn;
867
        my $isbn = $params->{isbn} // $self->biblioitem->isbn;
866
        return unless $isbn;
868
        return unless $isbn;
867
        $url =~ s|{isbn}|$isbn|g;
869
        $url =~ s|{isbn}|$isbn|g;
868
    }
870
    }
869
    if ( $url =~ m|{normalized_isbn}| ) {
871
    if ( $url =~ m|{normalized_isbn}| ) {
870
        my $normalized_isbn = C4::Koha::GetNormalizedISBN($self->biblioitem->isbn);
872
        my $normalized_isbn =  $params->{normalized_isbn} // C4::Koha::GetNormalizedISBN($self->biblioitem->isbn);
871
        return unless $normalized_isbn;
873
        return unless $normalized_isbn;
872
        $url =~ s|{normalized_isbn}|$normalized_isbn|g;
874
        $url =~ s|{normalized_isbn}|$normalized_isbn|g;
873
    }
875
    }
874
    if ( $url =~ m|{issn}| ) {
876
    if ( $url =~ m|{issn}| ) {
875
        my $issn = $self->biblioitem->issn;
877
        my $issn = $params->{issn} // $self->biblioitem->issn;
876
        return unless $issn;
878
        return unless $issn;
877
        $url =~ s|{issn}|$issn|g;
879
        $url =~ s|{issn}|$issn|g;
878
    }
880
    }
Lines 881-887 sub custom_cover_image_url { Link Here
881
    if ( $url =~ $re ) {
883
    if ( $url =~ $re ) {
882
        my $field = $+{field};
884
        my $field = $+{field};
883
        my $subfield = $+{subfield};
885
        my $subfield = $+{subfield};
884
        my $marc_record = $self->metadata->record;
886
        my $marc_record = $params->{record} // $self->metadata->record;
885
        my $value;
887
        my $value;
886
        if ( $subfield ) {
888
        if ( $subfield ) {
887
            $value = $marc_record->subfield( $field, $subfield );
889
            $value = $marc_record->subfield( $field, $subfield );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt (-1 / +1 lines)
Lines 467-473 Link Here
467
            [% END %]
467
            [% END %]
468
468
469
            [% IF Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL') %]
469
            [% IF Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL') %]
470
                [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %]
470
                [% SET custom_cover_image_url = SEARCH_RESULT.custom_cover_image_url %]
471
                [% IF custom_cover_image_url %]
471
                [% IF custom_cover_image_url %]
472
                    <div id="custom-coverimg-[% SEARCH_RESULT.biblionumber | html %]" class="cover-image custom-coverimg">
472
                    <div id="custom-coverimg-[% SEARCH_RESULT.biblionumber | html %]" class="cover-image custom-coverimg">
473
                        <a class="custom_cover_image" href="[% custom_cover_image_url | url %]">
473
                        <a class="custom_cover_image" href="[% custom_cover_image_url | url %]">
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt (-1 / +1 lines)
Lines 61-67 Link Here
61
[% IF ( BakerTaylorEnabled ) %][% IF bt_id %]<a href="https://[% BakerTaylorBookstoreURL |url %][% bt_id | uri %]"><img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL |url %][% bt_id | uri %]" /></a>[% END %][% END %]
61
[% IF ( BakerTaylorEnabled ) %][% IF bt_id %]<a href="https://[% BakerTaylorBookstoreURL |url %][% bt_id | uri %]"><img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL |url %][% bt_id | uri %]" /></a>[% END %][% END %]
62
62
63
[% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
63
[% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
64
    [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %]
64
    [% SET custom_cover_image_url = SEARCH_RESULT.custom_cover_image_url %]
65
    [% IF custom_cover_image_url %]
65
    [% IF custom_cover_image_url %]
66
        <img alt="Cover image" src="[% custom_cover_image_url | url %]" />
66
        <img alt="Cover image" src="[% custom_cover_image_url | url %]" />
67
    [% END %]
67
    [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (-1 / +1 lines)
Lines 423-429 Link Here
423
                                                    [% END %]
423
                                                    [% END %]
424
424
425
                                                    [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
425
                                                    [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
426
                                                        [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %]
426
                                                        [% SET custom_cover_image_url = SEARCH_RESULT.custom_cover_image_url %]
427
                                                        [% IF custom_cover_image_url %]
427
                                                        [% IF custom_cover_image_url %]
428
                                                            [% IF ( OPACURLOpenInNewWindow ) %]
428
                                                            [% IF ( OPACURLOpenInNewWindow ) %]
429
                                                                <a class="custom_cover_image" href="[% custom_cover_image_url | url %]" target="_blank" rel="noreferrer"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a>
429
                                                                <a class="custom_cover_image" href="[% custom_cover_image_url | url %]" target="_blank" rel="noreferrer"><img alt="Cover image" src="[% custom_cover_image_url | url %]" /></a>
(-)a/t/db_dependent/Koha/Biblios.t (-6 / +36 lines)
Lines 193-226 subtest 'can_be_transferred' => sub { Link Here
193
};
193
};
194
194
195
subtest 'custom_cover_image_url' => sub {
195
subtest 'custom_cover_image_url' => sub {
196
    plan tests => 6;
196
    plan tests => 10;
197
197
198
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' );
198
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' );
199
199
200
    my $isbn       = '0553573403 | 9780553573404 (pbk.).png';
200
    my $isbn       = '0553573403 | 9780553573404 (pbk.).png';
201
    my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn);
201
    my $issn       = 'my_issn';
202
    my $issn       = 'my_issn';
202
    my $cf_value   = 'from_control_field';
203
    my $cf_value   = 'from_control_field';
203
    my $marc_record = MARC::Record->new;
204
    my $marc_record = MARC::Record->new;
204
    my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
205
    my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
205
206
207
    my $custom_cover_image_url;
208
206
    my $biblio = Koha::Biblios->find( $biblionumber );
209
    my $biblio = Koha::Biblios->find( $biblionumber );
207
    my $biblioitem = $biblio->biblioitem->set(
210
    my $biblioitem = $biblio->biblioitem->set(
208
        { isbn => $isbn, issn => $issn });
211
        { isbn => $isbn, issn => $issn });
209
    is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png" );
212
    is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png", "URL is correctly generated for isbn and issbn when called as object" );
213
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
214
        isbn => $isbn,
215
        issn => $issn,
216
        record => $marc_record,
217
        normalized_isbn => $normalized_isbn
218
    });
219
    is( $custom_cover_image_url, "https://my_url/${isbn}_${issn}.png", "URL is correctly generated for isbn and issn when values passed as parameters" );
220
210
221
211
    my $marc_024a = '710347104926';
222
    my $marc_024a = '710347104926';
212
    $marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) );
223
    $marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) );
213
    C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
224
    C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
214
225
215
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{024$a}.png' );
226
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{024$a}.png' );
216
    is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png" );
227
    is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png", "URL is correctly generated using a custom field when called as object method" );
228
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
229
        isbn => $isbn,
230
        issn => $issn,
231
        record => $marc_record,
232
        normalized_isbn => $normalized_isbn
233
    });
234
    is( $custom_cover_image_url, "https://my_url/$marc_024a.png", "URL is correctly generated using a custom fieldwhen parameters passed" );
217
235
218
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' );
236
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' );
219
    my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn);
237
    is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png", "URL correctly generated using normalized ISBN when called as object method" );
220
    is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png" );
238
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
239
        isbn => $isbn,
240
        issn => $issn,
241
        record => $marc_record,
242
        normalized_isbn => $normalized_isbn
243
    });
244
    is( $custom_cover_image_url, "https://my_url/$normalized_isbn.png", "URL correctly generated using normalized ISBN when passed parameters" );
221
245
222
    $biblio->biblioitem->isbn('')->store;
246
    $biblio->biblioitem->isbn('')->store;
223
    is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
247
    is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
248
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
249
        isbn => $isbn,
250
        issn => $issn,
251
        record => $marc_record,
252
        normalized_isbn => ''
253
    });
254
    is( $custom_cover_image_url, undef, "Don't generate the url if the value needed to generate it is not passed" );
224
255
225
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{001}.png' );
256
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{001}.png' );
226
    is( $biblio->custom_cover_image_url, undef, 'Record does not have 001' );
257
    is( $biblio->custom_cover_image_url, undef, 'Record does not have 001' );
227
- 

Return to bug 28709