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

(-)a/C4/Search.pm (-4 / +41 lines)
Lines 329-335 sub getRecords { Link Here
329
    my (
329
    my (
330
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
330
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
331
        $results_per_page, $offset,       $expanded_facet, $branches,
331
        $results_per_page, $offset,       $expanded_facet, $branches,
332
        $itemtypes,        $query_type,   $scan,           $opac
332
        $itemtypes,        $query_type,   $scan,           $opac,        $availableLimit
333
    ) = @_;
333
    ) = @_;
334
334
335
    my @servers = @$servers_ref;
335
    my @servers = @$servers_ref;
Lines 348-353 sub getRecords { Link Here
348
    my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20;
348
    my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20;
349
349
350
    my @facets_loop;    # stores the ref to array of hashes for template facets loop
350
    my @facets_loop;    # stores the ref to array of hashes for template facets loop
351
    
352
    #Get the required marc tags for determining branch-based availability.
353
    my ( $holdingbranchField, $holdingbranchSubfield, $onloanField, $onloanSubfield );
354
    if ($availableLimit) {
355
        ( $holdingbranchField, $holdingbranchSubfield ) = GetMarcFromKohaField( "items.holdingbranch" );
356
        ( $onloanField, $onloanSubfield ) = GetMarcFromKohaField( "items.onloan" );
357
    }
358
    
351
359
352
    ### LOOP THROUGH THE SERVERS
360
    ### LOOP THROUGH THE SERVERS
353
    for ( my $i = 0 ; $i < @servers ; $i++ ) {
361
    for ( my $i = 0 ; $i < @servers ; $i++ ) {
Lines 493-500 sub getRecords { Link Here
493
501
494
                    # not an index scan
502
                    # not an index scan
495
                    else {
503
                    else {
496
                        $record = $results[ $i - 1 ]->record($j)->raw();
504
                        $record = $results[ $i - 1 ]->record($j);
505
                        last() unless $record;
506
                        $record = $record->raw();
497
                        # warn "RECORD $j:".$record;
507
                        # warn "RECORD $j:".$record;
508
                        
509
                        if (  $availableLimit && $availableLimit != 1 && #Availablelimit is 1 if there is no limit=branch:FTL given
510
                              not(isAvailableFromMARCXML( $record, $availableLimit, $holdingbranchField, $holdingbranchSubfield, $onloanField, $onloanSubfield )) ) {
511
                            $times++; #Skip this record, but make sure we still get the $results_per_page results to display.
512
                            next();
513
                        }
514
                        
498
                        $results_hash->{'RECORDS'}[$j] = $record;
515
                        $results_hash->{'RECORDS'}[$j] = $record;
499
                    }
516
                    }
500
517
Lines 1535-1542 sub buildQuery { Link Here
1535
## 'available' is defined as (items.onloan is NULL) and (items.itemlost = 0)
1552
## 'available' is defined as (items.onloan is NULL) and (items.itemlost = 0)
1536
## In English:
1553
## In English:
1537
## all records not indexed in the onloan register (zebra) and all records with a value of lost equal to 0
1554
## all records not indexed in the onloan register (zebra) and all records with a value of lost equal to 0
1538
            $availability_limit .=
1555
#            $availability_limit .=
1539
"( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and (lost,st-numeric=0) )"; #or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
1556
#"( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and (lost,st-numeric=0) )"; #or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
1540
            $limit_cgi  .= "&limit=available";
1557
            $limit_cgi  .= "&limit=available";
1541
            $limit_desc .= "";
1558
            $limit_desc .= "";
1542
        }
1559
        }
Lines 2434-2439 sub new_record_from_zebra { Link Here
2434
2451
2435
}
2452
}
2436
2453
2454
sub isAvailableFromMARCXML {
2455
    my ( $recordXML, $limitHoldingbranch, $holdingbranchField, $holdingbranchSubfield, $onloanField, $onloanSubfield ) = @_;
2456
    
2457
    my @itemsFields = $recordXML =~ /<datafield tag="$holdingbranchField".*?>(.*?)<\/datafield>/sg;
2458
    
2459
    my ($itemHoldingbranch, $itemOnloan);
2460
    foreach my $fieldStr (@itemsFields) {
2461
        if ($fieldStr =~ /<subfield code="$holdingbranchSubfield">(.*?)<\/subfield>/s) {
2462
            $itemHoldingbranch = $1;
2463
        }
2464
        if ($fieldStr =~ /<subfield code="$onloanSubfield">(.*?)<\/subfield>/s) {
2465
            $itemOnloan = $1;
2466
        }
2467
        if ($itemHoldingbranch && not($itemOnloan) && $itemHoldingbranch eq $limitHoldingbranch) {
2468
            return 1; #Available ! wooee!
2469
        }
2470
    }
2471
    return 0;
2472
}
2473
2437
END { }    # module clean-up code here (global destructor)
2474
END { }    # module clean-up code here (global destructor)
2438
2475
2439
1;
2476
1;
(-)a/catalogue/search.pl (-3 / +13 lines)
Lines 412-428 my @operands = map uri_unescape($_), $cgi->param('q'); Link Here
412
# limits are use to limit to results to a pre-defined category such as branch or language
412
# limits are use to limit to results to a pre-defined category such as branch or language
413
my @limits = map uri_unescape($_), $cgi->param('limit');
413
my @limits = map uri_unescape($_), $cgi->param('limit');
414
414
415
416
##HACKMAN HERE
417
#push @limits, "branch:JOE_JOE";
418
##HACKMAN 
415
if($params->{'multibranchlimit'}) {
419
if($params->{'multibranchlimit'}) {
416
    my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
420
    my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
417
    push @limits, $multibranch if ($multibranch ne  '()');
421
    push @limits, $multibranch if ($multibranch ne  '()');
418
}
422
}
419
423
420
my $available;
424
my ($available, $availableBranch);
421
foreach my $limit(@limits) {
425
foreach my $limit(@limits) {
422
    if ($limit =~/available/) {
426
    if ($limit =~/available/) {
423
        $available = 1;
427
        $available = 1;
424
    }
428
    }
429
	elsif ($limit =~ /^branch:(.*?)$/) {
430
		$availableBranch = $1;
431
	}
432
}
433
if ($availableBranch && $available) {
434
	$available = $availableBranch;
425
}
435
}
436
undef $availableBranch; #Don't pollute namespace!
426
$template->param(available => $available);
437
$template->param(available => $available);
427
438
428
# append year limits if they exist
439
# append year limits if they exist
Lines 520-526 my @results_array; Link Here
520
my $results_hashref;
531
my $results_hashref;
521
532
522
eval {
533
eval {
523
    ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan);
534
    ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan,undef,$available);
524
};
535
};
525
536
526
# This sorts the facets into alphabetical order
537
# This sorts the facets into alphabetical order
527
- 

Return to bug 11677