C4::Biblio - cataloging management functions
Biblio.pm contains functions for managing storage and editing of bibliographic data within Koha. Most of the functions in this module are used for cataloging records: adding, editing, or removing biblios, biblioitems, or items. Koha's stores bibliographic information in three places:
In the 3.0 version of Koha, the authoritative record-level information is in biblio_metadata.metadata
Because the data isn't completely normalized there's a chance for information to get out of sync. The design choice to go with a un-normalized schema was driven by performance and stability concerns. However, if this occur, it can be considered as a bug : The API is (or should be) complete & the only entry point for all biblio/items managements.
Because of this design choice, the process of managing storage and editing is a bit convoluted. Historically, Biblio.pm's grown to an unmanagable size and as a result we have several types of functions currently:
The MARC record (in biblio_metadata.metadata) contains the complete marc record, including items. It also contains the biblionumber. That is the reason why it is not stored directly by AddBiblio, with all other fields . To save a biblio, we need to :
($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
Exported function (core API) for adding a new biblio to koha.
The first argument is a MARC::Record
object containing the bib to add, while the second argument is the desired MARC framework code.
This function also accepts a third, optional argument: a hashref to additional options. The only defined option is defer_marc_save
, which if present and mapped to a true value, causes AddBiblio
to omit the call to save the MARC in biblio_metadata.metadata
This option is provided only for the use of scripts such as bulkmarcimport.pl
that may need to do some manipulation of the MARC record for item parsing before saving it and which cannot afford the performance hit of saving the MARC record twice. Consequently, do not use that option unless you can guarantee that ModBiblioMarc
will be called.
ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink);
Replace an existing bib record identified by $biblionumber
with one supplied by the MARC::Record object $record
. The embedded item, biblioitem, and biblionumber fields from the previous version of the bib record replace any such fields of those tags that are present in $record
. Consequently, ModBiblio() is not to be used to try to modify item records.
$frameworkcode
specifies the MARC framework to use when storing the modified bib record; among other things, this controls how MARC fields get mapped to display columns in the biblio
and biblioitems
tables, as well as which fields are used to store embedded item, biblioitem, and biblionumber data for indexing.
Unless $disable_autolink
is passed ModBiblio will relink record headings to authorities based on settings in the system preferences. This flag allows us to not relink records when the authority linker is saving modifications.
Returns 1 on success 0 on failure
_strip_item_fields($record, $frameworkcode)
Utility routine to remove item tags from a MARC bib.
my $error = &DelBiblio($biblionumber);
Exported function (core API) for deleting a biblio in koha. Deletes biblio record from Zebra and Koha tables (biblio & biblioitems) Also backs it up to deleted* tables. Checks to make sure that the biblio has no items attached. return: $error
: undef unless an error occurs
my $headings_linked = BiblioAutoLink($record, $frameworkcode)
Automatically links headings in a bib record to authorities.
Returns the number of headings changed
my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
Links bib headings to authority records by checking each authority-controlled field in the MARC::Record
object $marc
, looking for a matching authority record, and setting the linking subfield $9 to the ID of that authority record.
If $allowrelink is false, existing authids will never be replaced, regardless of the values of LinkerKeepStale and LinkerRelink.
Returns the number of heading links changed in the MARC record.
if ( _check_valid_auth_link($authid, $field) ) { ... }
Check whether the specified heading-auth link is valid without reference to Zebra. Ideally this code would be in C4::Heading, but that won't be possible until we have de-cycled C4::AuthoritiesMarc, so this is the safest place.
$data = &GetBiblioData($biblionumber);
Returns information about the book with the given biblionumber. &GetBiblioData
returns a reference-to-hash. The keys are the fields in the biblio
and biblioitems
tables in the Koha database.
In addition, $data->{subject}
is the list of the book's subjects, separated by " , "
(space, comma, space). If there are multiple biblioitems with the given biblionumber, only the first one is considered.
$isbd = &GetISBDView({ 'record' => $marc_record, 'template' => $interface, # opac/intranet 'framework' => $framework, });
Return the ISBD view which can be included in opac and intranet
my $tagslib = C4::Biblio::GetMarcStructure(); for my $tag ( sort keys %$tagslib ) { next unless $tag; for my $subfield ( sort keys %{ $tagslib->{$tag} } ) { next if IsMarcStructureInternal($tagslib->{$tag}{$subfield}); } # Process subfield }
GetMarcStructure creates keys (lib, tab, mandatory, repeatable, important) for a display purpose. These different values should not be processed as valid subfields.
$res = GetMarcStructure($forlibrarian, $frameworkcode, [ $params ]);
Returns a reference to a big hash of hash, with the Marc structure for the given frameworkcode $forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones $frameworkcode : the framework code to read $params allows you to pass { unsafe => 1 } for better performance.
Note: If you call GetMarcStructure with unsafe => 1, do not modify or even autovivify its contents. It is a cached/shared data structure. Your changes c/would be passed around in subsequent calls.
The same function as GetMarcStructure except it just takes field in tab 0-9. (used field)
my $results = GetUsedMarcStructure($frameworkcode);
$results
is a ref to an array which each case contains a ref to a hash which each keys is the columns from marc_subfield_structure
$frameworkcode
is the framework code.
my $structure = GetMarcSubfieldStructure($frameworkcode, [$params]);
Returns a reference to hash representing MARC subfield structure for framework with framework code $frameworkcode
, $params
is optional and may contain additional options.
$frameworkcode
The framework code.
$params
An optional hash reference with additional options. The following options are supported:
Pass { unsafe => 1 } do disable cached object cloning, and instead get a shared reference, resulting in better performance (but care must be taken so that retured object is never modified).
Note: If you call GetMarcSubfieldStructure with unsafe => 1, do not modify or even autovivify its contents. It is a cached/shared data structure. Your changes would be passed around in subsequent calls.
( $field,$subfield ) = GetMarcFromKohaField( $kohafield ); @fields = GetMarcFromKohaField( $kohafield ); $field = GetMarcFromKohaField( $kohafield ); Returns the MARC fields & subfields mapped to $kohafield. Since the Default framework is considered as authoritative for such mappings, the former frameworkcode parameter is obsoleted. In list context all mappings are returned; there can be multiple mappings. Note that in the above example you could miss a second mappings in the first call. In scalar context only the field tag of the first mapping is returned.
my $str = GetMarcSubfieldStructureFromKohaField( $kohafield ); Returns marc subfield structure information for $kohafield. The Default framework is used, since it is authoritative for kohafield mappings. In list context returns a list of all hashrefs, since there may be multiple mappings. In scalar context the first hashref is returned.
my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => $embeditems, opac => $opac, borcat => $patron_category });
Returns MARC::Record representing a biblio record, or undef
if the biblionumber doesn't exist.
Both embed_items and opac are optional. If embed_items is passed and is 1, items are embedded. If opac is passed and is 1, the record is filtered as needed.
$biblionumber
the biblionumber
$embeditems
set to true to include item information.
$opac
set to true to make the result suited for OPAC view. This causes things like OpacHiddenItems to be applied.
$borcat
If the OpacHiddenItemsExceptions system preference is set, this patron category can be used to make visible OPAC items which would be normally hidden. It only makes sense in combination both embed_items and opac values true.
my $marcxml = GetXmlBiblio($biblionumber);
Returns biblio_metadata.metadata/marcxml of the biblionumber passed in parameter. The XML should only contain biblio information (item information is no longer stored in marcxml field)
return the prices in accordance with the Marc format.
returns 0 if no price found returns undef if called without a marc record or with an unrecognized marc format
Return the best guess at what the actual price is from a price field.
return the quantity of a book. Used in acquisition only, when importing a file an iso2709 from a bookseller Warning : this is not really in the marc standard. In Unimarc, Electre (the most widely used bookseller) use the 969$a
returns 0 if no quantity found returns undef if called without a marc record or with an unrecognized marc format
my $subfieldvalue =get_authorised_value_desc( $tag, $subf[$i][0],$subf[$i][1], '', $taglib, $category, $opac);
Retrieve the complete description for a given authorised value.
Now takes $category and $value pair too.
my $auth_value_desc =GetAuthorisedValueDesc( '','', 'DVD' ,'','','CCODE');
If the optional $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
$marccontrolnumber = GetMarcControlnumber($record,$marcflavour);
Get the control number / record Identifier from the MARC record and return it.
$marcisbnsarray = GetMarcISBN( $record, $marcflavour );
Get all ISBNs from the MARC record and returns them in an array. ISBNs stored in different fields depending on MARC flavour
$marcissnsarray = GetMarcISSN( $record, $marcflavour );
Get all valid ISSNs from the MARC record and returns them in an array. ISSNs are stored in different fields depending on MARC flavour
$marcnotesarray = GetMarcNotes( $record, $marcflavour ); Get all notes from the MARC record and returns them in an array. The notes are stored in different fields depending on MARC flavour. MARC21 5XX $u subfields receive special attention as they are URIs.
$marcsubjcts = GetMarcSubjects($record,$marcflavour);
Get all subjects from the MARC record and returns them in an array. The subjects are stored in different fields depending on MARC flavour
authors = GetMarcAuthors($record,$marcflavour);
Get all authors from the MARC record and returns them in an array. The authors are stored in different fields depending on MARC flavour
$marcurls = GetMarcUrls($record,$marcflavour);
Returns arrayref of URLs from MARC data, suitable to pass to tmpl loop. Assumes web resources (not uncommon in MARC21 to omit resource type ind)
$marcseriesarray = GetMarcSeries($record,$marcflavour);
Get all series from the MARC record and returns them in an array. The series are stored in different fields depending on MARC flavour
my $record = C4::Biblio::UpsertMarcSubfield($MARC::Record, $fieldTag, $subfieldCode, $subfieldContent);
my $record = C4::Biblio::UpsertMarcControlField($MARC::Record, $fieldTag, $content);
$frameworkcode = GetFrameworkCode( $biblionumber )
$record = TransformKohaToMarc( $hash [, $params ] )
This function builds a (partial) MARC::Record from a hash. Hash entries can be from biblio, biblioitems or items. The params hash includes the parameter no_split used in C4::Items.
This function is called in acquisition module, to create a basic catalogue entry from user entry.
$hostfield = PrepHostMarcField ( $hostbiblionumber,$hostitemnumber,$marcflavour )
This function returns a host field populated with data from the host record, the field can then be added to an analytical record
$xml = TransformHtmlToXml( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type )
$auth_type contains :
Passed what should be an indicator returns a space if its undefined or zero length
L<$record> = TransformHtmlToMarc(L<$cgi>) L<$cgi> is the CGI object which contains the values for subfields { 'tag_010_indicator1_531951' , 'tag_010_indicator2_531951' , 'tag_010_code_a_531951_145735' , 'tag_010_subfield_a_531951_145735' , 'tag_200_indicator1_873510' , 'tag_200_indicator2_873510' , 'tag_200_code_a_873510_673465' , 'tag_200_subfield_a_873510_673465' , 'tag_200_code_b_873510_704318' , 'tag_200_subfield_b_873510_704318' , 'tag_200_code_e_873510_280822' , 'tag_200_subfield_e_873510_280822' , 'tag_200_code_f_873510_110730' , 'tag_200_subfield_f_873510_110730' , } L<$record> is the MARC::Record object.
$result = TransformMarcToKoha( $record, undef, $limit )
Extract data from a MARC bib record into a hashref representing Koha biblio, biblioitems, and items fields.
If passed an undefined record will log the error and return an empty hash_ref.
$newkey = _disambiguate($table, $field);
This is a temporary hack to distinguish between the following sets of columns when using TransformMarcToKoha.
items.cn_source & biblioitems.cn_source items.cn_sort & biblioitems.cn_sort
Columns that are currently NOT distinguished (FIXME due to lack of time to fully test) are:
biblio.notes and biblioitems.notes biblionumber timestamp biblioitemnumber
FIXME - this is necessary because prefixing each column name with the table name would require changing lots of code and templates, and exposing more of the DB structure than is good to the UI templates, particularly since biblio and bibloitems may well merge in a future version. In the future, it would also be good to separate DB access and UI presentation field names more.
$val = TransformMarcToKohaOneField( 'biblio.title', $marc ); Note: The authoritative Default framework is used implicitly.
Helper routine for TransformMarcToKohaOneField
my $count = CountItemsIssued( $biblionumber );
ModZebra( $record_number, $op, $server );
$record_number is the authid or biblionumber we want to index
$op is the operation: specialUpdate or recordDelete
$server is authorityserver or biblioserver
EmbedItemsInMarcBiblio({ marc_record => $marc, biblionumber => $biblionumber, item_numbers => $itemnumbers, opac => $opac });
Given a MARC::Record object containing a bib record, modify it to include the items attached to it as 9XX per the bib's MARC framework. if $itemnumbers is defined, only specified itemnumbers are embedded.
If $opac is true, then opac-relevant suppressions are included.
If opac filtering will be done, borcat should be passed to properly override if necessary.
_koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
Internal function to add or update biblionumber and biblioitemnumber to the MARC XML.
_koha_marc_update_biblioitem_cn_sort($marc, $biblioitem, $frameworkcode);
Given a MARC bib record and the biblioitem hash, update the subfield that contains a copy of the value of biblioitems.cn_sort.
my ($biblionumber,$error) = _koha_add_biblio($dbh,$biblioitem);
Internal function to add a biblio ($biblio is a hash with the values)
my ($biblionumber,$error) == _koha_modify_biblio($dbh,$biblio,$frameworkcode);
Internal function for updating the biblio table
my ($biblioitemnumber,$error) = _koha_modify_biblioitem_nonmarc( $dbh, $biblioitem );
my ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $biblioitem );
Internal function to add a biblioitem
$error = _koha_delete_biblio($dbh,$biblionumber);
Internal sub for deleting from biblio table -- also saves to deletedbiblio
$dbh
- the database handle
$biblionumber
- the biblionumber of the biblio to be deleted
$error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
$dbh
- the database handle $biblionumber
- the biblioitemnumber of the biblioitem to be deleted
$error = _koha_delete_biblio_metadata($biblionumber);
$biblionumber
- the biblionumber of the biblio metadata to be deleted
&ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
Add MARC XML data for a biblio to koha
Function exported, but should NOT be used, unless you really know what you're doing
$marcfield = prepare_host_field( $hostbiblioitem, $marcflavour ); Generate the host item entry for an analytic child entry
UpdateTotalIssues($biblionumber, $increase, [$value])
Update the total issue count for a particular bib record.
$biblionumber
is the biblionumber of the bib to update$increase
is the amount to increase (or decrease) the total issues count by$value
is the absolute value that total issues count should be set to. If provided, $increase
is ignored.&RemoveAllNsb($record);
Removes all nsb/nse chars from a record
Helper method that takes care of calling all plugin hooks
Koha Development Team <http://koha-community.org/>
Paul POULAIN paul.poulain@free.fr
Joshua Ferraro jmf@liblime.com