View | Details | Raw Unified | Return to bug 41714
Collapse All | Expand All

(-)a/C4/Heading.pm (-2 / +39 lines)
Lines 31-36 use C4::Context; Link Here
31
use Module::Load qw( load );
31
use Module::Load qw( load );
32
use List::Util   qw( none first );
32
use List::Util   qw( none first );
33
33
34
# Package-level cache for authority types from frameworks
35
my %authority_type_cache;
36
34
=head1 NAME
37
=head1 NAME
35
38
36
C4::Heading
39
C4::Heading
Lines 71-77 sub new_from_field { Link Here
71
    my $frameworkcode = shift;                                    #FIXME this is not used?
74
    my $frameworkcode = shift;                                    #FIXME this is not used?
72
    my $auth          = shift;
75
    my $auth          = shift;
73
    my $marcflavour   = C4::Context->preference('marcflavour');
76
    my $marcflavour   = C4::Context->preference('marcflavour');
74
    my $marc_handler  = _marc_format_handler($marcflavour);
77
78
    # Enable framework lookup for MARC21 if LinkerUseFrameworkAuthTypes is enabled
79
    my $use_frameworks = $marcflavour eq 'MARC21'
80
        && C4::Context->preference('LinkerUseFrameworkAuthTypes');
81
    my $marc_handler = _marc_format_handler( $marcflavour, { use_frameworks => $use_frameworks } );
75
82
76
    return unless $field;
83
    return unless $field;
77
    my $tag = $field->tag();
84
    my $tag = $field->tag();
Lines 304-309 sub _filter_diacritics { Link Here
304
311
305
=head1 INTERNAL FUNCTIONS
312
=head1 INTERNAL FUNCTIONS
306
313
314
=head2 _load_authority_types_from_frameworks
315
316
Load authority type mappings from marc_subfield_structure.
317
Shared by both MARC21 and UNIMARC implementations.
318
Results are cached at package level.
319
320
=cut
321
322
sub _load_authority_types_from_frameworks {
323
    my $cache_key = shift // 'default';
324
325
    unless ( exists $authority_type_cache{$cache_key} ) {
326
        my $dbh = C4::Context->dbh;
327
        my $sth = $dbh->prepare(
328
            "SELECT DISTINCT tagfield, authtypecode
329
             FROM marc_subfield_structure
330
             WHERE frameworkcode = '' AND authtypecode <> ''"
331
        );
332
        $sth->execute();
333
334
        $authority_type_cache{$cache_key} = {};
335
        while ( my ( $tag, $auth_type ) = $sth->fetchrow ) {
336
            $authority_type_cache{$cache_key}->{$tag} = $auth_type;
337
        }
338
    }
339
340
    return $authority_type_cache{$cache_key};
341
}
342
307
=head2 _marc_format_handler
343
=head2 _marc_format_handler
308
344
309
Returns a C4::Heading::MARC21 or C4::Heading::UNIMARC object
345
Returns a C4::Heading::MARC21 or C4::Heading::UNIMARC object
Lines 313-321 depending on the selected MARC flavour. Link Here
313
349
314
sub _marc_format_handler {
350
sub _marc_format_handler {
315
    my $marcflavour = uc shift;
351
    my $marcflavour = uc shift;
352
    my $params      = shift // {};
316
    my $pname       = "C4::Heading::$marcflavour";
353
    my $pname       = "C4::Heading::$marcflavour";
317
    load $pname;
354
    load $pname;
318
    return $pname->new();
355
    return $pname->new($params);
319
}
356
}
320
357
321
=head1 AUTHOR
358
=head1 AUTHOR
(-)a/C4/Heading/MARC21.pm (-4 / +34 lines)
Lines 245-257 my %subdivisions = ( Link Here
245
245
246
=head2 new
246
=head2 new
247
247
248
  my $marc_handler = C4::Heading::MARC21->new();
248
        my $marc_handler = C4::Heading::MARC21->new();
249
        my $marc_handler = C4::Heading::MARC21->new( { use_frameworks => 1 } );
250
251
Creates a new MARC21 heading handler.
252
253
If use_frameworks is true, authority types are loaded from marc_subfield_structure
254
instead of using the hardcoded defaults. This allows local customization of
255
authority types per tag via MARC bibliographic frameworks.
249
256
250
=cut
257
=cut
251
258
252
sub new {
259
sub new {
253
    my $class = shift;
260
    my $class  = shift;
254
    return bless {}, $class;
261
    my $params = shift // {};
262
263
    my $self = bless {}, $class;
264
265
    if ( $params->{use_frameworks} ) {
266
        $self->_load_from_frameworks();
267
    }
268
269
    return $self;
270
}
271
272
=head2 _load_from_frameworks
273
274
Load authority type mappings from marc_subfield_structure.
275
Uses shared method from C4::Heading with package-level caching.
276
277
=cut
278
279
sub _load_from_frameworks {
280
    my $self = shift;
281
    $self->{_framework_overrides} = C4::Heading::_load_authority_types_from_frameworks('marc21');
255
}
282
}
256
283
257
=head2 valid_heading_tag
284
=head2 valid_heading_tag
Lines 331-337 sub parse_heading { Link Here
331
    my $heading_fields = $auth ? {%$auth_heading_fields} : {%$bib_heading_fields};
358
    my $heading_fields = $auth ? {%$auth_heading_fields} : {%$bib_heading_fields};
332
359
333
    my $field_info = $heading_fields->{$tag};
360
    my $field_info = $heading_fields->{$tag};
334
    my $auth_type  = $field_info->{'auth_type'};
361
362
    # Use framework override if available, otherwise use hardcoded default
363
    my $auth_type = $self->{_framework_overrides}->{$tag} // $field_info->{'auth_type'};
364
335
    my $thesaurus =
365
    my $thesaurus =
336
        $tag =~ m/6../
366
        $tag =~ m/6../
337
        ? _get_subject_thesaurus($field)
367
        ? _get_subject_thesaurus($field)
(-)a/C4/Heading/UNIMARC.pm (-10 / +3 lines)
Lines 68-84 sub new { Link Here
68
    my $class = shift;
68
    my $class = shift;
69
69
70
    unless ( defined $bib_heading_fields ) {
70
    unless ( defined $bib_heading_fields ) {
71
        my $dbh = C4::Context->dbh;
71
        my $types = C4::Heading::_load_authority_types_from_frameworks('unimarc');
72
        my $sth = $dbh->prepare(
73
            "SELECT tagfield, authtypecode
74
             FROM marc_subfield_structure
75
             WHERE frameworkcode = '' AND authtypecode <> ''"
76
        );
77
        $sth->execute();
78
        $bib_heading_fields = {};
72
        $bib_heading_fields = {};
79
        while ( my ( $tag, $auth_type ) = $sth->fetchrow ) {
73
        foreach my $tag ( keys %$types ) {
80
            $bib_heading_fields->{$tag} = {
74
            $bib_heading_fields->{$tag} = {
81
                auth_type => $auth_type,
75
                auth_type => $types->{$tag},
82
                subfields => 'abcdefghjklmnopqrstvxyz',
76
                subfields => 'abcdefghjklmnopqrstvxyz',
83
            };
77
            };
84
        }
78
        }
85
- 

Return to bug 41714