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

(-)a/C4/Search.pm (-4 / +5 lines)
Lines 1958-1963 sub searchResults { Link Here
1958
            push @available_items_loop, $available_items->{$key}
1958
            push @available_items_loop, $available_items->{$key}
1959
        }
1959
        }
1960
1960
1961
        my $biblio_object = Koha::Biblios->find( $oldbiblio->{biblionumber} );
1962
        $oldbiblio->{biblio_object} = $biblio_object;
1963
1961
        # XSLT processing of some stuff
1964
        # XSLT processing of some stuff
1962
        # we fetched the sysprefs already before the loop through all retrieved record!
1965
        # we fetched the sysprefs already before the loop through all retrieved record!
1963
        if (!$scan) {
1966
        if (!$scan) {
Lines 1968-1973 sub searchResults { Link Here
1968
1971
1969
            $record_processor->process($marcrecord);
1972
            $record_processor->process($marcrecord);
1970
1973
1974
            my $url = $is_opac  && C4::Context->preference('OPACShowOpenURL') ? $biblio_object->get_openurl : undef;
1971
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
1975
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
1972
                {
1976
                {
1973
                    biblionumber => $oldbiblio->{biblionumber},
1977
                    biblionumber => $oldbiblio->{biblionumber},
Lines 1979-1992 sub searchResults { Link Here
1979
                    ),
1983
                    ),
1980
                    fix_amps       => 1,
1984
                    fix_amps       => 1,
1981
                    hidden_items   => \@hiddenitems,
1985
                    hidden_items   => \@hiddenitems,
1982
                    xslt_variables => $xslt_variables
1986
                    xslt_variables => { %$xslt_variables, OpenURLResolverURL => $url },
1983
                }
1987
                }
1984
            );
1988
            );
1985
        }
1989
        }
1986
1990
1987
        my $biblio_object = Koha::Biblios->find( $oldbiblio->{biblionumber} );
1988
        $oldbiblio->{biblio_object} = $biblio_object;
1989
1990
        my $can_place_holds = 1;
1991
        my $can_place_holds = 1;
1991
        # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
1992
        # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
