Lines 63-69
Replaces codes with authorized values in a MARC::Record object
Link Here
|
63 |
=cut |
63 |
=cut |
64 |
|
64 |
|
65 |
sub transformMARCXML4XSLT { |
65 |
sub transformMARCXML4XSLT { |
66 |
my ($biblionumber, $record, $opac) = @_; |
66 |
my ($biblionumber, $record, $opac, $branches, $itemtypes, $av) = @_; |
67 |
my $frameworkcode = GetFrameworkCode($biblionumber) || ''; |
67 |
my $frameworkcode = GetFrameworkCode($biblionumber) || ''; |
68 |
my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); |
68 |
my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); |
69 |
my @fields; |
69 |
my @fields; |
Lines 73-98
sub transformMARCXML4XSLT {
Link Here
|
73 |
}; |
73 |
}; |
74 |
if ($@) { warn "PROBLEM WITH RECORD"; next; } |
74 |
if ($@) { warn "PROBLEM WITH RECORD"; next; } |
75 |
my $marcflavour = C4::Context->preference('marcflavour'); |
75 |
my $marcflavour = C4::Context->preference('marcflavour'); |
76 |
my $av = getAuthorisedValues4MARCSubfields($frameworkcode); |
|
|
77 |
foreach my $tag ( keys %$av ) { |
76 |
foreach my $tag ( keys %$av ) { |
78 |
foreach my $field ( $record->field( $tag ) ) { |
77 |
foreach my $field ( $record->field( $tag ) ) { |
79 |
if ( $av->{ $tag } ) { |
78 |
if ( defined $av->{ $tag } ) { |
80 |
my @new_subfields = (); |
79 |
my @new_subfields = (); |
|
|
80 |
my $updated = 0; |
81 |
for my $subfield ( $field->subfields() ) { |
81 |
for my $subfield ( $field->subfields() ) { |
82 |
my ( $letter, $value ) = @$subfield; |
82 |
my ( $letter, $value ) = @$subfield; |
83 |
# Replace the field value with the authorised value *except* for MARC21 field 942$n (suppression in opac) |
83 |
if( defined $av->{ $tag }->{ $letter } ){ |
84 |
if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { |
84 |
my $category = $av->{$tag}->{$letter}->{category}; |
85 |
$value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib, undef, $opac ) |
85 |
# Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac) |
86 |
if $av->{ $tag }->{ $letter }; |
86 |
if( $category eq 'branches' ){ |
|
|
87 |
$value = defined $branches->{$value} ? $branches->{$value}: q{} ; |
88 |
$updated = 1; |
89 |
} |
90 |
elsif( $category eq 'itemtypes' ){ |
91 |
$value = defined $itemtypes->{$value}->{translated_description} ? $itemtypes->{$value}->{translated_description} : q{}; |
92 |
$updated = 1; |
93 |
} |
94 |
elsif ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { |
95 |
my $desc_field = $opac ? "lib_opac" : "lib"; |
96 |
if ( defined $av->{$tag}->{$letter}->{$category}->{$value}->{$desc_field} ) { |
97 |
$value = $av->{$tag}->{$letter}->{$category}->{$value}->{$desc_field} || $value; |
98 |
$updated = 1; |
99 |
} |
100 |
} |
87 |
} |
101 |
} |
88 |
push( @new_subfields, $letter, $value ); |
102 |
push( @new_subfields, $letter, $value ); |
89 |
} |
103 |
} |
90 |
$field ->replace_with( MARC::Field->new( |
104 |
$field ->replace_with( MARC::Field->new( |
91 |
$tag, |
105 |
$tag, |
92 |
$field->indicator(1), |
106 |
$field->indicator(1), |
93 |
$field->indicator(2), |
107 |
$field->indicator(2), |
94 |
@new_subfields |
108 |
@new_subfields |
95 |
) ); |
109 |
) ) if $updated; |
96 |
} |
110 |
} |
97 |
} |
111 |
} |
98 |
} |
112 |
} |
Lines 110-124
sub getAuthorisedValues4MARCSubfields {
Link Here
|
110 |
my ($frameworkcode) = @_; |
124 |
my ($frameworkcode) = @_; |
111 |
unless ( $authval_per_framework{ $frameworkcode } ) { |
125 |
unless ( $authval_per_framework{ $frameworkcode } ) { |
112 |
my $dbh = C4::Context->dbh; |
126 |
my $dbh = C4::Context->dbh; |
113 |
my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield |
127 |
my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield, authorised_value |
114 |
FROM marc_subfield_structure |
128 |
FROM marc_subfield_structure |
115 |
WHERE authorised_value IS NOT NULL |
129 |
WHERE authorised_value IS NOT NULL |
116 |
AND authorised_value!='' |
130 |
AND authorised_value!='' |
117 |
AND frameworkcode=?"); |
131 |
AND frameworkcode=?"); |
118 |
$sth->execute( $frameworkcode ); |
132 |
$sth->execute( $frameworkcode ); |
119 |
my $av = { }; |
133 |
my $av = { }; |
120 |
while ( my ( $tag, $letter ) = $sth->fetchrow() ) { |
134 |
while ( my ( $tag, $letter, $category ) = $sth->fetchrow() ) { |
121 |
$av->{ $tag }->{ $letter } = 1; |
135 |
my $authorised_values = { map { $_->{authorised_value} => $_ } @{ Koha::AuthorisedValues->search({ category => $category })->unblessed } }; |
|
|
136 |
$av->{ $tag }->{ $letter }->{category} = $category; |
137 |
$av->{ $tag }->{ $letter }->{$category} = $authorised_values unless ( $category eq 'itemtypes' || $category eq 'branches' ); |
122 |
} |
138 |
} |
123 |
$authval_per_framework{ $frameworkcode } = $av; |
139 |
$authval_per_framework{ $frameworkcode } = $av; |
124 |
} |
140 |
} |
Lines 251-256
sub XSLTParse4Display {
Link Here
|
251 |
my $hidden_items = $params->{hidden_items} || []; |
267 |
my $hidden_items = $params->{hidden_items} || []; |
252 |
my $variables = $params->{xslt_variables}; |
268 |
my $variables = $params->{xslt_variables}; |
253 |
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' })->as_list } unless $branches; |
274 |
$itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } } unless $itemtypes; |
254 |
|
275 |
|
255 |
die "Mandatory \$params->{xsl_syspref} was not provided, called with biblionumber $params->{biblionumber}" |
276 |
die "Mandatory \$params->{xsl_syspref} was not provided, called with biblionumber $params->{biblionumber}" |
256 |
if not defined $params->{xsl_syspref}; |
277 |
if not defined $params->{xsl_syspref}; |
Lines 258-269
sub XSLTParse4Display {
Link Here
|
258 |
my $xslfilename = get_xsl_filename( $xslsyspref); |
279 |
my $xslfilename = get_xsl_filename( $xslsyspref); |
259 |
|
280 |
|
260 |
# grab the XML, run it through our stylesheet, push it out to the browser |
281 |
# grab the XML, run it through our stylesheet, push it out to the browser |
261 |
my $record = transformMARCXML4XSLT($biblionumber, $orig_record); |
282 |
my $authorised_values = getAuthorisedValues4MARCSubfields(""); |
|
|
283 |
my $record = transformMARCXML4XSLT($biblionumber, $orig_record, undef, $branches, $itemtypes, $authorised_values ); |
262 |
my $itemsxml; |
284 |
my $itemsxml; |
263 |
if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) { |
285 |
if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) { |
264 |
$itemsxml = ""; #We don't use XSLT for items display on these pages |
286 |
$itemsxml = ""; #We don't use XSLT for items display on these pages |
265 |
} else { |
287 |
} else { |
266 |
$itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs); |
288 |
$itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes); |
267 |
} |
289 |
} |
268 |
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); |
290 |
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); |
269 |
|
291 |
|
Lines 324-330
Is only used in this module currently.
Link Here
|
324 |
=cut |
346 |
=cut |
325 |
|
347 |
|
326 |
sub buildKohaItemsNamespace { |
348 |
sub buildKohaItemsNamespace { |
327 |
my ($biblionumber, $hidden_items, $items_rs) = @_; |
349 |
my ($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes) = @_; |
328 |
|
350 |
|
329 |
$hidden_items ||= []; |
351 |
$hidden_items ||= []; |
330 |
|
352 |
|
Lines 344-352
sub buildKohaItemsNamespace {
Link Here
|
344 |
my $ccodes = |
366 |
my $ccodes = |
345 |
{ map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) }; |
367 |
{ map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) }; |
346 |
|
368 |
|
347 |
my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' })->as_list; |
|
|
348 |
|
349 |
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; |
350 |
my $xml = ''; |
369 |
my $xml = ''; |
351 |
my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ); |
370 |
my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ); |
352 |
my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2'; |
371 |
my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2'; |
Lines 411-418
sub buildKohaItemsNamespace {
Link Here
|
411 |
else { |
430 |
else { |
412 |
$status = "available"; |
431 |
$status = "available"; |
413 |
} |
432 |
} |
414 |
my $homebranch = C4::Koha::xml_escape($branches{$item->homebranch}); |
433 |
my $homebranch = C4::Koha::xml_escape($branches->{$item->homebranch}); |
415 |
my $holdingbranch = C4::Koha::xml_escape($branches{$item->holdingbranch}); |
434 |
my $holdingbranch = C4::Koha::xml_escape($branches->{$item->holdingbranch}); |
416 |
my $resultbranch = C4::Context->preference('OPACResultsLibrary') eq 'homebranch' ? $homebranch : $holdingbranch; |
435 |
my $resultbranch = C4::Context->preference('OPACResultsLibrary') eq 'homebranch' ? $homebranch : $holdingbranch; |
417 |
my $location = C4::Koha::xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location); |
436 |
my $location = C4::Koha::xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location); |
418 |
my $ccode = C4::Koha::xml_escape($item->ccode && exists $ccodes->{$item->ccode} ? $ccodes->{$item->ccode} : $item->ccode); |
437 |
my $ccode = C4::Koha::xml_escape($item->ccode && exists $ccodes->{$item->ccode} ? $ccodes->{$item->ccode} : $item->ccode); |
419 |
- |
|
|