use vars qw($VERSION @ISA @EXPORT);
BEGIN {
- $VERSION = 1.00;
+ $VERSION = 3.07.00.049;
require Exporter;
@ISA = qw( Exporter );
&ModBiblio
&ModBiblioframework
&ModZebra
+ &UpdateTotalIssues
+ &RemoveAllNsb
);
# To delete something
my ( $biblio_tag, $biblio_subfield ) = GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode );
die qq{No biblionumber tag for framework "$frameworkcode"} unless $biblio_tag;
my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
- die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblio_tag;
+ die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag;
if ( $biblio_tag == $biblioitem_tag ) {
return;
}
+
+=head2 UpdateTotalIssues
+
+ UpdateTotalIssues($biblionumber, $increase, [$value])
+
+Update the total issue count for a particular bib record.
+
+=over 4
+
+=item C<$biblionumber> is the biblionumber of the bib to update
+
+=item C<$increase> is the amount to increase (or decrease) the total issues count by
+
+=item C<$value> is the absolute value that total issues count should be set to. If provided, C<$increase> is ignored.
+
+=back
+
+=cut
+
+sub UpdateTotalIssues {
+ my ($biblionumber, $increase, $value) = @_;
+ my $totalissues;
+
+ my $data = GetBiblioData($biblionumber);
+
+ if (defined $value) {
+ $totalissues = $value;
+ } else {
+ $totalissues = $data->{'totalissues'} + $increase;
+ }
+ my ($totalissuestag, $totalissuessubfield) = GetMarcFromKohaField('biblioitems.totalissues', $data->{'frameworkcode'});
+
+ my $record = GetMarcBiblio($biblionumber);
+
+ my $field = $record->field($totalissuestag);
+ if (defined $field) {
+ $field->update( $totalissuessubfield => $totalissues );
+ } else {
+ $field = MARC::Field->new($totalissuestag, '0', '0',
+ $totalissuessubfield => $totalissues);
+ $record->insert_grouped_field($field);
+ }
+
+ ModBiblio($record, $biblionumber, $data->{'frameworkcode'});
+ return;
+}
+
+=head2 RemoveAllNsb
+
+ &RemoveAllNsb($record);
+
+Removes all nsb/nse chars from a record
+
+=cut
+
+sub RemoveAllNsb {
+ my $record = shift;
+
+ SetUTF8Flag($record);
+
+ foreach my $field ($record->fields()) {
+ if ($field->is_control_field()) {
+ $field->update(nsb_clean($field->data()));
+ } else {
+ my @subfields = $field->subfields();
+ my @new_subfields;
+ foreach my $subfield (@subfields) {
+ push @new_subfields, $subfield->[0] => nsb_clean($subfield->[1]);
+ }
+ if (scalar(@new_subfields) > 0) {
+ my $new_field;
+ eval {
+ $new_field = MARC::Field->new(
+ $field->tag(),
+ $field->indicator(1),
+ $field->indicator(2),
+ @new_subfields
+ );
+ };
+ if ($@) {
+ warn "error in RemoveAllNsb : $@";
+ } else {
+ $field->replace_with($new_field);
+ }
+ }
+ }
+ }
+
+ return $record;
+}
+
1;