[Koha-patches] [PATCH] Analytical records: Moving get host items code into a C4 routine, also calling the new routine in related perl scripts

savitra.sirohi at osslabs.biz savitra.sirohi at osslabs.biz
Tue Nov 16 07:02:44 CET 2010


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

---
 C4/Items.pm             |   30 ++++++++++++++++++++++++++++++
 catalogue/detail.pl     |   17 +++++------------
 catalogue/moredetail.pl |   17 +++++------------
 3 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index 264fa5b..c0c223a 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -64,6 +64,7 @@ BEGIN {
         GetItemInfosOf
         GetItemsByBiblioitemnumber
         GetItemsInfo
+	GetHostItemsInfo
         get_itemnumbers_of
         GetItemnumberFromBarcode
         GetBarcodeFromItemnumber
@@ -1317,6 +1318,35 @@ sub GetItemsInfo {
 	}
 }
 
+
+=head2 GetHostItemsInfo
+
+	$hostiteminfo = GetHostItemsInfo($hostfield);
+
+	Returns the iteminfo for items linked to records via a host field
+
+=cut
+
+sub GetHostItemsInfo {
+	my ($record) = @_;
+	my @returnitemsInfo;
+
+	#MARC21 mapping, UNIMARC to be added
+	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 (@returnitemsInfo,$hostitemInfo);
+				last;
+                	}
+        	}
+	}
+	return @returnitemsInfo;
+}
+
+
 =head2 GetLastAcquisitions
 
   my $lastacq = GetLastAcquisitions({'branches' => ('branch1','branch2'), 
diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index 4dd5ddf..72324de 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -105,18 +105,11 @@ my @items = &GetItemsInfo( $biblionumber, 'intra' );
 # flag indicating existence of at least one item linked via a host record
 my $hostrecords;
 # adding items linked via host biblios
-   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){
-                        $hostrecords =1;
-                        push(@items, $hostitemInfo);
-                }
-         }
-    }
-
+my @hostitems = GetHostItemsInfo($record);
+if (@hostitems){
+	$hostrecords =1;
+	push (@items, at hostitems);
+}
 
 my $dat = &GetBiblioData($biblionumber);
 
diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl
index 05a5a60..097d1ff 100755
--- a/catalogue/moredetail.pl
+++ b/catalogue/moredetail.pl
@@ -78,18 +78,11 @@ my $record=GetMarcBiblio($biblionumber);
 
 my $hostrecords;
 # adding items linked via host biblios
-   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){
-                        $hostrecords =1;
-                        push(@items, $hostitemInfo);
-                }
-         }
-    }
-
+my @hostitems = GetHostItemsInfo($record);
+if (@hostitems){
+        $hostrecords =1;
+        push (@items, at hostitems);
+}
 
 my $count=@items;
 $data->{'count'}=$count;
-- 
1.5.4.5



More information about the Koha-patches mailing list