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

(-)a/C4/Search.pm (+30 lines)
Lines 1470-1475 sub buildQuery { Link Here
1470
            $limit_cgi       .= "&limit=" . uri_escape_utf8($this_limit);
1470
            $limit_cgi       .= "&limit=" . uri_escape_utf8($this_limit);
1471
            $limit_desc      .= " $this_limit";
1471
            $limit_desc      .= " $this_limit";
1472
        }
1472
        }
1473
        elsif ( $this_limit =~ 'multibranchlimit|^branch' ) {
1474
            $limit_cgi  .= "&limit=" . uri_escape_utf8($this_limit);
1475
            $limit .= " and " if $limit || $query;
1476
            my $branchfield  = C4::Context->preference('SearchLimitLibrary');
1477
            my @branchcodes;
1478
            if(  $this_limit =~ 'multibranchlimit' ){
1479
                my ($group_id) = ( $this_limit =~ /^multibranchlimit:(.*)$/ );
1480
                my $search_group = Koha::Library::Groups->find( $group_id );
1481
                @branchcodes  = map { $_->branchcode } $search_group->all_libraries;
1482
                @branchcodes = sort { $a cmp $b } @branchcodes;
1483
            } else {
1484
                @branchcodes = ( $this_limit =~ /^branch:(.*)$/ );
1485
            }
1486
1487
            if (@branchcodes) {
1488
                if ( $branchfield eq "homebranch" ) {
1489
                    $this_limit = sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes;
1490
                }
1491
                elsif ( $branchfield eq "holdingbranch" ) {
1492
                    $this_limit = sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes;
1493
                }
1494
                else {
1495
                    $this_limit =  sprintf "(%s or %s)",
1496
                      join( " or ", map { 'homebranch: ' . $_ } @branchcodes ),
1497
                      join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes );
1498
                }
1499
            }
1500
            $limit .= "$this_limit";
1501
            $limit_desc .= " $this_limit";
1502
        }
1473
1503
1474
        # Regular old limits
1504
        # Regular old limits
1475
        else {
1505
        else {
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+26 lines)
Lines 1010-1015 sub _fix_limit_special_cases { Link Here
1010
            $date = $self->_modify_string_by_type(type => 'st-year', operand => $date);
1010
            $date = $self->_modify_string_by_type(type => 'st-year', operand => $date);
1011
            push @new_lim, "date-of-publication:$date";
1011
            push @new_lim, "date-of-publication:$date";
1012
        }
1012
        }
1013
        elsif ( $l =~ 'multibranchlimit|^branch' ) {
1014
            my $branchfield  = C4::Context->preference('SearchLimitLibrary');
1015
            my @branchcodes;
1016
            if( $l =~ 'multibranchlimit' ) {
1017
                my ($group_id) = ( $l =~ /^multibranchlimit:(.*)$/ );
1018
                my $search_group = Koha::Library::Groups->find( $group_id );
1019
                @branchcodes = map { $_->branchcode } $search_group->all_libraries;
1020
                @branchcodes = sort { $a cmp $b } @branchcodes;
1021
            } else {
1022
                @branchcodes = ( $l =~ /^branch:(.*)$/ );
1023
            }
1024
1025
            if (@branchcodes) {
1026
                if ( $branchfield eq "homebranch" ) {
1027
                    push @new_lim, sprintf "(%s)", join " OR ", map { 'homebranch: ' . $_ } @branchcodes;
1028
                }
1029
                elsif ( $branchfield eq "holdingbranch" ) {
1030
                    push @new_lim, sprintf "(%s)", join " OR ", map { 'holdingbranch: ' . $_ } @branchcodes;
1031
                }
1032
                else {
1033
                    push @new_lim, sprintf "(%s OR %s)",
1034
                      join( " OR ", map { 'homebranch: ' . $_ } @branchcodes ),
1035
                      join( " OR ", map { 'holdingbranch: ' . $_ } @branchcodes );
1036
                }
1037
            }
1038
        }
1013
        elsif ( $l =~ /^available$/ ) {
1039
        elsif ( $l =~ /^available$/ ) {
1014
            push @new_lim, 'onloan:false';
1040
            push @new_lim, 'onloan:false';
1015
        }
1041
        }
