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

(-)a/Koha/Biblio.pm (-26 lines)
Lines 99-130 sub can_article_request { Link Here
99
    return q{};
99
    return q{};
100
}
100
}
101
101
102
=head3 may_article_request
103
104
    Returns true if it is likely possible to make an article request for
105
    a given item type (or the default item type from biblioitems).
106
107
    # As class method:
108
    my $boolean = Koha::Biblio->may_article_request({ itemtype => 'BK' });
109
    # As instance method:
110
    my $boolean = Koha::Biblios->find($biblionumber)->may_article_request;
111
112
=cut
113
114
sub may_article_request {
115
    my ( $class_or_self, $params ) = @_;
116
    return q{} if !C4::Context->preference('ArticleRequests');
117
    my $itemtype = ref($class_or_self)
118
        ? $class_or_self->itemtype
119
        : $params->{itemtype};
120
    my $category = $params->{categorycode};
121
122
    my $guess = Koha::IssuingRules->guess_article_requestable_itemtypes({
123
        $category ? ( categorycode => $category ) : (),
124
    });
125
    return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
126
}
127
128
=head3 article_request_type
102
=head3 article_request_type
129
103
130
my $type = $biblio->article_request_type( $borrower );
104
my $type = $biblio->article_request_type( $borrower );
(-)a/Koha/ItemType.pm (+21 lines)
Lines 22-27 use Carp; Link Here
22
use C4::Koha;
22
use C4::Koha;
23
use C4::Languages;
23
use C4::Languages;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::IssuingRules;
25
use Koha::Localizations;
26
use Koha::Localizations;
26
27
27
use base qw(Koha::Object);
28
use base qw(Koha::Object);
Lines 106-111 sub can_be_deleted { Link Here
106
    return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
107
    return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
107
}
108
}
108
109
110
=head3 may_article_request
111
112
    Returns true if it is likely possible to make an article request for
113
    this item type.
114
    Optional parameter: categorycode (for patron).
115
116
=cut
117
118
sub may_article_request {
119
    my ( $self, $params ) = @_;
120
    return q{} if !C4::Context->preference('ArticleRequests');
121
    my $itemtype = $self->itemtype;
122
    my $category = $params->{categorycode};
123
124
    my $guess = Koha::IssuingRules->guess_article_requestable_itemtypes({
125
        $category ? ( categorycode => $category ) : (),
126
    });
127
    return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
128
}
129
109
=head3 type
130
=head3 type
110
131
111
=cut
132
=cut
(-)a/opac/opac-ISBDdetail.pl (-1 / +1 lines)
Lines 220-226 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ Link Here
220
if( C4::Context->preference('ArticleRequests') ) {
220
if( C4::Context->preference('ArticleRequests') ) {
221
    my $artreqpossible = $patron
221
    my $artreqpossible = $patron
222
        ? $biblio->can_article_request( $patron )
222
        ? $biblio->can_article_request( $patron )
223
        : $biblio->may_article_request;
223
        : Koha::ItemTypes->find($biblio->itemtype)->may_article_request;
224
    $template->param( artreqpossible => $artreqpossible );
224
    $template->param( artreqpossible => $artreqpossible );
225
}
225
}
226
226
(-)a/opac/opac-MARCdetail.pl (-1 / +2 lines)
Lines 60-65 use List::MoreUtils qw( any uniq ); Link Here
60
use Koha::Biblios;
60
use Koha::Biblios;
61
use Koha::IssuingRules;
61
use Koha::IssuingRules;
62
use Koha::Items;
62
use Koha::Items;
63
use Koha::ItemTypes;
63
use Koha::Patrons;
64
use Koha::Patrons;
64
use Koha::RecordProcessor;
65
use Koha::RecordProcessor;
65
66
Lines 352-358 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ Link Here
352
if( C4::Context->preference('ArticleRequests') ) {
353
if( C4::Context->preference('ArticleRequests') ) {
353
    my $artreqpossible = $patron
354
    my $artreqpossible = $patron
354
        ? $biblio->can_article_request( $patron )
355
        ? $biblio->can_article_request( $patron )
355
        : $biblio->may_article_request;
356
        : Koha::ItemTypes->find($biblio->itemtype)->may_article_request;
356
    $template->param( artreqpossible => $artreqpossible );
357
    $template->param( artreqpossible => $artreqpossible );
357
}
358
}
358
359
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 760-766 if( C4::Context->preference('ArticleRequests') ) { Link Here
760
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
760
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
761
    my $artreqpossible = $patron
761
    my $artreqpossible = $patron
762
        ? $biblio->can_article_request( $patron )
762
        ? $biblio->can_article_request( $patron )
763
        : $biblio->may_article_request;
763
        : Koha::ItemTypes->find($biblio->itemtype)->may_article_request;
764
    $template->param( artreqpossible => $artreqpossible );
764
    $template->param( artreqpossible => $artreqpossible );
765
}
765
}
766
766
(-)a/opac/opac-search.pl (-8 / +5 lines)
Lines 642-651 for (my $i=0;$i<@servers;$i++) { Link Here
642
        }
