1 package C4
::Heading
::UNIMARC
;
3 # Copyright (C) 2011 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 our $VERSION = 3.07.00.049;
35 use C4::Heading::UNIMARC;
39 This is an internal helper class used by
40 C<C4::Heading> to parse headings data from
41 UNIMARC records. Object of this type
42 do not carry data, instead, they only
45 =head1 DATA STRUCTURES
47 FIXME - this should be moved to a configuration file.
55 'x' => 'generalsubdiv',
56 'y' => 'chronologicalsubdiv',
57 'z' => 'geographicsubdiv',
60 my $bib_heading_fields;
66 my $marc_handler = C4::Heading::UNIMARC->new();
73 my $dbh = C4
::Context
->dbh;
74 my $sth = $dbh->prepare(
75 "SELECT tagfield, authtypecode
76 FROM marc_subfield_structure
77 WHERE frameworkcode = '' AND authtypecode <> ''"
80 $bib_heading_fields = {};
81 while ( my ( $tag, $auth_type ) = $sth->fetchrow ) {
82 $bib_heading_fields->{$tag} = {
83 auth_type
=> $auth_type,
84 subfields
=> 'abcdefghjklmnopqrstvxyz',
88 return bless {}, $class;
91 =head2 valid_bib_heading_tag
95 sub valid_bib_heading_tag
{
96 my ( $self, $tag ) = @_;
97 return $bib_heading_fields->{$tag};
105 my ( $self, $field ) = @_;
107 my $tag = $field->tag;
108 my $field_info = $bib_heading_fields->{$tag};
109 my $auth_type = $field_info->{'auth_type'};
111 _get_search_heading
( $field, $field_info->{'subfields'} );
112 my $display_heading =
113 _get_display_heading
( $field, $field_info->{'subfields'} );
115 return ( $auth_type, undef, $search_heading, $display_heading, 'exact' );
118 =head1 INTERNAL FUNCTIONS
120 =head2 _get_subject_thesaurus
124 sub _get_subject_thesaurus
{
127 my $thesaurus = "notdefined";
128 my $sf2 = $field->subfield('2');
129 $thesaurus = $sf2 if defined($sf2);
134 =head2 _get_search_heading
138 sub _get_search_heading
{
140 my $subfields = shift;
143 my @subfields = $field->subfields();
145 for ( my $i = 0 ; $i <= $#subfields ; $i++ ) {
146 my $code = $subfields[$i]->[0];
147 my $code_re = quotemeta $code;
148 my $value = $subfields[$i]->[1];
149 $value =~ s/[-,.:=;!%\/]*$//;
150 next unless $subfields =~ qr/$code_re/;
156 $heading .= " $value";
160 # remove characters that are part of CCL syntax
161 $heading =~ s/[)(=]//g;
166 =head2 _get_display_heading
170 sub _get_display_heading
{
172 my $subfields = shift;
175 my @subfields = $field->subfields();
177 for ( my $i = 0 ; $i <= $#subfields ; $i++ ) {
178 my $code = $subfields[$i]->[0];
179 my $code_re = quotemeta $code;
180 my $value = $subfields[$i]->[1];
181 next unless $subfields =~ qr/$code_re/;
187 if ( exists $subdivisions{$code} ) {
188 $heading .= "--$value";
191 $heading .= " $value";
200 Koha Development Team <http://koha-community.org/>
202 Jared Camins-Esakov <jcamins@cpbibliography.com>