# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
+
+use vars qw(@ISA @EXPORT);
+BEGIN {
+ require Exporter;
+ @ISA = qw(Exporter);
+
+ @EXPORT = qw(
+ AddBiblio
+ GetBiblioData
+ GetMarcBiblio
+ GetRecordValue
+ GetISBDView
+ GetMarcControlnumber
+ GetMarcNotes
+ GetMarcISBN
+ GetMarcISSN
+ GetMarcSubjects
+ GetMarcAuthors
+ GetMarcSeries
+ GetMarcHosts
+ GetMarcUrls
+ GetUsedMarcStructure
+ GetXmlBiblio
+ GetCOinSBiblio
+ GetMarcPrice
+ MungeMarcPrice
+ GetMarcQuantity
+ GetAuthorisedValueDesc
+ GetMarcStructure
+ IsMarcStructureInternal
+ GetMarcFromKohaField
+ GetMarcSubfieldStructureFromKohaField
+ GetFrameworkCode
+ TransformKohaToMarc
+ PrepHostMarcField
+ CountItemsIssued
+ CountBiblioInOrders
+ ModBiblio
+ ModZebra
+ UpdateTotalIssues
+ RemoveAllNsb
+ DelBiblio
+ BiblioAutoLink
+ LinkBibHeadingsToAuthorities
+ TransformMarcToKoha
+ TransformHtmlToMarc
+ TransformHtmlToXml
+ prepare_host_field
+ );
+
+ # Internal functions
+ # those functions are exported but should not be used
+ # they are useful in a few circumstances, so they are exported,
+ # but don't use them unless you are a core developer ;-)
+ push @EXPORT, qw(
+ ModBiblioMarc
+ );
+}
+
use Carp;
use Encode qw( decode is_utf8 );
use Koha::Caches;
use Koha::Authority::Types;
use Koha::Acquisition::Currencies;
-use Koha::Biblio::Metadata;
use Koha::Biblio::Metadatas;
use Koha::Holds;
use Koha::ItemTypes;
use Koha::SearchEngine;
use Koha::Libraries;
+use Koha::Util::MARC;
-use vars qw(@ISA @EXPORT);
use vars qw($debug $cgi_debug);
-BEGIN {
-
- require Exporter;
- @ISA = qw( Exporter );
-
- # to add biblios
- # EXPORTED FUNCTIONS.
- push @EXPORT, qw(
- &AddBiblio
- );
-
- # to get something
- push @EXPORT, qw(
- GetBiblioData
- GetMarcBiblio
-
- &GetRecordValue
-
- &GetISBDView
-
- &GetMarcControlnumber
- &GetMarcNotes
- &GetMarcISBN
- &GetMarcISSN
- &GetMarcSubjects
- &GetMarcAuthors
- &GetMarcSeries
- &GetMarcHosts
- GetMarcUrls
- &GetUsedMarcStructure
- &GetXmlBiblio
- &GetCOinSBiblio
- &GetMarcPrice
- &MungeMarcPrice
- &GetMarcQuantity
-
- &GetAuthorisedValueDesc
- &GetMarcStructure
- &IsMarcStructureInternal
- &GetMarcFromKohaField
- &GetMarcSubfieldStructureFromKohaField
- &GetFrameworkCode
- &TransformKohaToMarc
- &PrepHostMarcField
-
- &CountItemsIssued
- &CountBiblioInOrders
- );
-
- # To modify something
- push @EXPORT, qw(
- &ModBiblio
- &ModZebra
- &UpdateTotalIssues
- &RemoveAllNsb
- );
-
- # To delete something
- push @EXPORT, qw(
- &DelBiblio
- );
-
- # To link headings in a bib record
- # to authority records.
- push @EXPORT, qw(
- &BiblioAutoLink
- &LinkBibHeadingsToAuthorities
- );
-
- # Internal functions
- # those functions are exported but should not be used
- # they are useful in a few circumstances, so they are exported,
- # but don't use them unless you are a core developer ;-)
- push @EXPORT, qw(
- &ModBiblioMarc
- );
-
- # Others functions
- push @EXPORT, qw(
- &TransformMarcToKoha
- &TransformHtmlToMarc
- &TransformHtmlToXml
- prepare_host_field
- );
-}
=head1 NAME
$defer_marc_save = 1;
}
+ if (C4::Context->preference('BiblioAddsAuthorities')) {
+ BiblioAutoLink( $record, $frameworkcode );
+ }
+
my ( $biblionumber, $biblioitemnumber, $error );
my $dbh = C4::Context->dbh;
logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted );
}
+ if (C4::Context->preference('BiblioAddsAuthorities')) {
+ BiblioAutoLink( $record, $frameworkcode );
+ }
+
# Cleaning up invalid fields must be done early or SetUTF8Flag is liable to
# throw an exception which probably won't be handled.
foreach my $field ($record->fields()) {
sub DelBiblio {
my ($biblionumber) = @_;
+
+ my $biblio = Koha::Biblios->find( $biblionumber );
+ return unless $biblio; # Should we throw an exception instead?
+
my $dbh = C4::Context->dbh;
my $error; # for error handling
}
# We delete any existing holds
- my $biblio = Koha::Biblios->find( $biblionumber );
my $holds = $biblio->holds;
while ( my $hold = $holds->next ) {
$hold->cancel;
'', '', "a" => "" . $field->subfield('a') );
map {
$authfield->add_subfields( $_->[0] => $_->[1] )
- if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
+ if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a"
+ && C4::Heading::valid_bib_heading_subfield(
+ $authority_type->auth_tag_to_report, $_->[0] )
+ );
} $field->subfields();
$marcrecordauth->insert_fields_ordered($authfield);
my $framework = $params->{framework};
my $itemtype = $framework;
my ( $holdingbrtagf, $holdingbrtagsubf ) = &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
- my $tagslib = &GetMarcStructure( 1, $itemtype, { unsafe => 1 } );
+ my $tagslib = GetMarcStructure( 1, $itemtype, { unsafe => 1 } );
my $ISBD = C4::Context->preference($sysprefname);
my $bloc = $ISBD;
=back
+=back
+
=cut
sub GetMarcSubfieldStructure {
my $record = GetMarcBiblio({
biblionumber => $biblionumber,
embed_items => $embeditems,
- opac => $opac });
+ opac => $opac,
+ borcat => $patron_category });
Returns MARC::Record representing a biblio record, or C<undef> if the
biblionumber doesn't exist.
set to true to make the result suited for OPAC view. This causes things like
OpacHiddenItems to be applied.
+=item C<$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.
+
=back
=cut
my $biblionumber = $params->{biblionumber};
my $embeditems = $params->{embed_items} || 0;
my $opac = $params->{opac} || 0;
+ my $borcat = $params->{borcat} // q{};
if (not defined $biblionumber) {
carp 'GetMarcBiblio called with undefined biblionumber';
C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
$biblioitemnumber );
- C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
+ C4::Biblio::EmbedItemsInMarcBiblio({
+ marc_record => $record,
+ biblionumber => $biblionumber,
+ opac => $opac,
+ borcat => $borcat })
if ($embeditems);
return $record;
FROM biblio_metadata
WHERE biblionumber=?
AND format='marcxml'
- AND marcflavour=?
+ AND `schema`=?
|, undef, $biblionumber, C4::Context->preference('marcflavour')
);
return $marcxml;
#---- branch
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
- return Koha::Libraries->find($value)->branchname;
+ my $branch = Koha::Libraries->find($value);
+ return $branch? $branch->branchname: q{};
}
#---- itemtypes
my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
$marcflavour ||="MARC21";
- require C4::Items;
my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
- my $item = C4::Items::GetItem($hostitemnumber);
-
+ my $item = Koha::Items->find($hostitemnumber);
+
my $hostmarcfield;
if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
#other fields
my $ed = $hostrecord->subfield('250','a');
- my $barcode = $item->{'barcode'};
+ my $barcode = $item->barcode;
my $title = $hostrecord->subfield('245','a');
# record control number, 001 with 003 and prefix
=head2 EmbedItemsInMarcBiblio
- EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
+ 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
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.
+
=cut
sub EmbedItemsInMarcBiblio {
- my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
+ my ($params) = @_;
+ my ($marc, $biblionumber, $itemnumbers, $opac, $borcat);
+ $marc = $params->{marc_record};
if ( !$marc ) {
carp 'EmbedItemsInMarcBiblio: No MARC record passed';
return;
}
+ $biblionumber = $params->{biblionumber};
+ $itemnumbers = $params->{item_numbers};
+ $opac = $params->{opac};
+ $borcat = $params->{borcat} // q{};
$itemnumbers = [] unless defined $itemnumbers;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
$sth->execute($biblionumber);
- my @item_fields;
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
- my @items;
+
+ my @item_fields; # Array holding the actual MARC data for items to be included.
+ my @items; # Array holding items which are both in the list (sitenumbers)
+ # and on this biblionumber
+
+ # Flag indicating if there is potential hiding.
my $opachiddenitems = $opac
&& ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
+
require C4::Items;
while ( my ($itemnumber) = $sth->fetchrow_array ) {
next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
- my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
- push @items, { itemnumber => $itemnumber, item => $i };
+ my $item;
+ if ( $opachiddenitems ) {
+ $item = Koha::Items->find($itemnumber);
+ $item = $item ? $item->unblessed : undef;
+ }
+ push @items, { itemnumber => $itemnumber, item => $item };
}
+ my @items2pass = map { $_->{item} } @items;
my @hiddenitems =
$opachiddenitems
- ? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
+ ? C4::Items::GetHiddenItemnumbers({
+ items => \@items2pass,
+ borcat => $borcat })
: ();
# Convert to a hash for quick searching
my %hiddenitems = map { $_ => 1 } @hiddenitems;
$sth->execute(
$frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'},
- $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}, $biblio->{'biblionumber'}
+ $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'} ? int($biblio->{'copyrightdate'}) : undef, $biblio->{'abstract'}, $biblio->{'biblionumber'}
) if $biblio->{'biblionumber'};
if ( $dbh->errstr || !$biblio->{'biblionumber'} ) {
$schema->txn_do(
sub {
$dbh->do( q|
- INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata)
- SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=?
+ INSERT INTO deletedbiblio_metadata (biblionumber, format, `schema`, metadata)
+ SELECT biblionumber, format, `schema`, metadata FROM biblio_metadata WHERE biblionumber=?
|, undef, $biblionumber );
$dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|,
undef, $biblionumber );
my $metadata = {
biblionumber => $biblionumber,
format => 'marcxml',
- marcflavour => C4::Context->preference('marcflavour'),
+ schema => C4::Context->preference('marcflavour'),
};
$record->as_usmarc; # Bug 20126/10455 This triggers field length calculation
- # FIXME To replace with ->find_or_create?
- if ( my $m_rs = Koha::Biblio::Metadatas->find($metadata) ) {
- $m_rs->metadata( $record->as_xml_record($encoding) );
- $m_rs->store;
- } else {
- my $m_rs = Koha::Biblio::Metadata->new($metadata);
- $m_rs->metadata( $record->as_xml_record($encoding) );
- $m_rs->store;
+ my $m_rs = Koha::Biblio::Metadatas->find($metadata) //
+ Koha::Biblio::Metadata->new($metadata);
+
+ my $userenv = C4::Context->userenv;
+ if ($userenv) {
+ my $borrowernumber = $userenv->{number};
+ my $borrowername = join ' ', @$userenv{qw(firstname surname)};
+ unless ($m_rs->in_storage) {
+ Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForCreatorId'), $borrowernumber);
+ Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForCreatorName'), $borrowername);
+ }
+ Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierId'), $borrowernumber);
+ Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername);
}
+
+ $m_rs->metadata( $record->as_xml_record($encoding) );
+ $m_rs->store;
+
ModZebra( $biblionumber, "specialUpdate", "biblioserver", $record );
return $biblionumber;
}