<<

NAME

C4::Items - item management functions

DESCRIPTION

This module contains an API for manipulating item records in Koha, and is used by cataloguing, circulation, acquisitions, and serials management.

# FIXME This POD is not up-to-date A Koha item record is stored in two places: the items table and embedded in a MARC tag in the XML version of the associated bib record in biblioitems.marcxml. This is done to allow the item information to be readily indexed (e.g., by Zebra), but means that each item modification transaction must keep the items table and the MARC XML in sync at all times.

The items table will be considered authoritative. In other words, if there is ever a discrepancy between the items table and the MARC XML, the items table should be considered accurate.

HISTORICAL NOTE

Most of the functions in C4::Items were originally in the C4::Biblio module.

CORE EXPORTED FUNCTIONS

The following functions are meant for use by users of C4::Items

CartToShelf

  CartToShelf($itemnumber);

Set the current shelving location of the item record to its stored permanent shelving location. This is primarily used to indicate when an item whose current location is a special processing ('PROC') or shelving cart ('CART') location is back in the stacks.

AddItemFromMarc

  my ($biblionumber, $biblioitemnumber, $itemnumber) 
      = AddItemFromMarc($source_item_marc, $biblionumber);

Given a MARC::Record object containing an embedded item record and a biblionumber, create a new item record.

AddItemBatchFromMarc

  ($itemnumber_ref, $error_ref) = AddItemBatchFromMarc($record, 
             $biblionumber, $biblioitemnumber, $frameworkcode);

Efficiently create item records from a MARC biblio record with embedded item fields. This routine is suitable for batch jobs.

This API assumes that the bib record has already been saved to the biblio and biblioitems tables. It does not expect that biblio_metadata.metadata is populated, but it will do so via a call to ModBibiloMarc.

The goal of this API is to have a similar effect to using AddBiblio and AddItems in succession, but without inefficient repeated parsing of the MARC XML bib record.

This function returns an arrayref of new itemsnumbers and an arrayref of item errors encountered during the processing. Each entry in the errors list is a hashref containing the following keys:

item_sequence

Sequence number of original item tag in the MARC record.

item_barcode

Item barcode, provide to assist in the construction of useful error messages.

error_code

Code representing the error condition. Can be 'duplicate_barcode', 'invalid_homebranch', or 'invalid_holdingbranch'.

error_information

Additional information appropriate to the error condition.

ModItemTransfer

  ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger);

Marks an item as being transferred from one branch to another and records the trigger.

ModDateLastSeen

ModDateLastSeen( $itemnumber, $leave_item_lost );

Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking. $itemnumber is the item number $leave_item_lost determines if a lost item will be found or remain lost

CheckItemPreSave

    my $item_ref = TransformMarcToKoha($marc, 'items');
    # do stuff
    my %errors = CheckItemPreSave($item_ref);
    if (exists $errors{'duplicate_barcode'}) {
        print "item has duplicate barcode: ", $errors{'duplicate_barcode'}, "\n";
    } elsif (exists $errors{'invalid_homebranch'}) {
        print "item has invalid home branch: ", $errors{'invalid_homebranch'}, "\n";
    } elsif (exists $errors{'invalid_holdingbranch'}) {
        print "item has invalid holding branch: ", $errors{'invalid_holdingbranch'}, "\n";
    } else {
        print "item is OK";
    }

Given a hashref containing item fields, determine if it can be inserted or updated in the database. Specifically, checks for database integrity issues, and returns a hash containing any of the following keys, if applicable.

duplicate_barcode

Barcode, if it duplicates one already found in the database.

invalid_homebranch

Home branch, if not defined in branches table.

invalid_holdingbranch

Holding branch, if not defined in branches table.

This function does NOT implement any policy-related checks, e.g., whether current operator is allowed to save an item that has a given branch code.

EXPORTED SPECIAL ACCESSOR FUNCTIONS

The following functions provide various ways of getting an item record, a set of item records, or lists of authorized values for certain item fields.

GetItemsForInventory

($itemlist, $iTotalRecords) = GetItemsForInventory( { minlocation => $minlocation, maxlocation => $maxlocation, location => $location, itemtype => $itemtype, ignoreissued => $ignoreissued, datelastseen => $datelastseen, branchcode => $branchcode, branch => $branch, offset => $offset, size => $size, statushash => $statushash, } );

Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.

The sub returns a reference to a list of hashes, each containing itemnumber, author, title, barcode, item callnumber, and date last seen. It is ordered by callnumber then title.

The required minlocation & maxlocation parameters are used to specify a range of item callnumbers the datelastseen can be used to specify that you want to see items not seen since a past date only. offset & size can be used to retrieve only a part of the whole listing (defaut behaviour) $statushash requires a hashref that has the authorized values fieldname (intems.notforloan, etc...) as keys, and an arrayref of statuscodes we are searching for as values.

$iTotalRecords is the number of rows that would have been returned without the $offset, $size limit clause

