File Coverage

File:C4/Heading.pm
Coverage:28.3%

linestmtbrancondsubtimecode
1package C4::Heading;
2
3# Copyright (C) 2008 LibLime
4#
5# This file is part of Koha.
6#
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
10# version.
11#
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.
15#
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.
19
20
3
3
3
877
21
89
use strict;
21
3
3
3
30
18
170
use warnings;
22
3
3
3
302
12840
175
use MARC::Record;
23
3
3
3
34
23
76
use MARC::Field;
24
3
3
3
170
34
62
use C4::Context;
25
3
3
3
42158
1956
40
use Module::Load;
26
3
3
3
150
16
1898
use Carp;
27
28our $VERSION = 3.00;
29
30 - 64
=head1 NAME

C4::Heading

=head1 SYNOPSIS

 use C4::Heading;
 my $heading = C4::Heading->new_from_bib_field($field, $frameworkcode);
 my $thesaurus = $heading->thesaurus();
 my $type = $heading->type();
 my $display_heading = $heading->display_form();
 my $search_form = $heading->search_form();

=head1 DESCRIPTION

C<C4::Heading> implements a simple class to representing
headings found in bibliographic and authority records.

=head1 METHODS

=head2 new_from_bib_field

  my $heading = C4::Heading->new_from_bib_field($field, $frameworkcode, [, $marc_flavour]);

Given a C<MARC::Field> object containing a heading from a 
bib record, create a C<C4::Heading> object.

The optional second parameter is the MARC flavour (i.e., MARC21
or UNIMARC); if this parameter is not supplied, it is
taken from the Koha application context.

If the MARC field supplied is not a valid heading, undef
is returned.

=cut
65
66sub new_from_bib_field {
67
0
    my $class = shift;
68
0
    my $field = shift;
69
0
    my $frameworkcode = shift;
70
0
    my $marcflavour = @_ ? shift : C4::Context->preference('marcflavour');
71
72
0
    my $marc_handler = _marc_format_handler($marcflavour);
73
74
0
    my $tag = $field->tag();
75
0
    return unless $marc_handler->valid_bib_heading_tag( $tag, $frameworkcode );
76
0
    my $self = {};
77
78
0
    $self->{'field'} = $field;
79    (
80
0
        $self->{'auth_type'}, $self->{'thesaurus'},
81        $self->{'search_form'}, $self->{'display_form'},
82        $self->{'match_type'}
83    ) = $marc_handler->parse_heading($field);
84
85
0
    bless $self, $class;
86
0
    return $self;
87}
88
89 - 95
=head2 auth_type

  my $auth_type = $heading->auth_type();

Return the auth_type of the heading.

=cut
96
97sub auth_type {
98
0
    my $self = shift;
99
0
    return $self->{'auth_type'};
100}
101
102 - 108
=head2 field

  my $field = $heading->field();

Return the MARC::Field the heading is based on.

=cut
109
110sub field {
111
0
    my $self = shift;
112
0
    return $self->{'field'};
113}
114
115 - 121
=head2 display_form

  my $display = $heading->display_form();

Return the "canonical" display form of the heading.

=cut
122
123sub display_form {
124
0
    my $self = shift;
125
0
    return $self->{'display_form'};
126}
127
128 - 134
=head2 search_form

  my $search_form = $heading->search_form();

Return the "canonical" search form of the heading.

=cut
135
136sub search_form {
137
0
    my $self = shift;
138
0
    return $self->{'search_form'};
139}
140
141 - 149
=head2 authorities

  my $authorities = $heading->authorities([$skipmetadata]);

Return a list of authority records for this 
heading. If passed a true value for $skipmetadata,
SearchAuthorities will return only authids.

=cut
150
151sub authorities {
152
0
    my $self = shift;
153
0
    my $skipmetadata = shift;
154
0
    my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata );
155
0
    return $results;
156}
157
158 - 165
=head2 preferred_authorities

  my $preferred_authorities = $heading->preferred_authorities;

Return a list of authority records for headings
that are a preferred form of the heading.

=cut
166
167sub preferred_authorities {
168
0
    my $self = shift;
169
0
    my $skipmetadata = shift || undef;
170
0
    my ( $results, $total ) = _search( 'see-from', $skipmetadata );
171
0
    return $results;
172}
173
174 - 178
=head1 INTERNAL METHODS

=head2 _search

=cut
179
180sub _search {
181
0
    my $self = shift;
182
0
    my $index = shift || undef;
183
0
    my $skipmetadata = shift || undef;
184
0
    my @marclist;
185
0
    my @and_or;
186
0
    my @excluding = [];
187
0
    my @operator;
188
0
    my @value;
189
190
0
    if ($index) {
191
0
        push @marclist, $index;
192
0
        push @and_or, 'and';
193
0
        push @operator, $self->{'match_type'};
194
0
        push @value, $self->{'search_form'};
195    }
196
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'};
203    # }
204
0
    require C4::AuthoritiesMarc;
205
0
    return C4::AuthoritiesMarc::SearchAuthorities(
206        \@marclist, \@and_or, \@excluding, \@operator,
207        \@value, 0, 20, $self->{'auth_type'},
208        '', $skipmetadata
209    );
210}
211
212 - 219
=head1 INTERNAL FUNCTIONS

=head2 _marc_format_handler

Returns a C4::Heading::MARC21 or C4::Heading::UNIMARC object
depending on the selected MARC flavour.

=cut
220
221sub _marc_format_handler {
222
0
    my $marcflavour = uc shift;
223
0
    $marcflavour = 'MARC21' if ( $marcflavour eq 'NORMARC' );
224
0
    my $pname = "C4::Heading::$marcflavour";
225
0
    load $pname;
226
0
    return $pname->new();
227}
228
229 - 235
=head1 AUTHOR

Koha Development Team <http://koha-community.org/>

Galen Charlton <galen.charlton@liblime.com>

=cut
236
2371;