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

(-)a/C4/Search.pm (-1 / +3 lines)
Lines 1981-1987 sub searchResults { Link Here
1981
                    ),
1981
                    ),
1982
                    fix_amps       => 1,
1982
                    fix_amps       => 1,
1983
                    hidden_items   => \@hiddenitems,
1983
                    hidden_items   => \@hiddenitems,
1984
                    xslt_variables => $xslt_variables
1984
                    xslt_variables => $xslt_variables,
1985
                    branches => \%branches,
1986
                    itemtypes => \%itemtypes
1985
                }
1987
                }
1986
            );
1988
            );
1987
        }
1989
        }
(-)a/C4/XSLT.pm (-21 / +39 lines)
Lines 62-68 Replaces codes with authorized values in a MARC::Record object Link Here
62
=cut
62
=cut
63
63
64
sub transformMARCXML4XSLT {
64
sub transformMARCXML4XSLT {
65
    my ($biblionumber, $record, $opac) = @_;
65
    my ($biblionumber, $record, $opac, $branches, $itemtypes, $av) = @_;
66
    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
66
    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
67
    my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 });
67
    my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 });
68
    my @fields;
68
    my @fields;
Lines 72-97 sub transformMARCXML4XSLT { Link Here
72
    };
72
    };
73
    if ($@) { warn "PROBLEM WITH RECORD"; next; }
73
    if ($@) { warn "PROBLEM WITH RECORD"; next; }
74
    my $marcflavour = C4::Context->preference('marcflavour');
74
    my $marcflavour = C4::Context->preference('marcflavour');
75
    my $av = getAuthorisedValues4MARCSubfields($frameworkcode);
76
    foreach my $tag ( keys %$av ) {
75
    foreach my $tag ( keys %$av ) {
77
        foreach my $field ( $record->field( $tag ) ) {
76
        foreach my $field ( $record->field( $tag ) ) {
78
            if ( $av->{ $tag } ) {
77
            if ( defined $av->{ $tag } ) {
79
                my @new_subfields = ();
78
                my @new_subfields = ();
79
                my $updated = 0;
80
                for my $subfield ( $field->subfields() ) {
80
                for my $subfield ( $field->subfields() ) {
81
                    my ( $letter, $value ) = @$subfield;
81
                    my ( $letter, $value ) = @$subfield;
82
                    # Replace the field value with the authorised value *except* for MARC21 field 942$n (suppression in opac)
82
                    if( defined $av->{ $tag }->{ $letter } ){
83
                    if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) {
83
                        my $category = $av->{$tag}->{$letter}->{category};
84
                        $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib, undef, $opac )
84
                        # Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac)
85
                            if $av->{ $tag }->{ $letter };
85
                        if( $category eq 'branches' ){
86
                            $value = defined $branches->{$value} ? $branches->{$value}: q{} ;
87
                            $updated = 1;
88
                        }
89
                        elsif( $category eq 'itemtypes' ){
90
                            $value = defined $itemtypes->{$value}->{translated_description} ? $itemtypes->{$value}->{translated_description} : q{};
91
                            $updated = 1;
92
                        }
93
                        elsif ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) {
94
                            my $desc_field = $opac ? "lib_opac" : "lib";
95
                            if ( defined $av->{$tag}->{$letter}->{$category}->{$value}->{$desc_field} ) {
96
                                $value = $av->{$tag}->{$letter}->{$category}->{$value}->{$desc_field} || $value;
97
                                $updated = 1;
98
                            }
99
                        }
86
                    }
100
                    }
87
                    push( @new_subfields, $letter, $value );
101
                    push( @new_subfields, $letter, $value );
88
                } 
102
                }
89
                $field ->replace_with( MARC::Field->new(
103
                $field ->replace_with( MARC::Field->new(
90
                    $tag,
104
                    $tag,
91
                    $field->indicator(1),
105
                    $field->indicator(1),
92
                    $field->indicator(2),
106
                    $field->indicator(2),
93
                    @new_subfields
107
                    @new_subfields
94
                ) );
108
                ) ) if $updated;
95
            }
109
            }
96
        }
110
        }
97
    }
111
    }
