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

(-)a/C4/Search.pm (-1 / +10 lines)
Lines 2064-2070 sub searchResults { Link Here
2064
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
2064
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
2065
        }
2065
        }
2066
2066
2067
        $oldbiblio->{biblio_object} = Koha::Biblios->find( $oldbiblio->{biblionumber} );
2067
        if (
2068
            ( C4::Context->preference('CustomCoverImages') || C4::Context->preference('OPACCustomCoverIMages') )             && C4::Context->preference('CustomCoverImagesURL')
2069
        ){
2070
                $oldbiblio->{custom_cover_image_url} = Koha::Biblio->custom_cover_image_url({
2071
                    isbn => $oldbiblio->{isbn},
2072
                    normalized_isbn => $oldbiblio->{normalized_isbn},
2073
                    issn => $oldbiblio->{issn},
2074
                    record => $marcrecord
2075
                });
2076
        }
2068
2077
2069
        push( @newresults, $oldbiblio );
2078
        push( @newresults, $oldbiblio );
2070
    }
2079
    }
(-)a/Koha/Biblio.pm (-5 / +8 lines)
Lines 756-775 It is built regaring the value of the system preference CustomCoverImagesURL Link Here
756
=cut
756
=cut
757
757
758
sub custom_cover_image_url {
758
sub custom_cover_image_url {
759
    my ( $self ) = @_;
759
    my ( $self, $params ) = @_;
760
    return unless (ref $self || $params);
761
760
    my $url = C4::Context->preference('CustomCoverImagesURL');
762
    my $url = C4::Context->preference('CustomCoverImagesURL');
761
    if ( $url =~ m|{isbn}| ) {
763
    if ( $url =~ m|{isbn}| ) {
762
        my $isbn = $self->biblioitem->isbn;
764
        my $isbn = (ref $self) ? $self->biblioitem->isbn : $params->{isbn};
763
        return unless $isbn;
765
        return unless $isbn;
764
        $url =~ s|{isbn}|$isbn|g;
766
        $url =~ s|{isbn}|$isbn|g;
765
    }
767
    }
766
    if ( $url =~ m|{normalized_isbn}| ) {
768
    if ( $url =~ m|{normalized_isbn}| ) {
767
        my $normalized_isbn = C4::Koha::GetNormalizedISBN($self->biblioitem->isbn);
769
        my $normalized_isbn = (ref $self) ?
770
            C4::Koha::GetNormalizedISBN($self->biblioitem->isbn): $params->{normalized_isbn};
768
        return unless $normalized_isbn;
771
        return unless $normalized_isbn;
769
        $url =~ s|{normalized_isbn}|$normalized_isbn|g;
772
        $url =~ s|{normalized_isbn}|$normalized_isbn|g;
770
    }
773
    }
771
    if ( $url =~ m|{issn}| ) {
774
    if ( $url =~ m|{issn}| ) {
772
        my $issn = $self->biblioitem->issn;
775
        my $issn = (ref $self ) ? $self->biblioitem->issn : $params->{issn};
773
        return unless $issn;
776
        return unless $issn;
774
        $url =~ s|{issn}|$issn|g;
777
        $url =~ s|{issn}|$issn|g;
775
    }
778
    }
Lines 778-784 sub custom_cover_image_url { Link Here
778
    if ( $url =~ $re ) {
781
    if ( $url =~ $re ) {
779
        my $field = $+{field};
782
        my $field = $+{field};
780
        my $subfield = $+{subfield};
783
        my $subfield = $+{subfield};
781
        my $marc_record = $self->metadata->record;
784
        my $marc_record = (ref $self) ? $self->metadata->record : $params->{record};
782
        my $value = $marc_record->subfield($field, $subfield);
785
        my $value = $marc_record->subfield($field, $subfield);
783
        return unless $value;
786
        return unless $value;
784
        $url =~ s|$re|$value|;
787
        $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-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