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

(-)a/C4/Search.pm (-1 / +10 lines)
Lines 2069-2075 sub searchResults { Link Here
2069
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
2069
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
2070
        }
2070
        }
2071
2071
2072
        $oldbiblio->{biblio_object} = Koha::Biblios->find( $oldbiblio->{biblionumber} );
2072
        if (
2073
            ( C4::Context->preference('CustomCoverImages') || C4::Context->preference('OPACCustomCoverIMages') )             && C4::Context->preference('CustomCoverImagesURL')
2074
        ){
2075
                $oldbiblio->{custom_cover_image_url} = Koha::Biblio->custom_cover_image_url({
2076
                    isbn => $oldbiblio->{isbn},
2077
                    normalized_isbn => $oldbiblio->{normalized_isbn},
2078
                    issn => $oldbiblio->{issn},
2079
                    record => $marcrecord
2080
                });
2081
        }
2073
2082
2074
        push( @newresults, $oldbiblio );
2083
        push( @newresults, $oldbiblio );
2075
    }
2084
    }
(-)a/Koha/Biblio.pm (-5 / +7 lines)
Lines 754-773 It is built regaring the value of the system preference CustomCoverImagesURL Link Here
754
=cut
754
=cut
755
755
756
sub custom_cover_image_url {
756
sub custom_cover_image_url {
757
    my ( $self ) = @_;
757
    my ( $self, $params ) = @_;
758
    return unless (ref $self || $params);
759
758
    my $url = C4::Context->preference('CustomCoverImagesURL');
760
    my $url = C4::Context->preference('CustomCoverImagesURL');
759
    if ( $url =~ m|{isbn}| ) {
761
    if ( $url =~ m|{isbn}| ) {
760
        my $isbn = $self->biblioitem->isbn;
762
        my $isbn = $params->{isbn} // $self->biblioitem->isbn;
761
        return unless $isbn;
763
        return unless $isbn;
762
        $url =~ s|{isbn}|$isbn|g;
764
        $url =~ s|{isbn}|$isbn|g;
763
    }
765
    }
764
    if ( $url =~ m|{normalized_isbn}| ) {
766
    if ( $url =~ m|{normalized_isbn}| ) {
765
        my $normalized_isbn = C4::Koha::GetNormalizedISBN($self->biblioitem->isbn);
767
        my $normalized_isbn =  $params->{normalized_isbn} // C4::Koha::GetNormalizedISBN($self->biblioitem->isbn);
766
        return unless $normalized_isbn;
768
        return unless $normalized_isbn;
767
        $url =~ s|{normalized_isbn}|$normalized_isbn|g;
769
        $url =~ s|{normalized_isbn}|$normalized_isbn|g;
768
    }
770
    }
769
    if ( $url =~ m|{issn}| ) {
771
    if ( $url =~ m|{issn}| ) {
770
        my $issn = $self->biblioitem->issn;
772
        my $issn = $params->{issn} // $self->biblioitem->issn;
771
        return unless $issn;
773
        return unless $issn;
772
        $url =~ s|{issn}|$issn|g;
774
        $url =~ s|{issn}|$issn|g;
773
    }
775
    }
Lines 776-782 sub custom_cover_image_url { Link Here
776
    if ( $url =~ $re ) {
778
    if ( $url =~ $re ) {
777
        my $field = $+{field};
779
        my $field = $+{field};
778
        my $subfield = $+{subfield};
780
        my $subfield = $+{subfield};
779
        my $marc_record = $self->metadata->record;
781
        my $marc_record = $params->{record}// $self->metadata->record;
780
        my $value = $marc_record->subfield($field, $subfield);
782
        my $value = $marc_record->subfield($field, $subfield);
781
        return unless $value;
783
        return unless $value;
782
        $url =~ s|$re|$value|;
784
        $url =~ s|$re|$value|;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt (-1 / +1 lines)
Lines 476-482 Link Here
476
            [% END %]
476
            [% END %]
477
477
478
            [% IF Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL') %]
478
            [% IF Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL') %]
479
                [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %]
479
                [% SET custom_cover_image_url = SEARCH_RESULT.custom_cover_image_url %]
480
                [% IF custom_cover_image_url %]
480
                [% IF custom_cover_image_url %]
481
                    <div id="custom-coverimg-[% SEARCH_RESULT.biblionumber | html %]" class="cover-image custom-coverimg">
481
                    <div id="custom-coverimg-[% SEARCH_RESULT.biblionumber | html %]" class="cover-image custom-coverimg">
482
                        <a class="custom_cover_image" href="[% custom_cover_image_url | url %]">
482
                        <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 66-72 Link Here
66
[% 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 %]
66
[% 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 %]
67
67
68
[% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
68
[% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
69
    [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %]
69
    [% SET custom_cover_image_url = SEARCH_RESULT.custom_cover_image_url %]
70
    [% IF custom_cover_image_url %]
70
    [% IF custom_cover_image_url %]
71
        <img alt="Cover image" src="[% custom_cover_image_url | url %]" />
71
        <img alt="Cover image" src="[% custom_cover_image_url | url %]" />
72
    [% END %]
72
    [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (-1 / +1 lines)
Lines 431-437 Link Here
431
                                                    [% END %]
431
                                                    [% END %]
432
432
433
                                                    [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
433
                                                    [% IF Koha.Preference('OPACCustomCoverImages') AND Koha.Preference('CustomCoverImagesURL') %]
434
                                                        [% SET custom_cover_image_url = SEARCH_RESULT.biblio_object.custom_cover_image_url %]
434
                                                        [% SET custom_cover_image_url = SEARCH_RESULT.custom_cover_image_url %]
435
                                                        [% IF custom_cover_image_url %]
435
                                                        [% IF custom_cover_image_url %]
436
                                                            [% IF ( OPACURLOpenInNewWindow ) %]
436
                                                            [% IF ( OPACURLOpenInNewWindow ) %]
437
                                                                <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>
437
                                                                <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-225 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 => 4;
196
    plan tests => 8;
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 $marc_record = MARC::Record->new;
203
    my $marc_record = MARC::Record->new;
203
    my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
204
    my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
204
205
206
    my $custom_cover_image_url;
207
205
    my $biblio = Koha::Biblios->find( $biblionumber );
208
    my $biblio = Koha::Biblios->find( $biblionumber );
206
    my $biblioitem = $biblio->biblioitem->set(
209
    my $biblioitem = $biblio->biblioitem->set(
207
        { isbn => $isbn, issn => $issn });
210
        { isbn => $isbn, issn => $issn });
208
    is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png" );
211
    is( $biblio->custom_cover_image_url, "https://my_url/${isbn}_${issn}.png", "URL is correctly generated for isbn and issbn when called as object" );
212
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
213
        isbn => $isbn,
214
        issn => $issn,
215
        record => $marc_record,
216
        normalized_isbn => $normalized_isbn
217
    });
218
    is( $custom_cover_image_url, "https://my_url/${isbn}_${issn}.png", "URL is correctly generated for isbn and issn when values passed as parameters" );
219
209
220
210
    my $marc_024a = '710347104926';
221
    my $marc_024a = '710347104926';
211
    $marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) );
222
    $marc_record->append_fields( MARC::Field->new( '024', '', '', a => $marc_024a ) );
212
    C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
223
    C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
213
224
214
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{024$a}.png' );
225
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{024$a}.png' );
215
    is( $biblio->custom_cover_image_url, "https://my_url/$marc_024a.png" );
226
    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" );
227
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
228
        isbn => $isbn,
229
        issn => $issn,
230
        record => $marc_record,
231
        normalized_isbn => $normalized_isbn
232
    });
233
    is( $custom_cover_image_url, "https://my_url/$marc_024a.png", "URL is correctly generated using a custom fieldwhen parameters passed" );
216
234
217
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' );
235
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{normalized_isbn}.png' );
218
    my $normalized_isbn = C4::Koha::GetNormalizedISBN($isbn);
236
    is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png", "URL correctly generated using normalized ISBN when called as object method" );
219
    is( $biblio->custom_cover_image_url, "https://my_url/$normalized_isbn.png" );
237
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
238
        isbn => $isbn,
239
        issn => $issn,
240
        record => $marc_record,
241
        normalized_isbn => $normalized_isbn
242
    });
243
    is( $custom_cover_image_url, "https://my_url/$normalized_isbn.png", "URL correctly generated using normalized ISBN when passed parameters" );
220
244
221
    $biblio->biblioitem->isbn('')->store;
245
    $biblio->biblioitem->isbn('')->store;
222
    is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
246
    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
    $custom_cover_image_url = Koha::Biblio->custom_cover_image_url({
248
        isbn => $isbn,
249
        issn => $issn,
250
        record => $marc_record,
251
        normalized_isbn => ''
252
    });
253
    is( $custom_cover_image_url, undef, "Don't generate the url if the value needed to generate it is not passed" );
223
254
224
};
255
};
225
256
226
- 

Return to bug 28709