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

(-)a/C4/Search.pm (-1 / +3 lines)
Lines 1970-1976 sub searchResults { Link Here
1970
                    ),
1970
                    ),
1971
                    fix_amps       => 1,
1971
                    fix_amps       => 1,
1972
                    hidden_items   => \@hiddenitems,
1972
                    hidden_items   => \@hiddenitems,
1973
                    xslt_variables => $xslt_variables
1973
                    xslt_variables => $xslt_variables,
1974
                    branches => \%branches,
1975
                    itemtypes => \%itemtypes
1974
                }
1976
                }
1975
            );
1977
            );
1976
        }
1978
        }
(-)a/C4/XSLT.pm (-21 / +38 lines)
Lines 65-71 Is only used in this module currently. Link Here
65
=cut
65
=cut
66
66
67
sub transformMARCXML4XSLT {
67
sub transformMARCXML4XSLT {
68
    my ($biblionumber, $record) = @_;
68
    my ($biblionumber, $record, $branches, $itemtypes, $av) = @_;
69
    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
69
    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
70
    my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 });
70
    my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 });
71
    my @fields;
71
    my @fields;
Lines 75-100 sub transformMARCXML4XSLT { Link Here
75
    };
75
    };
76
    if ($@) { warn "PROBLEM WITH RECORD"; next; }
76
    if ($@) { warn "PROBLEM WITH RECORD"; next; }
77
    my $marcflavour = C4::Context->preference('marcflavour');
77
    my $marcflavour = C4::Context->preference('marcflavour');
78
    my $av = getAuthorisedValues4MARCSubfields($frameworkcode);
79
    foreach my $tag ( keys %$av ) {
78
    foreach my $tag ( keys %$av ) {
80
        foreach my $field ( $record->field( $tag ) ) {
79
        foreach my $field ( $record->field( $tag ) ) {
81
            if ( $av->{ $tag } ) {
80
            if ( defined $av->{ $tag } ) {
82
                my @new_subfields = ();
81
                my @new_subfields = ();
82
                my $updated = 0;
83
                for my $subfield ( $field->subfields() ) {
83
                for my $subfield ( $field->subfields() ) {
84
                    my ( $letter, $value ) = @$subfield;
84
                    my ( $letter, $value ) = @$subfield;
85
                    # Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac)
85
                    if( defined $av->{ $tag }->{ $letter } ){
86
                    if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) {
86
                        my $category = $av->{$tag}->{$letter}->{category};
87
                        $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib )
87
                        # Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac)
88
                            if $av->{ $tag }->{ $letter };
88
                        if( $category eq 'branches' ){
89
                            $value = defined $branches->{$value} ? $branches->{$value}: q{} ;
90
                            $updated = 1;
91
                        }
92
                        elsif( $category eq 'itemtypes' ){
93
                            $value = defined $itemtypes->{$value}->{translated_description} ? $itemtypes->{$value}->{translated_description} : q{};
94
                            $updated = 1;
95
                        }
96
                        elsif ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) {
97
                            if ( defined $av->{$tag}->{$letter}->{$category}->{$value}->{lib} ) {
98
                                $value = $av->{$tag}->{$letter}->{$category}->{$value}->{lib} || $value;
99
                                $updated = 1;
100
                            }
101
                        }
89
                    }
102
                    }
90
                    push( @new_subfields, $letter, $value );
103
                    push( @new_subfields, $letter, $value );
91
                } 
104
                }
92
                $field ->replace_with( MARC::Field->new(
105
                $field ->replace_with( MARC::Field->new(
93
                    $tag,
106
                    $tag,
94
                    $field->indicator(1),
107
                    $field->indicator(1),
95
                    $field->indicator(2),
108
                    $field->indicator(2),
96
                    @new_subfields
109
                    @new_subfields
97
                ) );
110
                ) ) if $updated;
98
            }
111
            }
99
        }
112
        }
100
    }
113
    }
