[Koha-patches] [PATCH] tools/export add options remove non-local biblio and item format

Michael Hafen mdhafen at tech.washk12.org
Tue Sep 29 22:03:19 CEST 2009


Added an option to skip biblios that doen't have a copy at the users branch
Added an option to map the item fields to a different tag and subfields.  I
tried to follow the MARC21 and UNIMARC Recommendation 995 specs.  I couldn't
find the UNIMARC spec, so I guessed from what's already in Koha.  In the MARC21
mapping there is one non-standard subfield, used by Follett, for price.
---
 .../prog/en/modules/tools/export.tmpl              |   16 ++++
 tools/export.pl                                    |   81 +++++++++++++++++---
 2 files changed, 85 insertions(+), 12 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tmpl
index 33387e2..ea78b9a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tmpl
@@ -113,6 +113,22 @@ Calendar.setup(
         <input id="strip_nonlocal_items" type="checkbox" name="strip_nonlocal_items" />
         <!-- /TMPL_IF -->
         </li>
+	<li>
+	<label for="strip_nonlocal_biblios">Remove non-local biblios</label>
+        <!-- TMPL_IF NAME="Independant_Branches" -->
+	<input id="strip_nonlocal_biblios" name="strip_nonlocal_biblios" type="checkbox" checked="checked" />
+        <!-- TMPL_ELSE -->
+	<input id="strip_nonlocal_biblios" name="strip_nonlocal_biblios" type="checkbox" />
+        <!-- /TMPL_IF -->
+	</li>
+	<li>
+	<label for="item_format">Item Format</label>
+	<select id="item_format" name="item_format">
+		<option value="KOHA">Koha</option>
+		<option value="MARC21">MARC 21</option>
+		<option value="UNIMARC">UNIMARC</option>
+	</select>
+	</li>
         <li>
         <label for="dont_export_fields">Don't export fields</label>
         <input id="dont_export_fields" type="text" name="dont_export_fields" />
diff --git a/tools/export.pl b/tools/export.pl
index 5195bac..c9b7445 100755
--- a/tools/export.pl
+++ b/tools/export.pl
@@ -55,17 +55,19 @@ if ( $op eq "export" ) {
         -attachment => $filename
     );
 
-    my $StartingBiblionumber = $query->param("StartingBiblionumber");
-    my $EndingBiblionumber   = $query->param("EndingBiblionumber");
-    my $output_format        = $query->param("output_format");
-    my $itemtype             = $query->param("itemtype");
-    my $start_callnumber     = $query->param("start_callnumber");
-    my $end_callnumber       = $query->param("end_callnumber");
-    my $start_accession      = ( $query->param("start_accession") ) ? C4::Dates->new( $query->param("start_accession") ) : '';
-    my $end_accession        = ( $query->param("end_accession") ) ? C4::Dates->new( $query->param("end_accession") ) : '';
-    my $dont_export_items    = $query->param("dont_export_item");
-    my $strip_nonlocal_items = $query->param("strip_nonlocal_items");
-    my $dont_export_fields   = $query->param("dont_export_fields");
+    my $StartingBiblionumber   = $query->param("StartingBiblionumber");
+    my $EndingBiblionumber     = $query->param("EndingBiblionumber");
+    my $output_format          = $query->param("output_format");
+    my $itemtype               = $query->param("itemtype");
+    my $start_callnumber       = $query->param("start_callnumber");
+    my $end_callnumber         = $query->param("end_callnumber");
+    my $start_accession        = ( $query->param("start_accession") ) ? C4::Dates->new( $query->param("start_accession") ) : '';
+    my $end_accession          = ( $query->param("end_accession") ) ? C4::Dates->new( $query->param("end_accession") ) : '';
+    my $dont_export_items      = $query->param("dont_export_item");
+    my $strip_nonlocal_items   = $query->param("strip_nonlocal_items");
+    my $strip_nonlocal_biblios = $query->param("strip_nonlocal_biblios");
+    my $item_format            = $query->param("item_format");
+    my $dont_export_fields     = $query->param("dont_export_fields");
     my @sql_params;
 
     my $items_filter =
@@ -130,14 +132,69 @@ if ( $op eq "export" ) {
             next;
         }
         next if not defined $record;
-        if ( $dont_export_items || $strip_nonlocal_items || $limit_ind_branch ) {
+        if ( $dont_export_items || $strip_nonlocal_items || $limit_ind_branch || $strip_nonlocal_biblios ) {
+            my $local_bib;
             my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch', '' );
             # if stripping nonlocal items, use loggedinuser's branch if they didn't select one
             $branch ||= C4::Branch::mybranch();
             for my $itemfield ( $record->field($homebranchfield) ) {
 
+                $local_bib = 1 if ( $itemfield->subfield($homebranchsubfield) eq $branch );
                 $record->delete_field($itemfield) if ( $dont_export_items || ( $itemfield->subfield($homebranchsubfield) ne $branch ) );
             }
+            if ( $strip_nonlocal_biblios && ! $local_bib ) {
+                next;
+            }
+            if ( ! $dont_export_items && $item_format ) {
+                my ($b_tag,$b_sub) = &GetMarcFromKohaField("items.barcode",'');
+                my ($h_tag,$h_sub) = &GetMarcFromKohaField("items.homebranch",'');
+                my ($p_tag,$p_sub) = &GetMarcFromKohaField("items.price",'');
+                my ($p2_tag,$p2_sub) = &GetMarcFromKohaField("items.replacementprice",'');
+                my ($c_tag,$c_sub) = &GetMarcFromKohaField("items.itemcallnumber",'');
+                my ($n_tag,$n_sub) = &GetMarcFromKohaField("items.itemnotes",'');
+                my ($loc_tag,$loc_sub) = &GetMarcFromKohaField("items.location",'');
+                my ($copy_tag,$copy_sub) = &GetMarcFromKohaField("items.copynumber",'');
+                for my $itemfield ( $record->field( $homebranchfield ) ) {
+                    my $barcode = $itemfield->subfield( $b_sub );
+                    my $branch = $itemfield->subfield( $h_sub );
+                    my $price = $itemfield->subfield( $p_sub ) || $itemfield->subfield( $p2_sub );
+                    my $callnum = $itemfield->subfield( $c_sub );
+                    my $notes = $itemfield->subfield( $n_sub );
+                    my $location = $itemfield->subfield( $loc_sub );
+                    my $copy = $itemfield->subfield( $copy_sub );
+
+                    my @subs;
+                    my $temp_field;
+
+                    if ( $item_format eq 'MARC21' ) {
+                        @subs = (
+                            'p', $barcode,
+                            'b', $branch,
+                            '9', $price,  # Follett uses this
+                            'h', $callnum,
+                            'z', $notes,
+                            'c', $location,
+                            't', $copy,
+                        );
+                        $temp_field = MARC::Field->new( '852', '1', '0', @subs );
+                    } elsif ( $item_format eq 'UNIMARC' ) {
+                        @subs = (
+                            'f', $barcode,
+                            'b', $branch,
+                            #'9', $price,  # is there a common non-standard sub?
+                            'k', $callnum,
+                            'u', $notes,
+                            'e', $location,
+                            '7', $copy,
+                        );
+                        $temp_field = MARC::Field->new( '995', '1', '0', @subs );
+                    }
+                    if ( $temp_field ) {
+                        $record->append_fields($temp_field);
+                        $record->delete_field( $itemfield );
+                    }
+                }
+	    }
         }
 
         if ($dont_export_fields) {
-- 
1.6.0.4




More information about the Koha-patches mailing list