[Koha-patches] [PATCH] Analytical records - move host field population to a C4 routine, all changes in pl files to call new routine

savitra.sirohi at osslabs.biz savitra.sirohi at osslabs.biz
Wed Nov 24 05:46:43 CET 2010


From: Amit Gupta <amit.gupta at osslabs.biz>

Signed-off-by: Amit Gupta <amit.gupta at osslabs.biz>
---
 C4/Biblio.pm             |   25 +++++++++++++++++++++++++
 cataloguing/addbiblio.pl |    7 +++++++
 cataloguing/linkitem.pl  |    9 +--------
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index eb0b248..eb6ea42 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -84,6 +84,7 @@ BEGIN {
       &GetFrameworkCode
       &GetPublisherNameFromIsbn
       &TransformKohaToMarc
+      &PrepHostMarcField
 
       &CountItemsIssued
     );
@@ -1663,6 +1664,30 @@ sub TransformKohaToMarc {
     return $record;
 }
 
+=head2 PrepHostMarcField
+
+    $hostfield = PrepHostMarcField ( $hostbiblionumber )
+
+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')
+                );
+
+    return $hostmarcfield;
+}
+
+
 =head2 TransformKohaToMarcOneField
 
     $record = TransformKohaToMarcOneField( $sth, $record, $kohafieldname, $value, $frameworkcode );
diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index 5111365..e3f69e5 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -929,6 +929,13 @@ if (($biblionumber) && !($breedingid)){
 if ($breedingid) {
     ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
 }
+#populate hostfield if hostbiblionumber is available
+if ($hostbiblionumber){
+	$record=MARC::Record->new();
+	$record->leader('');
+        my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber);
+	$record->append_fields($field);
+}
 
 $is_a_modif = 0;
     
diff --git a/cataloguing/linkitem.pl b/cataloguing/linkitem.pl
index c299a5a..d4959ad 100755
--- a/cataloguing/linkitem.pl
+++ b/cataloguing/linkitem.pl
@@ -55,16 +55,9 @@ if ($barcode && $biblionumber) {
 
     if ($hostitemnumber) {
 	my $hostbiblionumber = GetBiblionumberFromItemnumber($hostitemnumber);
-	my $hostrecord = GetMarcBiblio($hostbiblionumber);
 
 	if ($hostbiblionumber) {
-	        my $field = MARC::Field->new(
-			773, '', '',
-			'w' => $hostbiblionumber,
-			'o' => $hostitemnumber,
-               		'a' => $hostrecord->subfield('245','a'),
-	                'x' => $hostrecord->subfield('245','x')
-                );
+	        my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber);
 		$biblio->append_fields($field);
 
 		my $modresult = ModBiblio($biblio, $biblionumber, ''); 
-- 
1.5.4.5



More information about the Koha-patches mailing list