1992
        if (!C4::Context->preference("item-level_itypes")) {
1993
        if (!C4::Context->preference("item-level_itypes")) {
(-)a/C4/XSLT.pm (-19 / +1 lines)
Lines 248-254 sub XSLTParse4Display { Link Here
248
    my $xslsyspref   = $params->{xsl_syspref};
248
    my $xslsyspref   = $params->{xsl_syspref};
249
    my $fixamps      = $params->{fix_amps};
249
    my $fixamps      = $params->{fix_amps};
250
    my $hidden_items = $params->{hidden_items} || [];
250
    my $hidden_items = $params->{hidden_items} || [];
251
    my $variables    = $params->{xslt_variables};
251
    my $variables    = $params->{xslt_variables} // {};
252
    my $items_rs     = $params->{items_rs};
252
    my $items_rs     = $params->{items_rs};
253
253
254
    my $xslfilename = get_xsl_filename( $xslsyspref);
254
    my $xslfilename = get_xsl_filename( $xslsyspref);
Lines 263-286 sub XSLTParse4Display { Link Here
263
    }
263
    }
264
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
264
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
265
265
266
    $variables ||= {};
267
    my $biblio;
268
    if (C4::Context->preference('OPACShowOpenURL')) {
269
        my @biblio_itemtypes;
270
        $biblio //= Koha::Biblios->find($biblionumber);
271
        if (C4::Context->preference('item-level_itypes')) {
272
            @biblio_itemtypes = $biblio->items->get_column("itype");
273
        } else {
274
            push @biblio_itemtypes, $biblio->itemtype;
275
        }
276
        my @itypes = split( /\s/, C4::Context->preference('OPACOpenURLItemTypes') );
277
        my %original = ();
278
        map { $original{$_} = 1 } @biblio_itemtypes;
279
        if ( grep { $original{$_} } @itypes ) {
280
            $variables->{OpenURLResolverURL} = $biblio->get_openurl;
281
        }
282
    }
283
284
    my $varxml = "<variables>\n";
266
    my $varxml = "<variables>\n";
285
    while (my ($key, $value) = each %$variables) {
267
    while (my ($key, $value) = each %$variables) {
286
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
268
        $varxml .= "<variable name=\"$key\">$value</variable>\n";
(-)a/Koha/Biblio.pm (-3 / +10 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use List::MoreUtils qw( any );
22
use List::MoreUtils qw( any );
23
use URI;
23
use URI;
24
use URI::Escape qw( uri_escape_utf8 );
24
use URI::Escape qw( uri_escape_utf8 );
25
use Array::Utils qw( intersect );
25
26
26
use C4::Koha qw( GetNormalizedISBN );
27
use C4::Koha qw( GetNormalizedISBN );
27
use C4::XSLT qw( transformMARCXML4XSLT );
28
use C4::XSLT qw( transformMARCXML4XSLT );
Lines 766-775 Returns url for OpenURL resolver set in OpenURLResolverURL system preference Link Here
766
767
767
sub get_openurl {
768
sub get_openurl {
768
    my ( $self ) = @_;
769
    my ( $self ) = @_;
770
    my $OpenURLResolverURL = C4::Context->preference('OpenURLResolverURL') or return;
769
771
770
    my $OpenURLResolverURL = C4::Context->preference('OpenURLResolverURL');
772
    my @biblio_itemtypes;
773
    if( C4::Context->preference('item-level_itypes') ) {
774
        @biblio_itemtypes = $self->items->get_column("itype");
775
    } else {
776
        push @biblio_itemtypes, $self->itemtype;
777
    }
778
    my @openurl_itypes = split( /\s/, C4::Context->preference('OPACOpenURLItemTypes') );
771
779
772
    if ($OpenURLResolverURL) {
780
    if( intersect(@biblio_itemtypes, @openurl_itypes) ) {
773
        my $uri = URI->new($OpenURLResolverURL);
781
        my $uri = URI->new($OpenURLResolverURL);
774
782
775
        if (not defined $uri->query) {
783
        if (not defined $uri->query) {
Lines 779-785 sub get_openurl { Link Here
779
        }
787
        }
780
        $OpenURLResolverURL .= $self->get_coins;
788
        $OpenURLResolverURL .= $self->get_coins;
781
    }
789
    }
782
783
    return $OpenURLResolverURL;
790
    return $OpenURLResolverURL;
784
}
791
}
785
792
(-)a/opac/opac-detail.pl (+1 lines)
Lines 667-672 for my $plugin_variables ( @plugin_responses ) { Link Here
667
}
667
}
668
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
668
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
669
$variables->{show_analytics_link} = $show_analytics;
669
$variables->{show_analytics_link} = $show_analytics;
670
$variables->{OpenURLResolverURL} = C4::Context->preference('OPACShowOpenURL') ? $biblio->get_openurl : undef;
670
$template->param(
671
$template->param(
671
    XSLTBloc => XSLTParse4Display({
672
    XSLTBloc => XSLTParse4Display({
672
        biblionumber   => $biblionumber,
673
        biblionumber   => $biblionumber,
(-)a/opac/opac-shelves.pl (-1 / +2 lines)
Lines 366-372 if ( $op eq 'view' ) { Link Here
366
                $this_item->{'ITEM_RESULTS'} = $items;
366
                $this_item->{'ITEM_RESULTS'} = $items;
367
367
368
                my $variables = {
368
                my $variables = {
369
                    anonymous_session => ($loggedinuser) ? 0 : 1
369
                    anonymous_session  => ($loggedinuser) ? 0 : 1,
370
                    OpenURLResolverURL => C4::Context->preference('OPACShowOpenURL') ? $biblio->get_openurl : undef,
370
                };
371
                };
371
                $this_item->{XSLTBloc} = XSLTParse4Display(
372
                $this_item->{XSLTBloc} = XSLTParse4Display(
372
                    {
373
                    {
(-)a/opac/opac-tags.pl (-1 / +2 lines)
Lines 286-292 if ($loggedinuser) { Link Here
286
        $tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
286
        $tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
287
287
288
        my $variables = {
288
        my $variables = {
289
            anonymous_session => ($loggedinuser) ? 0 : 1
289
            anonymous_session  => ($loggedinuser) ? 0 : 1,
290
            OpenURLResolverURL => C4::Context->preference('OPACShowOpenURL') ? $biblio->get_openurl : undef,
290
        };
291
        };
291
        $tag->{XSLTBloc} = XSLTParse4Display(
292
        $tag->{XSLTBloc} = XSLTParse4Display(
292
            {
293
            {
(-)a/t/db_dependent/Koha/Biblio.t (-3 / +15 lines)
Lines 145-152 subtest 'items() tests' => sub { Link Here
145
};
145
};
146
146
147
subtest 'get_coins and get_openurl' => sub {
147
subtest 'get_coins and get_openurl' => sub {
148
148
    plan tests => 7;
149
    plan tests => 4;
150
149
151
    $schema->storage->txn_begin;
150
    $schema->storage->txn_begin;
152
151
Lines 171-176 subtest 'get_coins and get_openurl' => sub { Link Here
171
        'GetCOinsBiblio returned right metadata if biblio does not have a title'
170
        'GetCOinsBiblio returned right metadata if biblio does not have a title'
172
    );
171
    );
173
172
173
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
174
    t::lib::Mocks::mock_preference( 'OPACOpenURLItemTypes', $item->itype );
174
    t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/");
175
    t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/");
175
    is(
176
    is(
176
        $biblio->get_openurl,
177
        $biblio->get_openurl,
Lines 185-190 subtest 'get_coins and get_openurl' => sub { Link Here
185
        'Koha::Biblio->get_openurl returned right URL'
186
        'Koha::Biblio->get_openurl returned right URL'
186
    );
187
    );
187
188
189
    # Now change itemtypes in the pref, preventing coins call
190
    my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes' } );
191
    my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes' } );
192
    t::lib::Mocks::mock_preference( 'OPACOpenURLItemTypes', $itemtype1->itemtype. ' '. $itemtype2->itemtype );
193
    is( $biblio->get_openurl, C4::Context->preference("OpenURLResolverURL"), "No suffix expected now" );
194
195
    # And clear the pref
196
    t::lib::Mocks::mock_preference("OpenURLResolverURL", undef);
197
    is( $biblio->get_openurl, undef, "Undef when pref undefined" );
198
    t::lib::Mocks::mock_preference("OpenURLResolverURL", q{});
199
    is( $biblio->get_openurl, undef, "Undef when pref empty" );
200
188
    $schema->storage->txn_rollback;
201
    $schema->storage->txn_rollback;
189
};
202
};
190
203
191
- 

Return to bug 29314