| Lines 1354-1378
          Returns an array of MARC::Record objects of the items for the biblio.
      
      
        Link Here | 
        
          | 1354 | sub GetMarcItemFields { | 1354 | sub GetMarcItemFields { | 
        
          | 1355 |     my ( $biblionumber, $itemnumbers, $hidingrules ) = @_; | 1355 |     my ( $biblionumber, $itemnumbers, $hidingrules ) = @_; | 
        
          | 1356 |  | 1356 |  | 
          
            
              | 1357 |     my $item_level_itype = C4::Context->preference('item-level_itypes'); | 1357 |     my $params = { | 
            
              | 1358 |     # This is so much faster than using Koha::Items->search that it makes sense even if it's ugly. | 1358 |         biblionumber => $biblionumber | 
            
              | 1359 |     my $query = 'SELECT * FROM items WHERE biblionumber = ?'; | 1359 |     }; | 
        
          | 1360 |     if (@$itemnumbers) { | 1360 |     if (@$itemnumbers) { | 
          
            
              | 1361 |         $query .= ' AND itemnumber IN (' . join(',', @$itemnumbers) . ')'; | 1361 |         my @itemnumberlist; | 
            
              |  |  | 1362 |         foreach my $itemnumber (@$itemnumbers) { | 
            
              | 1363 |             push @itemnumberlist, {itemnumber => $itemnumber}; | 
            
              | 1364 |         } | 
            
              | 1365 |         $params->{-or} = \@itemnumberlist; | 
        
          | 1362 |     } | 1366 |     } | 
          
            
              | 1363 |     my $sth = C4::Context->dbh->prepare($query); | 1367 |     my $items = Koha::Items->search($params); | 
            
              | 1364 |     $sth->execute($biblionumber); |  |  | 
            
              | 1365 |     my $items = $sth->fetchall_arrayref({}); | 
            
              | 1366 |     $sth->finish(); | 
        
          | 1367 |     my @item_fields; | 1368 |     my @item_fields; | 
        
          | 1368 |     my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber'); | 1369 |     my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber'); | 
        
          | 1369 |  | 1370 |  | 
          
            
              | 1370 |     ITEMLOOP: foreach my $item (@$items) { | 1371 |     ITEMLOOP: while ( my $item = $items->next() ) { | 
            
              |  |  | 1372 |  | 
            
              | 1373 |         my $item_unblessed = $item->unblessed; | 
            
              | 1374 |         $item_unblessed->{itype} = $item->effective_itemtype() unless $item_unblessed->{itype}; | 
        
          | 1371 |  | 1375 |  | 
        
          | 1372 |         # Check hiding rules | 1376 |         # Check hiding rules | 
        
          | 1373 |         if (defined $hidingrules) { | 1377 |         if (defined $hidingrules) { | 
        
          | 1374 |             foreach my $field (keys %$hidingrules) { | 1378 |             foreach my $field (keys %$hidingrules) { | 
          
            
              | 1375 |                 my $val = $item->{$field}; | 1379 |                 my $val = $item_unblessed->{$field}; | 
        
          | 1376 |                 $val = '' unless defined $val; | 1380 |                 $val = '' unless defined $val; | 
        
          | 1377 |  | 1381 |  | 
        
          | 1378 |                 # If the results matches the values in the hiding rules, skip the item | 1382 |                 # If the results matches the values in the hiding rules, skip the item | 
  
    | Lines 1382-1398
          sub GetMarcItemFields {
      
      
        Link Here | 
        
          | 1382 |             } | 1386 |             } | 
        
          | 1383 |         } | 1387 |         } | 
        
          | 1384 |  | 1388 |  | 
            
              | 1385 |         # Set correct item type |  |  | 
            
              | 1386 |         if (!$item_level_itype || !$item->{itype}) { | 
            
              | 1387 |             warn 'item-level_itypes set but no itemtype set for item (' . $item->{itemnumber} . ')' if (!$item->{itype}); | 
            
              | 1388 |             my $biblioitem = Koha::Biblioitems->find($item->{biblioitemnumber}); | 
            
              | 1389 |             $item->{itype} = $biblioitem->itemtype(); | 
            
              | 1390 |         } | 
            
              | 1391 |  | 
        
          | 1392 |         my $mungeditem = { | 1389 |         my $mungeditem = { | 
        
          | 1393 |             map { | 1390 |             map { | 
          
            
              | 1394 |                 defined($item->{$_}) && $item->{$_} ne '' ? ("items.$_" => $item->{$_}) : () | 1391 |                 defined($item_unblessed->{$_}) && $item_unblessed->{$_} ne '' ? ("items.$_" => $item_unblessed->{$_}) : () | 
            
              | 1395 |             } keys %{ $item } | 1392 |             } keys %{ $item_unblessed } | 
        
          | 1396 |         }; | 1393 |         }; | 
        
          | 1397 |         my $itemmarc = TransformKohaToMarc($mungeditem); | 1394 |         my $itemmarc = TransformKohaToMarc($mungeditem); | 
        
          | 1398 |  | 1395 |  | 
            
              | 1399 | -  |  |  |