642
        }
643
        $hits = 0 unless @newresults;
643
        $hits = 0 unless @newresults;
644
644
645
        my $categorycode; # needed for may_article_request
645
        my $art_req_itypes;
646
        if( $borrowernumber && C4::Context->preference('ArticleRequests') ) {
646
        if( C4::Context->preference('ArticleRequests') ) {
647
            my $patron = Koha::Patrons->find( $borrowernumber );
647
            my $patron = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : undef;
648
            $categorycode = $patron ? $patron->categorycode : undef;
648
            $art_req_itypes = Koha::IssuingRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
649
        }
649
        }
650
650
651
        foreach my $res (@newresults) {
651
        foreach my $res (@newresults) {
Lines 705-714 for (my $i=0;$i<@servers;$i++) { Link Here
705
            }
705
            }
706
706
707
            # BZ17530: 'Intelligent' guess if result can be article requested
707
            # BZ17530: 'Intelligent' guess if result can be article requested
708
            $res->{artreqpossible} = Koha::Biblio->may_article_request({
708
            $res->{artreqpossible} = ( $art_req_itypes->{ $res->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
709
                categorycode => $categorycode,
710
                itemtype     => $res->{itemtype},
711
            });
712
        }
709
        }
713
710
714
        if ($results_hashref->{$server}->{"hits"}){
711
        if ($results_hashref->{$server}->{"hits"}){
(-)a/t/db_dependent/ArticleRequests.t (-14 / +5 lines)
Lines 221-227 subtest 'search_limited' => sub { Link Here
221
};
221
};
222
222
223
subtest 'may_article_request' => sub {
223
subtest 'may_article_request' => sub {
224
    plan tests => 6;
224
    plan tests => 3;
225
225
226
    # mocking
226
    # mocking
227
    t::lib::Mocks::mock_preference('ArticleRequests', 1);
227
    t::lib::Mocks::mock_preference('ArticleRequests', 1);
Lines 231-248 subtest 'may_article_request' => sub { Link Here
231
        'PT' => { 'BK' => 1 },
231
        'PT' => { 'BK' => 1 },
232
    });
232
    });
233
233
234
    # tests for class method call
234
    my $itemtype = Koha::ItemTypes->find('CR') // Koha::ItemType->new({ itemtype => 'CR' })->store;
235
    is( Koha::Biblio->may_article_request({ itemtype => 'CR' }), 1, 'SER/* should be true' );
235
    is( $itemtype->may_article_request, 1, 'SER/* should be true' );
236
    is( Koha::Biblio->may_article_request({ itemtype => 'CR', categorycode => 'S' }), 1, 'SER/S should be true' );
236
    is( $itemtype->may_article_request({ categorycode => 'S' }), 1, 'SER/S should be true' );
237
    is( Koha::Biblio->may_article_request({ itemtype => 'CR', categorycode => 'PT' }), '', 'SER/PT should be false' );
237
    is( $itemtype->may_article_request({ categorycode => 'PT' }), '', 'SER/PT should be false' );
238
239
    # tests for instance method call
240
    my $builder = t::lib::TestBuilder->new;
241
    my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
242
    my $biblioitem = $builder->build_object({ class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber, itemtype => 'BK' }});
243
    is( $biblio->may_article_request, '', 'BK/* false' );
244
    is( $biblio->may_article_request({ categorycode => 'S' }), 1, 'BK/S true' );
245
    is( $biblio->may_article_request({ categorycode => 'PT' }), 1, 'BK/PT true' );
246
238
247
    # Cleanup
239
    # Cleanup
248
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
240
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
249
- 

Return to bug 17530