(-)a/catalogue/search.pl (-39 lines)
Lines 378-422 my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); Link Here
378
my %is_nolimit = map { $_ => 1 } @nolimits;
378
my %is_nolimit = map { $_ => 1 } @nolimits;
379
@limits = grep { not $is_nolimit{$_} } @limits;
379
@limits = grep { not $is_nolimit{$_} } @limits;
380
380
381
if ( $params->{'multibranchlimit'} ) {
382
    my $branchfield  = C4::Context->preference('SearchLimitLibrary');
383
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
384
    my @branchcodes  = map { $_->branchcode } $search_group->all_libraries;
385
386
    if (@branchcodes) {
387
        if ( $branchfield eq "homebranch" ) {
388
            push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes;
389
        }
390
        elsif ( $branchfield eq "holdingbranch" ) {
391
            push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes;
392
        }
393
        else {
394
            push @limits, sprintf "(%s or %s)",
395
              join( " or ", map { 'homebranch: ' . $_ } @branchcodes ),
396
              join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes );
397
        }
398
    }
399
}
400
401
for ( my $i=0; $i<@limits; $i++ ) {
402
    if ( $limits[$i] =~ /^branch:/ ) {
403
        my $branchfield  = C4::Context->preference('SearchLimitLibrary');
404
        if ( $branchfield eq "homebranch" ) {
405
            $limits[$i] =~ s/branch/homebranch/;
406
        }
407
        elsif ( $branchfield eq "holdingbranch" ) {
408
            $limits[$i] =~ s/branch/holdingbranch/;
409
        }
410
        else {
411
            my $homebranchlimit = $limits[$i];
412
            my $holdingbranchlimit = $limits[$i];
413
            $homebranchlimit =~ s/branch/homebranch/;
414
            $holdingbranchlimit =~ s/branch/holdingbranch/;
415
            $limits[$i] = "($homebranchlimit or $holdingbranchlimit)";
416
        }
417
    }
418
}
419
420
my $available;
381
my $available;
421
foreach my $limit(@limits) {
382
foreach my $limit(@limits) {
422
    if ($limit =~/available/) {
383
    if ($limit =~/available/) {
(-)a/opac/opac-search.pl (-40 lines)
Lines 484-528 if (@searchCategories > 0) { Link Here
484
484
485
@limits = map { uri_unescape($_) } @limits;
485
@limits = map { uri_unescape($_) } @limits;
486
486
487
if ( $params->{'multibranchlimit'} || ( $branch_group_limit && $branch_group_limit =~ /^multibranchlimit-/ ) ) {
488
    my $branchfield  = C4::Context->preference('SearchLimitLibrary');
489
    my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
490
491
    my @branchcodes  = map { $_->branchcode } $search_group->all_libraries;
492
493
    if (@branchcodes) {
494
        if ( $branchfield eq "homebranch" ) {
495
            push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes;
496
        }
497
        elsif ( $branchfield eq "holdingbranch" ) {
498
            push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes;
499
        }
500
        else {
501
            push @limits, sprintf "(%s or %s)",
502
              join( " or ", map { 'homebranch: ' . $_ } @branchcodes ),
503
              join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes );
504
        }
505
    }
506
}
507
508
for ( my $i=0; $i<@limits; $i++ ) {
509
    if ( $limits[$i] =~ /^branch:/ ) {
510
        my $branchfield  = C4::Context->preference('SearchLimitLibrary');
511
        if ( $branchfield eq "homebranch" ) {
512
            $limits[$i] =~ s/branch/homebranch/;
513
        }
514
        elsif ( $branchfield eq "holdingbranch" ) {
515
            $limits[$i] =~ s/branch/holdingbranch/;
516
        }
517
        else {
518
            my $homebranchlimit = $limits[$i];
519
            my $holdingbranchlimit = $limits[$i];
520
            $homebranchlimit =~ s/branch/homebranch/;
521
            $holdingbranchlimit =~ s/branch/holdingbranch/;
522
            $limits[$i] = "($homebranchlimit or $holdingbranchlimit)";
523
        }
524
    }
525
}
526
487
527
my $available;
488
my $available;
528
foreach my $limit(@limits) {
489
foreach my $limit(@limits) {
529
- 

Return to bug 28847