GetMarcUrls
&GetUsedMarcStructure
&GetXmlBiblio
- &GetCOinSBiblio
+ &GetCOinSBiblio
&GetAuthorisedValueDesc
&GetMarcStructure
&GetFrameworkCode
&GetPublisherNameFromIsbn
&TransformKohaToMarc
+
+ &CountItemsIssued
);
# To modify something
);
}
+eval {
+ my $servers = C4::Context->config('memcached_servers');
+ if ($servers) {
+ require Memoize::Memcached;
+ import Memoize::Memcached qw(memoize_memcached);
+
+ my $memcached = {
+ servers => [ $servers ],
+ key_prefix => C4::Context->config('memcached_namespace') || 'koha',
+ };
+ memoize_memcached('GetMarcStructure', memcached => $memcached, expire_time => 600); #cache for 10 minutes
+ }
+};
=head1 NAME
C4::Biblio - cataloging management functions
return $marc_structure_cache->{$forlibrarian}->{$frameworkcode};
}
- my $sth;
- my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
-
- # check that framework exists
- $sth =
- $dbh->prepare(
+ my $sth = $dbh->prepare(
"SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode=?");
$sth->execute($frameworkcode);
my ($total) = $sth->fetchrow;
$frameworkcode = "" unless ( $total > 0 );
- $sth =
- $dbh->prepare(
+ $sth = $dbh->prepare(
"SELECT tagfield,liblibrarian,libopac,mandatory,repeatable
FROM marc_tag_structure
WHERE frameworkcode=?
ORDER BY tagfield"
- );
+ );
$sth->execute($frameworkcode);
my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
$res->{$tag}->{repeatable} = $repeatable;
}
- $sth =
- $dbh->prepare(
- "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue
- FROM marc_subfield_structure
- WHERE frameworkcode=?
- ORDER BY tagfield,tagsubfield
- "
+ $sth = $dbh->prepare(
+ "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue
+ FROM marc_subfield_structure
+ WHERE frameworkcode=?
+ ORDER BY tagfield,tagsubfield
+ "
);
$sth->execute($frameworkcode);
while (
(
$tag, $subfield, $liblibrarian,
- , $libopac, $tab,
+ $libopac, $tab,
$mandatory, $repeatable, $authorised_value,
$authtypecode, $value_builder, $kohafield,
$seealso, $hidden, $isurl,
=head2 GetUsedMarcStructure
- the same function as GetMarcStructure expcet it just take field
+ the same function as GetMarcStructure except it just takes field
in tab 0-9. (used field)
my $results = GetUsedMarcStructure($frameworkcode);
sub GetUsedMarcStructure($){
my $frameworkcode = shift || '';
- my $dbh = C4::Context->dbh;
my $query = qq/
SELECT *
FROM marc_subfield_structure
WHERE tab > -1
AND frameworkcode = ?
+ ORDER BY tagfield, tagsubfield
/;
- my @results;
- my $sth = $dbh->prepare($query);
+ my $sth = C4::Context->dbh->prepare($query);
$sth->execute($frameworkcode);
- while (my $row = $sth->fetchrow_hashref){
- push @results,$row;
- }
- return \@results;
+ return $sth->fetchall_arrayref({});
}
=head2 GetMarcFromKohaField
my ( $record, $marcflavour ) = @_;
my ( $mintag, $maxtag );
# tagslib useful for UNIMARC author reponsabilities
- my $tagslib = &GetMarcStructure( 1, '' ); # FIXME : we don't have the framework available, we take the default framework. May be bugguy on some setups, will be usually correct.
+ my $tagslib = &GetMarcStructure( 1, '' ); # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
if ( $marcflavour eq "MARC21" ) {
$mintag = "700";
$maxtag = "720";
sub TransformHtmlToXml {
my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_;
my $xml = MARC::File::XML::header('UTF-8');
+ $xml .= "<record>\n";
$auth_type = C4::Context->preference('marcflavour') unless $auth_type;
MARC::File::XML->default_record_format($auth_type);
# in UNIMARC, field 100 contains the encoding
warn "Indicator in @$tags[$i] is empty";
$ind2 = " ";
}
- $xml .=
-"<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
- $xml .=
-"<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+ $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
$first = 0;
}
else {
# rest of the fixed fields
}
elsif ( @$tags[$i] < 10 ) {
- $xml .=
-"<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
+ $xml .= "<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
$first = 1;
}
else {
my $ind1 = substr( @$indicator[$j], 0, 1 );
my $ind2 = substr( @$indicator[$j], 1, 1 );
- $xml .=
-"<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
- $xml .=
-"<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+ $ind1 = " " if !defined($ind2) or $ind2 eq "";
+ $ind2 = " " if !defined($ind2) or $ind2 eq "";
+ $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
$first = 0;
}
}
if ($first) {
my $ind1 = substr( @$indicator[$j], 0, 1 );
my $ind2 = substr( @$indicator[$j], 1, 1 );
- $xml .=
-"<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $ind1 = " " if !defined($ind2) or $ind2 eq "";
+ $ind2 = " " if !defined($ind2) or $ind2 eq "";
+ $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
$first = 0;
}
- $xml .=
-"<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+ $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
}
}
$prevtag = @$tags[$i];
$xml .= "<subfield code=\"a\">$string</subfield>\n";
$xml .= "</datafield>\n";
}
+ $xml .= "</record>\n";
$xml .= MARC::File::XML::footer();
return $xml;
}
=cut
+sub CountItemsIssued {
+ my ( $biblionumber ) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare('SELECT COUNT(*) as issuedCount FROM items, issues WHERE items.itemnumber = issues.itemnumber AND items.biblionumber = ?');
+ $sth->execute( $biblionumber );
+ my $row = $sth->fetchrow_hashref();
+ return $row->{'issuedCount'};
+}
+
sub _disambiguate {
my ($table, $column) = @_;
if ($column eq "cn_sort" or $column eq "cn_source") {
$tagslib->{$tag}->{$subfield}->{repeatable};
$subfield_data{hidden} = "display:none"
if $tagslib->{$tag}->{$subfield}->{hidden};
- my ( $x, $value );
- ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
- if ($itemrecord);
- $value =~ s/"/"/g;
+ my ( $x, $value );
+ if ($itemrecord) {
+ ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord );
+ }
+ if (!defined $value) {
+ $value = q||;
+ }
+ $value =~ s/"/"/g;
# search for itemcallnumber if applicable
if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
foreach (split / /,$line) {
next unless $_; # skip empty values (multiple spaces)
# if the entry is already here, improve weight
- if ($result{'__RAW__'}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/) {
+ my $tmpstr = $result{'__RAW__'}->{"$_"} || "";
+ if ($tmpstr =~ /$biblionumber,\Q$title\E\-(\d+);/) {
my $weight=$1+1;
$result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
$result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
# it exists
if ($existing_biblionumbers) {
$result{'__RAW__'}->{"$_"} =$existing_biblionumbers;
- my $weight=$1+1;
+ my $weight = ($1 ? $1 : 0) + 1;
$result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
$result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
# create a new ligne for this entry
# deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
if ( $encoding eq "UNIMARC" ) {
- my $string;
- if ( length($record->subfield( 100, "a" )) == 35 ) {
- $string = $record->subfield( 100, "a" );
+ my $string = $record->subfield( 100, "a" );
+ if ( ($string) && ( length($record->subfield( 100, "a" )) == 35 ) ) {
my $f100 = $record->field(100);
$record->delete_field($f100);
}
biblionumber
MARC::Record of the bib
- returns: a hashref malling the authorised value to the value set for this biblionumber
+ returns: a hashref mapping the authorised value to the value set for this biblionumber
$authorised_values = {
'Scent' => 'flowery',