Lines 109-123 sub getAuthorisedValues4MARCSubfields { Link Here
109
    my ($frameworkcode) = @_;
123
    my ($frameworkcode) = @_;
110
    unless ( $authval_per_framework{ $frameworkcode } ) {
124
    unless ( $authval_per_framework{ $frameworkcode } ) {
111
        my $dbh = C4::Context->dbh;
125
        my $dbh = C4::Context->dbh;
112
        my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield
126
        my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield, authorised_value
113
                                 FROM marc_subfield_structure
127
                                 FROM marc_subfield_structure
114
                                 WHERE authorised_value IS NOT NULL
128
                                 WHERE authorised_value IS NOT NULL
115
                                   AND authorised_value!=''
129
                                   AND authorised_value!=''
116
                                   AND frameworkcode=?");
130
                                   AND frameworkcode=?");
117
        $sth->execute( $frameworkcode );
131
        $sth->execute( $frameworkcode );
118
        my $av = { };
132
        my $av = { };
119
        while ( my ( $tag, $letter ) = $sth->fetchrow() ) {
133
        while ( my ( $tag, $letter, $category ) = $sth->fetchrow() ) {
120
            $av->{ $tag }->{ $letter } = 1;
134
            my $authorised_values = { map { $_->{authorised_value} => $_ } @{ Koha::AuthorisedValues->search({ category => $category })->unblessed } };
135
            $av->{ $tag }->{ $letter }->{category} = $category;
136
            $av->{ $tag }->{ $letter }->{$category} = $authorised_values unless ( $category eq 'itemtypes' || $category eq 'branches' );
121
        }
137
        }
122
        $authval_per_framework{ $frameworkcode } = $av;
138
        $authval_per_framework{ $frameworkcode } = $av;
123
    }
139
    }
Lines 250-265 sub XSLTParse4Display { Link Here
250
    my $hidden_items = $params->{hidden_items} || [];
266
    my $hidden_items = $params->{hidden_items} || [];
251
    my $variables    = $params->{xslt_variables};
267
    my $variables    = $params->{xslt_variables};
252
    my $items_rs     = $params->{items_rs};
268
    my $items_rs     = $params->{items_rs};
269
    my $branches     = $params->{branches};
270
    my $itemtypes    = $params->{itemtypes};
271
272
    $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }) } unless $branches;
273
    $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } } unless $itemtypes;
253
274
254
    my $xslfilename = get_xsl_filename( $xslsyspref);
275
    my $xslfilename = get_xsl_filename( $xslsyspref);
255
276
256
    # grab the XML, run it through our stylesheet, push it out to the browser
277
    # grab the XML, run it through our stylesheet, push it out to the browser
257
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
278
    my $authorised_values = getAuthorisedValues4MARCSubfields("");
279
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record, undef, $branches, $itemtypes, $authorised_values );
258
    my $itemsxml;
280
    my $itemsxml;
259
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) {
281
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) {
260
        $itemsxml = ""; #We don't use XSLT for items display on these pages
282
        $itemsxml = ""; #We don't use XSLT for items display on these pages
261
    } else {
283
    } else {
262
        $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs);
284
        $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes);
263
    }
285
    }
264
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
286
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
265
287
Lines 319-325 Is only used in this module currently. Link Here
319
=cut
341
=cut
320
342
321
sub buildKohaItemsNamespace {
343
sub buildKohaItemsNamespace {
322
    my ($biblionumber, $hidden_items, $items_rs) = @_;
344
    my ($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes) = @_;
323
345
324
    $hidden_items ||= [];
346
    $hidden_items ||= [];
325
347
Lines 339-347 sub buildKohaItemsNamespace { Link Here
339
    my $ccodes =
361
    my $ccodes =
340
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
362
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
341
363
342
    my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
343
344
    my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
345
    my $xml = '';
364
    my $xml = '';
346
    my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } );
365
    my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } );
347
    my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2';
366
    my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2';
Lines 396-403 sub buildKohaItemsNamespace { Link Here
396
        else {
415
        else {
397
            $status = "available";
416
            $status = "available";
398
        }
417
        }
399
        my $homebranch     = C4::Koha::xml_escape($branches{$item->homebranch});
418
        my $homebranch     = C4::Koha::xml_escape($branches->{$item->homebranch});
400
        my $holdingbranch  = C4::Koha::xml_escape($branches{$item->holdingbranch});
419
        my $holdingbranch  = C4::Koha::xml_escape($branches->{$item->holdingbranch});
401
        my $resultbranch   = C4::Context->preference('OPACResultsLibrary') eq 'homebranch' ? $homebranch : $holdingbranch;
420
        my $resultbranch   = C4::Context->preference('OPACResultsLibrary') eq 'homebranch' ? $homebranch : $holdingbranch;
402
        my $location       = C4::Koha::xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location);
421
        my $location       = C4::Koha::xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location);
403
        my $ccode          = C4::Koha::xml_escape($item->ccode    && exists $ccodes->{$item->ccode}            ? $ccodes->{$item->ccode}            : $item->ccode);
422
        my $ccode          = C4::Koha::xml_escape($item->ccode    && exists $ccodes->{$item->ccode}            ? $ccodes->{$item->ccode}            : $item->ccode);
404
- 

Return to bug 28371