- my $hits = $show_results;
- my (@results, @items);
-
- # This code needs to be refactored using these subs...
- #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
- #my $dat = &GetBiblioData( $biblio->{biblionumber} );
- for (my $i = 0 ; $i < $hits ; $i++) {
-
- #DEBUG Notes: Decode the MARC record from each resulting MARC record...
- my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
-
- #DEBUG Notes: Transform it to Koha form...
- my $biblio = TransformMarcToKoha(C4::Context->dbh, $marcrecord, '');
-
-# Begin building the hash for the template...
-# I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
-#$biblio->{highlight} = ($i % 2)?(1):(0);
-#DEBUG Notes: Stuff the bib into @results...
- push @results, $biblio;
- my $biblionumber = $biblio->{'biblionumber'};
-
- #DEBUG Notes: Grab the item numbers associated with this MARC record...
- my $itemnums = get_itemnumbers_of($biblionumber);
-
- #DEBUG Notes: Retrieve the item data for each number...
- my $iii = $itemnums->{$biblionumber};
- if ($iii) {
- my $item_results = GetItemInfosOf(@$iii);
- foreach my $item (keys %$item_results) {
-
-#DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
- if ($item_results->{$item}->{'biblionumber'} eq
- $results[$i]->{'biblionumber'}) {
-
-# NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
-# This is a real hack, but I can't think of a better way right now. -fbcit
-# It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility.
- push @{ $results[$i]->{'item'} }, { i_itemnumber1 =>
- $item_results->{$item}->{'itemnumber'} };
- push @{ $results[$i]->{'item'} },
- { i_itemcallnumber => (
- $item_results->{$item}->{'itemcallnumber'}
- ? $item_results->{$item}->{'itemcallnumber'} : 'NA'
- )
- };
- push @{ $results[$i]->{'item'} }, { i_dateaccessioned =>
- $item_results->{$item}->{'dateaccessioned'} };
- push @{ $results[$i]->{'item'} },
- { i_barcode => (
- $item_results->{$item}->{'barcode'}
- ? $item_results->{$item}->{'barcode'} : 'NA'
- )
- };
- push @{ $results[$i]->{'item'} }, { i_itemnumber2 =>
- $item_results->{$item}->{'itemnumber'} };
- }
- }
- }
- }
- $debug and warn "**********\@results**********\n";
- $debug and warn Dumper(@results);
-
- ($template, $loggedinuser, $cookie) = get_template_and_user(
- { template_name => "labels/result.tmpl",
- query => $query,
- type => "intranet",
- authnotrequired => 0,
- flagsrequired => { borrowers => 1 },
- flagsrequired => { catalogue => 1 },
- debug => 1,
- }
- );
-
- # build page nav stuff.
- my (@field_data, @numbers);
- $total = $total_hits;
+ my $hits = $show_results;
+ my @results_set = ();
+ my @items =();
+ # This code needs to be refactored using these subs...
+ #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
+ #my $dat = &GetBiblioData( $biblio->{biblionumber} );
+ for ( my $i = 0 ; $i < $hits ; $i++ ) {
+ my @row_data= ();
+ #DEBUG Notes: Decode the MARC record from each resulting MARC record...
+ my $marcrecord = MARC::File::USMARC::decode( $marcresults->[$i] );
+ #DEBUG Notes: Transform it to Koha form...
+ my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' );
+ #DEBUG Notes: Stuff the bib into @biblio_data...
+ push (@results_set, $biblio);
+ my $biblionumber = $biblio->{'biblionumber'};
+ #DEBUG Notes: Grab the item numbers associated with this MARC record...
+ my $itemnums = get_itemnumbers_of($biblionumber);
+ #DEBUG Notes: Retrieve the item data for each number...
+ if (my $iii = $itemnums->{$biblionumber}) {
+ my $item_results = GetItemInfosOf(@$iii);
+ foreach my $item ( keys %$item_results ) {
+ #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
+ if ($item_results->{$item}->{'biblionumber'} eq $results_set[$i]->{'biblionumber'}) {
+ my $item_data;
+ $item_data->{'_item_number'} = $item_results->{$item}->{'itemnumber'};
+ $item_data->{'_item_call_number'} = ($item_results->{$item}->{'itemcallnumber'} ? $item_results->{$item}->{'itemcallnumber'} : 'NA');
+ $item_data->{'_date_accessioned'} = $item_results->{$item}->{'dateaccessioned'};
+ $item_data->{'_barcode'} = ( $item_results->{$item}->{'barcode'} ? $item_results->{$item}->{'barcode'} : 'NA');
+ $item_data->{'_add'} = $item_results->{$item}->{'itemnumber'};
+ unshift (@row_data, $item_data); # item numbers are given to us in descending order by get_itemnumbers_of()...
+ }
+ }
+ $results_set[$i]->{'item_table'} = html_table($display_columns, \@row_data);
+ }
+ else {
+ # FIXME: Some error trapping code needed
+ warn sprintf('No item numbers retrieved for biblio number: %s', $biblionumber);
+ }
+ }