3 # Copyright (C) 2008 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 our $VERSION = 3.07.00.049;
37 my $heading = C4::Heading->new_from_bib_field($field, $frameworkcode);
38 my $thesaurus = $heading->thesaurus();
39 my $type = $heading->type();
40 my $display_heading = $heading->display_form();
41 my $search_form = $heading->search_form();
45 C<C4::Heading> implements a simple class to representing
46 headings found in bibliographic and authority records.
50 =head2 new_from_bib_field
52 my $heading = C4::Heading->new_from_bib_field($field, $frameworkcode, [, $marc_flavour]);
54 Given a C<MARC::Field> object containing a heading from a
55 bib record, create a C<C4::Heading> object.
57 The optional second parameter is the MARC flavour (i.e., MARC21
58 or UNIMARC); if this parameter is not supplied, it is
59 taken from the Koha application context.
61 If the MARC field supplied is not a valid heading, undef
66 sub new_from_bib_field
{
69 my $frameworkcode = shift;
70 my $marcflavour = @_ ?
shift : C4
::Context
->preference('marcflavour');
72 my $marc_handler = _marc_format_handler
($marcflavour);
74 my $tag = $field->tag();
75 return unless $marc_handler->valid_bib_heading_tag( $tag, $frameworkcode );
78 $self->{'field'} = $field;
80 $self->{'auth_type'}, $self->{'thesaurus'},
81 $self->{'search_form'}, $self->{'display_form'},
83 ) = $marc_handler->parse_heading($field);
91 my $auth_type = $heading->auth_type();
93 Return the auth_type of the heading.
99 return $self->{'auth_type'};
104 my $field = $heading->field();
106 Return the MARC::Field the heading is based on.
112 return $self->{'field'};
117 my $display = $heading->display_form();
119 Return the "canonical" display form of the heading.
125 return $self->{'display_form'};
130 my $search_form = $heading->search_form();
132 Return the "canonical" search form of the heading.
138 return $self->{'search_form'};
143 my $authorities = $heading->authorities([$skipmetadata]);
145 Return a list of authority records for this
146 heading. If passed a true value for $skipmetadata,
147 SearchAuthorities will return only authids.
153 my $skipmetadata = shift;
154 my ( $results, $total ) = _search
( $self, 'match-heading', $skipmetadata );
158 =head2 preferred_authorities
160 my $preferred_authorities = $heading->preferred_authorities;
162 Return a list of authority records for headings
163 that are a preferred form of the heading.
167 sub preferred_authorities
{
169 my $skipmetadata = shift || undef;
170 my ( $results, $total ) = _search
( 'see-from', $skipmetadata );
174 =head1 INTERNAL METHODS
182 my $index = shift || undef;
183 my $skipmetadata = shift || undef;
191 push @marclist, $index;
193 push @operator, $self->{'match_type'};
194 push @value, $self->{'search_form'};
197 # if ($self->{'thesaurus'}) {
198 # push @marclist, 'thesaurus';
199 # push @and_or, 'and';
200 # push @excluding, '';
201 # push @operator, 'is';
202 # push @value, $self->{'thesaurus'};
204 require C4
::AuthoritiesMarc
;
205 return C4
::AuthoritiesMarc
::SearchAuthorities
(
206 \
@marclist, \
@and_or, \
@excluding, \
@operator,
207 \
@value, 0, 20, $self->{'auth_type'},
208 'AuthidAsc', $skipmetadata
212 =head1 INTERNAL FUNCTIONS
214 =head2 _marc_format_handler
216 Returns a C4::Heading::MARC21 or C4::Heading::UNIMARC object
217 depending on the selected MARC flavour.
221 sub _marc_format_handler
{
222 my $marcflavour = uc shift;
223 $marcflavour = 'MARC21' if ( $marcflavour eq 'NORMARC' );
224 my $pname = "C4::Heading::$marcflavour";
226 return $pname->new();
231 Koha Development Team <http://koha-community.org/>
233 Galen Charlton <galen.charlton@liblime.com>