[Koha-patches] [PATCH] Analytical record: Insert UNIMARC support in API e cgi, I set the variable $marcflavour or used C4::Context->preference('marcflavour')
Zeno Tajoli
tajoli at cile.it
Mon Nov 29 12:17:54 CET 2010
From: Zeno Tajoli <tajoli at cilea.it>
---
C4/Biblio.pm | 40 ++++++++++++++++++++++++++--------------
C4/Items.pm | 34 +++++++++++++++++++++++++---------
C4/Search.pm | 24 +++++++++++++++++++++++-
cataloguing/addbiblio.pl | 3 ++-
cataloguing/additem.pl | 17 ++++++++++++++---
cataloguing/linkitem.pl | 8 ++++++--
opac/opac-detail.pl | 28 ++++++++++++++++++++++------
7 files changed, 118 insertions(+), 36 deletions(-)
diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index eb6ea42..692f1a8 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -1572,13 +1572,13 @@ sub GetMarcHosts {
$title_subf = "a";
$bibnumber_subf ="w";
$itemnumber_subf='o';
- }
- elsif ($marcflavour eq "UNIMARC") {
+ };
+ if ($marcflavour eq "UNIMARC") {
$tag = "461";
$title_subf = "t";
$bibnumber_subf ="0";
$itemnumber_subf='9';
- }
+ };
my @marchosts;
@@ -1666,23 +1666,35 @@ sub TransformKohaToMarc {
=head2 PrepHostMarcField
- $hostfield = PrepHostMarcField ( $hostbiblionumber )
+ $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
=cut
sub PrepHostMarcField {
- my ($hostbiblionumber,$hostitemnumber) = @_;
- my $hostrecord = GetMarcBiblio($hostbiblionumber);
-
- my $hostmarcfield = MARC::Field->new(
- 773, '', '',
- 'w' => $hostbiblionumber,
- 'o' => $hostitemnumber,
- 'a' => $hostrecord->subfield('245','a'),
- 'x' => $hostrecord->subfield('245','x')
- );
+ my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
+ $marcflavour ||="MARC21";
+
+ my $hostrecord = GetMarcBiblio($hostbiblionumber);
+
+ if ( $marcflavour eq "MARC21" ) {
+ my $hostmarcfield = MARC::Field->new(
+ 773, '', '',
+ 'w' => $hostbiblionumber,
+ 'o' => $hostitemnumber,
+ 'a' => $hostrecord->subfield('245','a'),
+ 'x' => $hostrecord->subfield('245','x')
+ );
+ };
+ if ($marcflavour eq "UNIMARC") {
+ my $hostmarcfield = MARC::Field->new(
+ 461, '', '',
+ '0' => $hostbiblionumber,
+ 't' => $hostrecord->subfield('200','a'),
+ '9' => $hostitemnumber
+ );
+ };
return $hostmarcfield;
}
diff --git a/C4/Items.pm b/C4/Items.pm
index 1f82db1..ac3c9ec 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -1323,7 +1323,6 @@ sub GetItemsInfo {
=head2 GetHostItemsInfo
$hostiteminfo = GetHostItemsInfo($hostfield);
-
Returns the iteminfo for items linked to records via a host field
=cut
@@ -1332,8 +1331,8 @@ sub GetHostItemsInfo {
my ($record) = @_;
my @returnitemsInfo;
- #MARC21 mapping, UNIMARC to be added
- foreach my $hostfield ( $record->field('773') ) {
+ if ( C4::Context->preference('marcflavour') eq 'MARC21'){
+ foreach my $hostfield ( $record->field('773') ) {
my $hostbiblionumber = $hostfield->subfield("w");
my $linkeditemnumber = $hostfield->subfield("o");
my @hostitemInfos = GetItemsInfo($hostbiblionumber);
@@ -1343,6 +1342,20 @@ sub GetHostItemsInfo {
last;
}
}
+ }
+ }
+ if ( C4::Context->preference('marcflavour') eq 'UNIMARC'){
+ foreach my $hostfield ( $record->field('461') ) {
+ my $hostbiblionumber = $hostfield->subfield("0");
+ my $linkeditemnumber = $hostfield->subfield("9");
+ my @hostitemInfos = GetItemsInfo($hostbiblionumber);
+ foreach my $hostitemInfo (@hostitemInfos){
+ if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
+ push (@returnitemsInfo,$hostitemInfo);
+ last;
+ }
+ }
+ }
}
return @returnitemsInfo;
}
@@ -1449,12 +1462,15 @@ references on array of itemnumbers.
sub get_hostitemnumbers_of {
my ($biblionumber) = @_;
my $marcrecord = GetMarcBiblio($biblionumber);
- my @returnhostitemnumbers;
-
- #MARC21 mapping, UNIMARC to be added
- foreach my $hostfield ( $marcrecord->field('773') ) {
- my $hostbiblionumber = $hostfield->subfield("w");
- my $linkeditemnumber = $hostfield->subfield("o");
+ my (@returnhostitemnumbers,$tag, $biblio_s, $item_s);
+
+ my $marcflavor = C4::Context->preference('marcflavour');
+ if ($marcflavor eq 'MARC21'){$tag='773';$biblio_s='w';$item_s='o'};
+ if ($marcflavor eq 'UNIMARC'){$tag='461';$biblio_s='0';$item_s='9'};
+
+ foreach my $hostfield ( $marcrecord->field($tag) ) {
+ my $hostbiblionumber = $hostfield->subfield($biblio_s);
+ my $linkeditemnumber = $hostfield->subfield($item_s);
my @itemnumbers;
if (my $itemnumbers = get_itemnumbers_of($hostbiblionumber)->{$hostbiblionumber})
{
diff --git a/C4/Search.pm b/C4/Search.pm
index 7795b6f..74ae142 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1502,7 +1502,8 @@ sub searchResults {
my @fields = $marcrecord->field($itemtag);
# adding linked items that belong to host records
- foreach my $hostfield ( $marcrecord->field('773')) {
+ if ($marcflavor eq 'MARC21'){
+ foreach my $hostfield ( $marcrecord->field('773')) {
my $hostbiblionumber = $hostfield->subfield("w");
my $linkeditemnumber = $hostfield->subfield("o");
if(!$hostbiblionumber eq undef){
@@ -1519,6 +1520,27 @@ sub searchResults {
}
}
}
+ }
+ }
+ if ($marcflavor eq 'UNIMARC'){
+ foreach my $hostfield ( $marcrecord->field('461')) {
+ my $hostbiblionumber = $hostfield->subfield("0");
+ my $linkeditemnumber = $hostfield->subfield("9");
+ if(!$hostbiblionumber eq undef){
+ my $hostbiblio = GetMarcBiblio($hostbiblionumber);
+ if(!$hostbiblio eq undef){
+ my @hostitems = $hostbiblio->field('995');
+ foreach my $hostitem (@hostitems){
+ if ($hostitem->subfield("9") eq $linkeditemnumber){
+ my $linkeditem =$hostitem;
+ # append linked items if they exist
+ if (!$linkeditem eq undef){
+ push (@fields, $linkeditem);}
+ }
+ }
+ }
+ }
+ }
}
# Setting item statuses for display
diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index 79b8d17..0bbd237 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -894,8 +894,9 @@ if ($breedingid) {
}
#populate hostfield if hostbiblionumber is available
if ($hostbiblionumber){
+ my $marcflavour = C4::Context->preference("marcflavour");
$record=MARC::Record->new();
- my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber);
+ my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber,$marcflavour);
$record->append_fields($field);
}
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 32c7a4f..869e612 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -97,6 +97,7 @@ my $biblionumber = $input->param('biblionumber');
my $itemnumber = $input->param('itemnumber');
my $op = $input->param('op');
my $hostitemnumber = $input->param('hostitemnumber');
+my $marcflavour = C4::Context->preference("marcflavour");
my $frameworkcode = &GetFrameworkCode($biblionumber);
@@ -302,12 +303,22 @@ if ($op eq "additem") {
}
$nextop="additem";
} elsif ($op eq "delinkitem"){
- foreach my $field ($record->field('773')){
+ if ($marcflavour eq 'MARC21'){
+ foreach my $field ($record->field('773')){
if ($field->subfield('o') eq $hostitemnumber){
$record->delete_field($field);
last;
}
+ }
}
+ if ($marcflavour eq 'UNIMARC'){
+ foreach my $field ($record->field('461')){
+ if ($field->subfield('9') eq $hostitemnumber){
+ $record->delete_field($field);
+ last;
+ }
+ }
+ }
my $modbibresult = ModBiblio($record, $biblionumber,'');
}
@@ -585,9 +596,9 @@ foreach my $tag (sort keys %{$tagslib}) {
$subfield_data{marc_value} = qq(<input type="text" $attributes />);
}
elsif ( length($value) > 100
- or (C4::Context->preference("marcflavour") eq "UNIMARC" and
+ or ($marcflavour eq "UNIMARC" and
300 <= $tag && $tag < 400 && $subfield eq 'a' )
- or (C4::Context->preference("marcflavour") eq "MARC21" and
+ or ($marcflavour eq "MARC21" and
500 <= $tag && $tag < 600 )
) {
# oversize field (textarea)
diff --git a/cataloguing/linkitem.pl b/cataloguing/linkitem.pl
index d4959ad..33a8397 100755
--- a/cataloguing/linkitem.pl
+++ b/cataloguing/linkitem.pl
@@ -45,7 +45,11 @@ my ($template, $loggedinuser, $cookie)
});
my $biblio = GetMarcBiblio($biblionumber);
-$template->param(bibliotitle => $biblio->subfield('245','a'));
+my $marcflavour = C4::Context->preference("marcflavour");
+$marcflavour ||="MARC21";
+if ($marcflavour eq 'MARC21'){$template->param(bibliotitle => $biblio->subfield('245','a'))};
+if ($marcflavour eq 'UNIMARC'){$template->param(bibliotitle => $biblio->subfield('200','a'))};
+
$template->param(biblionumber => $biblionumber);
if ($barcode && $biblionumber) {
@@ -57,7 +61,7 @@ if ($barcode && $biblionumber) {
my $hostbiblionumber = GetBiblionumberFromItemnumber($hostitemnumber);
if ($hostbiblionumber) {
- my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber);
+ my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber,$marcflavour);
$biblio->append_fields($field);
my $modresult = ModBiblio($biblio, $biblionumber, '');
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index 0487783..48ec720 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -80,16 +80,33 @@ $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowChec
my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
# adding items linked via host biblios
- foreach my $hostfield ( $record->field('773')) {
+my $marcflavour = C4::Context->preference("marcflavour");
+
+
+if ($marcflavour eq 'MARC21'){
+ foreach my $hostfield ( $record->field('773')) {
my $hostbiblionumber = $hostfield->subfield("w");
my $linkeditemnumber = $hostfield->subfield("o");
my @hostitemInfos = GetItemsInfo($hostbiblionumber);
foreach my $hostitemInfo (@hostitemInfos){
- if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
- push(@all_items, $hostitemInfo);
- }
- }
+ if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
+ push(@all_items, $hostitemInfo);
+ }
+ }
}
+}
+if ($marcflavour eq 'UNIMARC'){
+ foreach my $hostfield ( $record->field('461')) {
+ my $hostbiblionumber = $hostfield->subfield("0");
+ my $linkeditemnumber = $hostfield->subfield("9");
+ my @hostitemInfos = GetItemsInfo($hostbiblionumber);
+ foreach my $hostitemInfo (@hostitemInfos){
+ if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
+ push(@all_items, $hostitemInfo);
+ }
+ }
+ }
+}
my @items;
@items = @all_items unless C4::Context->preference('hidelostitems');
@@ -209,7 +226,6 @@ for my $itm (@items) {
## get notes and subjects from MARC record
my $dbh = C4::Context->dbh;
-my $marcflavour = C4::Context->preference("marcflavour");
my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
--
1.6.0.4
More information about the Koha-patches
mailing list