X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FItems.pm;h=fa31f523274072da97f68ca10ff8faad446fd0c7;hb=5d2fde5d587100e1c00e629c8cc21acb956aba6f;hp=1721eb89f6775fe44f0576761e541a4599bee11d;hpb=7be6d1f12bd765b669e9cc0ac73793ded4cf56c5;p=koha.git diff --git a/C4/Items.pm b/C4/Items.pm index 1721eb89f6..fa31f52327 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -229,8 +229,6 @@ sub AddItem { # create MARC tag representing item and add to bib my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields); - warn "HERE : ".$item->{'biblionumber'}; - warn "HERE 2 : ".$new_item_marc->as_formatted; _add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode ); logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); @@ -843,28 +841,35 @@ sub GetItemLocation { =over 4 -$items = GetLostItems($where,$orderby); +$items = GetLostItems( $where, $orderby ); =back -This function get the items lost into C<$items>. +This function gets a list of lost items. =over 2 =item input: + C<$where> is a hashref. it containts a field of the items table as key -and the value to match as value. -C<$orderby> is a field of the items table. +and the value to match as value. For example: + +{ barcode => 'abc123', + homebranch => 'CPL', } + +C<$orderby> is a field of the items table by which the resultset +should be orderd. =item return: -C<$items> is a reference to an array full of hasref which keys are items' table column. + +C<$items> is a reference to an array full of hashrefs with columns +from the "items" table as keys. =item usage in the perl script: -my %where; -$where{barcode} = 0001548; -my $items = GetLostItems( \%where, "homebranch" ); -$template->param(itemsloop => $items); +my $where = { barcode => '0001548' }; +my $items = GetLostItems( $where, "homebranch" ); +$template->param( itemsloop => $items ); =back @@ -887,18 +892,23 @@ sub GetLostItems { AND itemlost <> 0 "; + my @query_parameters; foreach my $key (keys %$where) { - $query .= " AND " . $key . " LIKE '%" . $where->{$key} . "%'"; + $query .= " AND $key LIKE ?"; + push @query_parameters, "%$where->{$key}%"; + } + if ( defined $orderby ) { + $query .= ' ORDER BY ?'; + push @query_parameters, $orderby; } - $query .= " ORDER BY ".$orderby." " if defined $orderby; my $sth = $dbh->prepare($query); - $sth->execute; - my @items; + $sth->execute( @query_parameters ); + my $items = []; while ( my $row = $sth->fetchrow_hashref ){ - push @items, $row; + push @$items, $row; } - return \@items; + return $items; } =head2 GetItemsForInventory @@ -1317,6 +1327,106 @@ sub GetItemnumberFromBarcode { return ($result); } +=head3 get_item_authorised_values + + find the types and values for all authorised values assigned to this item. + + parameters: + itemnumber + + returns: a hashref malling the authorised value to the value set for this itemnumber + + $authorised_values = { + 'CCODE' => undef, + 'DAMAGED' => '0', + 'LOC' => '3', + 'LOST' => '0' + 'NOT_LOAN' => '0', + 'RESTRICTED' => undef, + 'STACK' => undef, + 'WITHDRAWN' => '0', + 'branches' => 'CPL', + 'cn_source' => undef, + 'itemtypes' => 'SER', + }; + + Notes: see C4::Biblio::get_biblio_authorised_values for a similar method at the biblio level. + +=cut + +sub get_item_authorised_values { + my $itemnumber = shift; + + # assume that these entries in the authorised_value table are item level. + my $query = q(SELECT distinct authorised_value, kohafield + FROM marc_subfield_structure + WHERE kohafield like 'item%' + AND authorised_value != '' ); + + my $itemlevel_authorised_values = C4::Context->dbh->selectall_hashref( $query, 'authorised_value' ); + my $iteminfo = GetItem( $itemnumber ); + # warn( Data::Dumper->Dump( [ $itemlevel_authorised_values ], [ 'itemlevel_authorised_values' ] ) ); + my $return; + foreach my $this_authorised_value ( keys %$itemlevel_authorised_values ) { + my $field = $itemlevel_authorised_values->{ $this_authorised_value }->{'kohafield'}; + $field =~ s/^items\.//; + if ( exists $iteminfo->{ $field } ) { + $return->{ $this_authorised_value } = $iteminfo->{ $field }; + } + } + # warn( Data::Dumper->Dump( [ $return ], [ 'return' ] ) ); + return $return; +} + +=head3 get_authorised_value_images + + find a list of icons that are appropriate for display based on the + authorised values for a biblio. + + parameters: listref of authorised values, such as comes from + get_item_ahtorised_values or + from C4::Biblio::get_biblio_authorised_values + + returns: listref of hashrefs for each image. Each hashref looks like + this: + + { imageurl => '/intranet-tmpl/prog/img/itemtypeimg/npl/WEB.gif', + label => '', + category => '', + value => '', } + + Notes: Currently, I put on the full path to the images on the staff + side. This should either be configurable or not done at all. Since I + have to deal with 'intranet' or 'opac' in + get_biblio_authorised_values, perhaps I should be passing it in. + +=cut + +sub get_authorised_value_images { + my $authorised_values = shift; + + my @imagelist; + + my $authorised_value_list = GetAuthorisedValues(); + # warn ( Data::Dumper->Dump( [ $authorised_value_list ], [ 'authorised_value_list' ] ) ); + foreach my $this_authorised_value ( @$authorised_value_list ) { + if ( exists $authorised_values->{ $this_authorised_value->{'category'} } + && $authorised_values->{ $this_authorised_value->{'category'} } eq $this_authorised_value->{'authorised_value'} ) { + # warn ( Data::Dumper->Dump( [ $this_authorised_value ], [ 'this_authorised_value' ] ) ); + if ( defined $this_authorised_value->{'imageurl'} ) { + push @imagelist, { imageurl => C4::Koha::getitemtypeimagesrc( 'intranet' ) . '/' . $this_authorised_value->{'imageurl'}, + label => $this_authorised_value->{'lib'}, + category => $this_authorised_value->{'category'}, + value => $this_authorised_value->{'authorised_value'}, }; + } + } + } + + # warn ( Data::Dumper->Dump( [ \@imagelist ], [ 'imagelist' ] ) ); + return \@imagelist; + +} + =head1 LIMITED USE FUNCTIONS The following functions, while part of the public API,