Bug 17600: Standardize our EXPORT_OK
[srvgit] / C4 / Heading / UNIMARC.pm
index 7925345..9767f75 100644 (file)
@@ -4,27 +4,25 @@ package C4::Heading::UNIMARC;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use 5.010;
 use strict;
 use warnings;
-use MARC::Record;
 use MARC::Field;
 use C4::Context;
 
-our $VERSION = 3.00;
 
 =head1 NAME
 
@@ -53,8 +51,8 @@ FIXME - this should be moved to a configuration file.
 my %subdivisions = (
     'j' => 'formsubdiv',
     'x' => 'generalsubdiv',
-    'y' => 'chronologicalsubdiv',
-    'z' => 'geographicsubdiv',
+    'y' => 'geographicsubdiv',
+    'z' => 'chronologicalsubdiv',
 );
 
 my $bib_heading_fields;
@@ -88,15 +86,30 @@ sub new {
     return bless {}, $class;
 }
 
-=head2 valid_bib_heading_tag
+=head2 valid_heading_tag
 
 =cut
 
-sub valid_bib_heading_tag {
+sub valid_heading_tag {
     my ( $self, $tag ) = @_;
     return $bib_heading_fields->{$tag};
 }
 
+=head2 valid_heading_subfield
+
+=cut
+
+sub valid_heading_subfield {
+    my $self          = shift;
+    my $tag           = shift;
+    my $subfield      = shift;
+
+    if ( exists $bib_heading_fields->{$tag} ) {
+        return 1 if ($bib_heading_fields->{$tag}->{subfields} =~ /$subfield/);
+    }
+    return 0;
+}
+
 =head2 parse_heading
 
 =cut
@@ -146,14 +159,19 @@ sub _get_search_heading {
         my $code    = $subfields[$i]->[0];
         my $code_re = quotemeta $code;
         my $value   = $subfields[$i]->[1];
-        $value =~ s/[-,.:=;!%\/]*$//;
+        $value =~ s/[\s]*[-,.:=;!%\/][\s]*$//;
         next unless $subfields =~ qr/$code_re/;
         if ($first) {
             $first   = 0;
             $heading = $value;
         }
         else {
-            $heading .= " $value";
+            if ( exists $subdivisions{$code} ) {
+                $heading .= " $subdivisions{$code} $value";
+            }
+            else {
+                $heading .= " $value";
+            }
         }
     }