use Koha::ItemTypes;
use Koha::SearchEngine;
use Koha::Libraries;
+use Koha::Util::MARC;
use vars qw($debug $cgi_debug);
$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 $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;
#---- 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
=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 @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'} ) {
};
$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;
}