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

(-)a/C4/Reserves.pm (-3 / +14 lines)
Lines 1188-1194 and canreservefromotherbranches. Link Here
1188
=cut
1188
=cut
1189
1189
1190
sub IsAvailableForItemLevelRequest {
1190
sub IsAvailableForItemLevelRequest {
1191
    my ( $item, $patron, $pickup_branchcode ) = @_;
1191
    my $item                = shift;
1192
    my $patron              = shift;
1193
    my $pickup_branchcode   = shift;
1194
    # items_any_available is precalculated status passed from request.pl when set of items
1195
    # looped outside of IsAvailableForItemLevelRequest to avoid nested loops:
1196
    my $items_any_available = shift;
1192
1197
1193
    my $dbh = C4::Context->dbh;
1198
    my $dbh = C4::Context->dbh;
1194
    # must check the notforloan setting of the itemtype
1199
    # must check the notforloan setting of the itemtype
Lines 1205-1212 sub IsAvailableForItemLevelRequest { Link Here
1205
        $item->withdrawn        ||
1210
        $item->withdrawn        ||
1206
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1211
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1207
1212
1208
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1209
1210
    if ($pickup_branchcode) {
1213
    if ($pickup_branchcode) {
1211
        my $destination = Koha::Libraries->find($pickup_branchcode);
1214
        my $destination = Koha::Libraries->find($pickup_branchcode);
1212
        return 0 unless $destination;
1215
        return 0 unless $destination;
Lines 1214-1222 sub IsAvailableForItemLevelRequest { Link Here
1214
        return 0 unless $item->can_be_transferred( { to => $destination } );
1217
        return 0 unless $item->can_be_transferred( { to => $destination } );
1215
    }
1218
    }
1216
1219
1220
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1221
1217
    if ( $on_shelf_holds == 1 ) {
1222
    if ( $on_shelf_holds == 1 ) {
1218
        return 1;
1223
        return 1;
1219
    } elsif ( $on_shelf_holds == 2 ) {
1224
    } elsif ( $on_shelf_holds == 2 ) {
1225
1226
        # if we have this param predefined from outer caller sub, we just need
1227
        # to return it, so we saving from having loop inside other loop:
1228
        return  $items_any_available ? 0 : 1
1229
            if defined $items_any_available;
1230
1220
        my @items =
1231
        my @items =
1221
          Koha::Items->search( { biblionumber => $item->biblionumber } );
1232
          Koha::Items->search( { biblionumber => $item->biblionumber } );
1222
1233
(-)a/reserve/request.pl (-2 / +28 lines)
Lines 444-449 foreach my $biblionumber (@biblionumbers) { Link Here
444
                $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
444
                $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
445
        }
445
        }
446
446
447
        # iterating through all items first to check if any of them available
448
        # to pass this value further inside down to IsAvailableForItemLevelRequest to
449
        # it's complicated logic to analyse.
450
        # (before this loop was inside that sub loop so it was O(n^2) )
451
        my $items_any_available;
452
        if ( $patron ) {
453
            my @items = Koha::Items->search( { biblionumber => $biblioitemnumber } );
454
455
            foreach my $i (@items) {
456
                my $reserves_control_branch = GetReservesControlBranch( $i->unblessed(), $patron->unblessed );
457
                my $branchitemrule = C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
458
459
                $items_any_available = 1
460
                  unless $i->itemlost
461
                  || $i->notforloan > 0
462
                  || $i->withdrawn
463
                  || $i->onloan
464
                  || IsItemOnHoldAndFound( $i->id )
465
                  || ( $i->damaged
466
                    && !C4::Context->preference('AllowHoldsOnDamagedItems') )
467
                  || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
468
                  || $branchitemrule->{holdallowed} == 1 && $patron->branchcode ne $i->homebranch;
469
            }
470
        }
471
447
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
472
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
448
            my $item = $iteminfos_of->{$itemnumber};
473
            my $item = $iteminfos_of->{$itemnumber};
449
            my $do_check;
474
            my $do_check;
Lines 556-563 foreach my $biblionumber (@biblionumbers) { Link Here
556
                if (
581
                if (
557
                       !$item->{cantreserve}
582
                       !$item->{cantreserve}
558
                    && !$exceeded_maxreserves
583
                    && !$exceeded_maxreserves
559
                    && IsAvailableForItemLevelRequest($item_object, $patron)
560
                    && $can_item_be_reserved eq 'OK'
584
                    && $can_item_be_reserved eq 'OK'
585
                    # items_any_available defined outside of the current loop,
586
                    # so we avoiding loop inside IsAvailableForItemLevelRequest:
587
                    && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
561
                  )
588
                  )
562
                {
589
                {
563
                    $item->{available} = 1;
590
                    $item->{available} = 1;
564
- 

Return to bug 24185