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
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>.
36 my $heading = C4::Heading->new_from_bib_field($field, $frameworkcode);
37 my $thesaurus = $heading->thesaurus();
38 my $type = $heading->type();
39 my $display_heading = $heading->display_form();
40 my $search_form = $heading->search_form();
44 C<C4::Heading> implements a simple class to representing
45 headings found in bibliographic and authority records.
49 =head2 new_from_bib_field
51 my $heading = C4::Heading->new_from_bib_field($field, $frameworkcode, [, $marc_flavour]);
53 Given a C<MARC::Field> object containing a heading from a
54 bib record, create a C<C4::Heading> object.
56 The optional second parameter is the MARC flavour (i.e., MARC21
57 or UNIMARC); if this parameter is not supplied, it is
58 taken from the Koha application context.
60 If the MARC field supplied is not a valid heading, undef
65 sub new_from_bib_field
{
68 my $frameworkcode = shift;
69 my $marcflavour = @_ ?
shift : C4
::Context
->preference('marcflavour');
71 my $marc_handler = _marc_format_handler
($marcflavour);
73 my $tag = $field->tag();
74 return unless $marc_handler->valid_bib_heading_tag( $tag, $frameworkcode );
77 $self->{'field'} = $field;
79 $self->{'auth_type'}, $self->{'thesaurus'},
80 $self->{'search_form'}, $self->{'display_form'},
82 ) = $marc_handler->parse_heading($field);
90 my $auth_type = $heading->auth_type();
92 Return the auth_type of the heading.
98 return $self->{'auth_type'};
103 my $field = $heading->field();
105 Return the MARC::Field the heading is based on.
111 return $self->{'field'};
116 my $display = $heading->display_form();
118 Return the "canonical" display form of the heading.
124 return $self->{'display_form'};
129 my $search_form = $heading->search_form();
131 Return the "canonical" search form of the heading.
137 return $self->{'search_form'};
142 my $authorities = $heading->authorities([$skipmetadata]);
144 Return a list of authority records for this
145 heading. If passed a true value for $skipmetadata,
146 SearchAuthorities will return only authids.
152 my $skipmetadata = shift;
153 my ( $results, $total ) = _search
( $self, 'match-heading', $skipmetadata );
157 =head2 preferred_authorities
159 my $preferred_authorities = $heading->preferred_authorities;
161 Return a list of authority records for headings
162 that are a preferred form of the heading.
166 sub preferred_authorities
{
168 my $skipmetadata = shift || undef;
169 my ( $results, $total ) = _search
( 'see-from', $skipmetadata );
173 =head1 INTERNAL METHODS
181 my $index = shift || undef;
182 my $skipmetadata = shift || undef;
190 push @marclist, $index;
192 push @operator, $self->{'match_type'};
193 push @value, $self->{'search_form'};
196 # if ($self->{'thesaurus'}) {
197 # push @marclist, 'thesaurus';
198 # push @and_or, 'and';
199 # push @excluding, '';
200 # push @operator, 'is';
201 # push @value, $self->{'thesaurus'};
203 require C4
::AuthoritiesMarc
;
204 return C4
::AuthoritiesMarc
::SearchAuthorities
(
205 \
@marclist, \
@and_or, \
@excluding, \
@operator,
206 \
@value, 0, 20, $self->{'auth_type'},
207 'AuthidAsc', $skipmetadata
211 =head1 INTERNAL FUNCTIONS
213 =head2 _marc_format_handler
215 Returns a C4::Heading::MARC21 or C4::Heading::UNIMARC object
216 depending on the selected MARC flavour.
220 sub _marc_format_handler
{
221 my $marcflavour = uc shift;
222 $marcflavour = 'MARC21' if ( $marcflavour eq 'NORMARC' );
223 my $pname = "C4::Heading::$marcflavour";
225 return $pname->new();
230 Koha Development Team <http://koha-community.org/>
232 Galen Charlton <galen.charlton@liblime.com>