GetItemsInfo

  @results = GetItemsInfo($biblionumber);

Returns information about items with the given biblionumber.

GetItemsInfo returns a list of references-to-hash. Each element contains a number of keys. Most of them are attributes from the biblio, biblioitems, items, and itemtypes tables in the Koha database. Other keys include:

$data->{branchname}

The name (not the code) of the branch to which the book belongs.

$data->{datelastseen}

This is simply items.datelastseen, except that while the date is stored in YYYY-MM-DD format in the database, here it is converted to DD/MM/YYYY format. A NULL date is returned as //.

$data->{datedue}
$data->{class}

This is the concatenation of biblioitems.classification, the book's Dewey code, and biblioitems.subclass.

$data->{ocount}

I think this is the number of copies of the book available.

$data->{order}

If this is set, it is set to One Order.

GetItemsLocationInfo

  my @itemlocinfo = GetItemsLocationInfo($biblionumber);

Returns the branch names, shelving location and itemcallnumber for each item attached to the biblio in question

GetItemsInfo returns a list of references-to-hash. Data returned:

$data->{homebranch}

Branch Name of the item's homebranch

$data->{holdingbranch}

Branch Name of the item's holdingbranch

$data->{location}

Item's shelving location code

$data->{location_intranet}

The intranet description for the Shelving Location as set in authorised_values 'LOC'

$data->{location_opac}

The OPAC description for the Shelving Location as set in authorised_values 'LOC'. Falls back to intranet description if no OPAC description is set.

$data->{itemcallnumber}

Item's itemcallnumber

$data->{cn_sort}

Item's call number normalized for sorting

GetHostItemsInfo

    $hostiteminfo = GetHostItemsInfo($hostfield);
    Returns the iteminfo for items linked to records via a host field

get_hostitemnumbers_of

  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);

Given a biblionumber, return the list of corresponding itemnumbers that are linked to it via host fields

Return a reference on a hash where key is a biblionumber and values are references on array of itemnumbers.

GetHiddenItemnumbers

    my @itemnumbers_to_hide = GetHiddenItemnumbers({ items => \@items, borcat => $category });

Given a list of items it checks which should be hidden from the OPAC given the current configuration. Returns a list of itemnumbers corresponding to those that should be hidden. Optionally takes a borcat parameter for certain borrower types to be excluded

LIMITED USE FUNCTIONS

The following functions, while part of the public API, are not exported. This is generally because they are meant to be used by only one script for a specific purpose, and should not be used in any other context without careful thought.

GetMarcItem

  my $item_marc = GetMarcItem($biblionumber, $itemnumber);

Returns MARC::Record of the item passed in parameter. This function is meant for use only in cataloguing/additem.pl, where it is needed to support that script's MARC-like editor.

PRIVATE FUNCTIONS AND VARIABLES

The following functions are not meant to be called directly, but are documented in order to explain the inner workings of C4::Items.

MoveItemFromBiblio

  MoveItemFromBiblio($itenumber, $frombiblio, $tobiblio);

Moves an item from a biblio to another

Returns undef if the move failed or the biblionumber of the destination record otherwise

_marc_from_item_hash

  my $item_marc = _marc_from_item_hash($item, $frameworkcode[, $unlinked_item_subfields]);

Given an item hash representing a complete item record, create a MARC::Record object containing an embedded tag representing that item.

The third, optional parameter $unlinked_item_subfields is an arrayref of subfields (not mapped to items fields per the framework) to be added to the MARC representation of the item.

_repack_item_errors

Add an error message hash generated by CheckItemPreSave to a list of errors.

_get_unlinked_item_subfields

  my $unlinked_item_subfields = _get_unlinked_item_subfields($original_item_marc, $frameworkcode);

_get_unlinked_subfields_xml

  my $unlinked_subfields_xml = _get_unlinked_subfields_xml($unlinked_item_subfields);

_parse_unlinked_item_subfields_from_xml

  my $unlinked_item_subfields = _parse_unlinked_item_subfields_from_xml($whole_item->{'more_subfields_xml'}):

GetAnalyticsCount

  $count= &GetAnalyticsCount($itemnumber)

counts Usage of itemnumber in Analytical bibliorecords.

SearchItems

    my ($items, $total) = SearchItems($filter, $params);

Perform a search among items

$filter is a reference to a hash which can be a filter, or a combination of filters.

A filter has the following keys:

A combination of filters hash the following keys:

$params is a reference to a hash that can contain the following parameters:

OTHER FUNCTIONS

_find_value

  ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);

Find the given $subfield in the given $tag in the given MARC::Record $record. If the subfield is found, returns the (indicators, value) pair; otherwise, (undef, undef) is returned.

PROPOSITION : Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities. I suggest we export it from this module.

PrepareItemrecordDisplay

  PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);

Returns a hash with all the fields for Display a given item data in a template

The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided

<<