Lines 112-126 sub getAuthorisedValues4MARCSubfields { Link Here
112
    my ($frameworkcode) = @_;
125
    my ($frameworkcode) = @_;
113
    unless ( $authval_per_framework{ $frameworkcode } ) {
126
    unless ( $authval_per_framework{ $frameworkcode } ) {
114
        my $dbh = C4::Context->dbh;
127
        my $dbh = C4::Context->dbh;
115
        my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield
128
        my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield, authorised_value
116
                                 FROM marc_subfield_structure
129
                                 FROM marc_subfield_structure
117
                                 WHERE authorised_value IS NOT NULL
130
                                 WHERE authorised_value IS NOT NULL
118
                                   AND authorised_value!=''
131
                                   AND authorised_value!=''
119
                                   AND frameworkcode=?");
132
                                   AND frameworkcode=?");
120
        $sth->execute( $frameworkcode );
133
        $sth->execute( $frameworkcode );
121
        my $av = { };
134
        my $av = { };
122
        while ( my ( $tag, $letter ) = $sth->fetchrow() ) {
135
        while ( my ( $tag, $letter, $category ) = $sth->fetchrow() ) {
123
            $av->{ $tag }->{ $letter } = 1;
136
            my $authorised_values = { map { $_->{authorised_value} => $_ } @{ Koha::AuthorisedValues->search({ category => $category })->unblessed } };
137
            $av->{ $tag }->{ $letter }->{category} = $category;
138
            $av->{ $tag }->{ $letter }->{$category} = $authorised_values unless ( $category eq 'itemtypes' || $category eq 'branches' );
124
        }
139
        }
125
        $authval_per_framework{ $frameworkcode } = $av;
140
        $authval_per_framework{ $frameworkcode } = $av;
126
    }
141
    }
Lines 252-267 sub XSLTParse4Display { Link Here
252
    my $hidden_items = $params->{hidden_items} || [];
267
    my $hidden_items = $params->{hidden_items} || [];
253
    my $variables    = $params->{xslt_variables};
268
    my $variables    = $params->{xslt_variables};
254
    my $items_rs     = $params->{items_rs};
269
    my $items_rs     = $params->{items_rs};
270
    my $branches     = $params->{branches};
271
    my $itemtypes    = $params->{itemtypes};
272
273
    $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }) } unless $branches;
274
    $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } } unless $itemtypes;
255
275
256
    my $xslfilename = get_xsl_filename( $xslsyspref);
276
    my $xslfilename = get_xsl_filename( $xslsyspref);
257
277
258
    # grab the XML, run it through our stylesheet, push it out to the browser
278
    # grab the XML, run it through our stylesheet, push it out to the browser
259
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
279
    my $authorised_values = getAuthorisedValues4MARCSubfields("");
280
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record, $branches, $itemtypes, $authorised_values );
260
    my $itemsxml;
281
    my $itemsxml;
261
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) {
282
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) {
262
        $itemsxml = ""; #We don't use XSLT for items display on these pages
283
        $itemsxml = ""; #We don't use XSLT for items display on these pages
263
    } else {
284
    } else {
264
        $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs);
285
        $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes);
265
    }
286
    }
266
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
287
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
267
288
Lines 319-325 Is only used in this module currently. Link Here
319
=cut
340
=cut
320
341
321
sub buildKohaItemsNamespace {
342
sub buildKohaItemsNamespace {
322
    my ($biblionumber, $hidden_items, $items_rs) = @_;
343
    my ($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes) = @_;
323
344
324
    $hidden_items ||= [];
345
    $hidden_items ||= [];
325
346
Lines 339-347 sub buildKohaItemsNamespace { Link Here
339
    my $ccodes =
360
    my $ccodes =
340
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
361
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
341
362
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 = '';
363
    my $xml = '';
346
    my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } );
364
    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';
365
    my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2';
Lines 389-396 sub buildKohaItemsNamespace { Link Here
389
        else {
407
        else {
390
            $status = "available";
408
            $status = "available";
391
        }
409
        }
392
        my $homebranch     = xml_escape($branches{$item->homebranch});
410
        my $homebranch     = xml_escape($branches->{$item->homebranch});
393
        my $holdingbranch  = xml_escape($branches{$item->holdingbranch});
411
        my $holdingbranch  = xml_escape($branches->{$item->holdingbranch});
394
        my $location       = xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location);
412
        my $location       = xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location);
395
        my $ccode          = xml_escape($item->ccode    && exists $ccodes->{$item->ccode}            ? $ccodes->{$item->ccode}            : $item->ccode);
413
        my $ccode          = xml_escape($item->ccode    && exists $ccodes->{$item->ccode}            ? $ccodes->{$item->ccode}            : $item->ccode);
396
        my $itemcallnumber = xml_escape($item->itemcallnumber);
414
        my $itemcallnumber = xml_escape($item->itemcallnumber);
397
- 

Return to bug 28371