Skip to content

Instantly share code, notes, and snippets.

@gnucifer
Created January 3, 2018 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnucifer/5b2119f656592c4d6b3f6dab0b8087f1 to your computer and use it in GitHub Desktop.
Save gnucifer/5b2119f656592c4d6b3f6dab0b8087f1 to your computer and use it in GitHub Desktop.
sub GetItems {
my ($itemnumbers, $barcodes, $serial) = @_;
my $dbh = C4::Context->dbh;
my $items_data = [];
# Important: If 'item-level_itypes' preference is not set Koha::Item::effective_itemtype()
# will be equal to $item->{itype} and it is possible to fetch the data directly from items table.
# This will have a much smaller footprint then unblessing the item objects fetched through
# find/search. If more calculated attributes are added in the future, this code will need
# to account for that.
# TEMPORARLILY DISABLE OPTIMIZATION AND INSTEAD USE ->search
if (C4::Context->preference('item-level_itypes') && 0) {
$items_data = Koha::Items->search_unblessed($itemnumbers ? $itemnumbers : { barcode => $barcodes });
}
else {
my @items = Koha::Items->search(
$itemnumbers ? { itemnumber => { IN => $itemnumbers } } : { barcode => { IN => $barcodes } }
);
foreach my $item (@items) {
my $data = $item->unblessed();
# Set the correct itype
$data->{itype} = $item->effective_itemtype();
push @{$items_data}, $data;
}
}
if ($serial) {
foreach my $data (@{$items_data}) {
my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=ser
ial.serialid where serialitems.itemnumber=?");
$ssth->execute( $data->{'itemnumber'} );
( $data->{'serialseq'}, $data->{'publisheddate'} ) = $ssth->fetchrow_array();
}
}
return $items_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment