Lines 28-49
use C4::Koha qw( xml_escape );
Link Here
|
28 |
use C4::Biblio qw( GetAuthorisedValueDesc GetFrameworkCode GetMarcStructure ); |
28 |
use C4::Biblio qw( GetAuthorisedValueDesc GetFrameworkCode GetMarcStructure ); |
29 |
use Koha::AuthorisedValues; |
29 |
use Koha::AuthorisedValues; |
30 |
use Koha::ItemTypes; |
30 |
use Koha::ItemTypes; |
|
|
31 |
use Koha::RecordProcessor; |
31 |
use Koha::XSLT::Base; |
32 |
use Koha::XSLT::Base; |
32 |
use Koha::Libraries; |
33 |
use Koha::Libraries; |
33 |
use Koha::Recalls; |
34 |
use Koha::Recalls; |
34 |
|
35 |
|
35 |
my $engine; #XSLT Handler object |
36 |
my $engine; #XSLT Handler object |
36 |
my %authval_per_framework; |
|
|
37 |
# Cache for tagfield-tagsubfield to decode per framework. |
38 |
# Should be preferably be placed in Koha-core... |
39 |
|
37 |
|
40 |
our (@ISA, @EXPORT_OK); |
38 |
our (@ISA, @EXPORT_OK); |
41 |
BEGIN { |
39 |
BEGIN { |
42 |
require Exporter; |
40 |
require Exporter; |
43 |
@ISA = qw(Exporter); |
41 |
@ISA = qw(Exporter); |
44 |
@EXPORT_OK = qw( |
42 |
@EXPORT_OK = qw( |
45 |
transformMARCXML4XSLT |
|
|
46 |
getAuthorisedValues4MARCSubfields |
47 |
buildKohaItemsNamespace |
43 |
buildKohaItemsNamespace |
48 |
XSLTParse4Display |
44 |
XSLTParse4Display |
49 |
); |
45 |
); |
Lines 56-130
C4::XSLT - Functions for displaying XSLT-generated content
Link Here
|
56 |
|
52 |
|
57 |
=head1 FUNCTIONS |
53 |
=head1 FUNCTIONS |
58 |
|
54 |
|
59 |
=head2 transformMARCXML4XSLT |
|
|
60 |
|
61 |
Replaces codes with authorized values in a MARC::Record object |
62 |
|
63 |
=cut |
64 |
|
65 |
sub transformMARCXML4XSLT { |
66 |
my ($biblionumber, $record, $opac) = @_; |
67 |
my $frameworkcode = GetFrameworkCode($biblionumber) || ''; |
68 |
my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); |
69 |
my @fields; |
70 |
# FIXME: wish there was a better way to handle exceptions |
71 |
eval { |
72 |
@fields = $record->fields(); |
73 |
}; |
74 |
if ($@) { warn "PROBLEM WITH RECORD"; next; } |
75 |
my $marcflavour = C4::Context->preference('marcflavour'); |
76 |
my $av = getAuthorisedValues4MARCSubfields($frameworkcode); |
77 |
foreach my $tag ( keys %$av ) { |
78 |
foreach my $field ( $record->field( $tag ) ) { |
79 |
if ( $av->{ $tag } ) { |
80 |
my @new_subfields = (); |
81 |
for my $subfield ( $field->subfields() ) { |
82 |
my ( $letter, $value ) = @$subfield; |
83 |
# Replace the field value with the authorised value *except* for MARC21 field 942$n (suppression in opac) |
84 |
if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { |
85 |
$value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib, undef, $opac ) |
86 |
if $av->{ $tag }->{ $letter }; |
87 |
} |
88 |
push( @new_subfields, $letter, $value ); |
89 |
} |
90 |
$field ->replace_with( MARC::Field->new( |
91 |
$tag, |
92 |
$field->indicator(1), |
93 |
$field->indicator(2), |
94 |
@new_subfields |
95 |
) ); |
96 |
} |
97 |
} |
98 |
} |
99 |
return $record; |
100 |
} |
101 |
|
102 |
=head2 getAuthorisedValues4MARCSubfields |
103 |
|
104 |
Returns a ref of hash of ref of hash for tag -> letter controlled by authorised values |
105 |
Is only used in this module currently. |
106 |
|
107 |
=cut |
108 |
|
109 |
sub getAuthorisedValues4MARCSubfields { |
110 |
my ($frameworkcode) = @_; |
111 |
unless ( $authval_per_framework{ $frameworkcode } ) { |
112 |
my $dbh = C4::Context->dbh; |
113 |
my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield |
114 |
FROM marc_subfield_structure |
115 |
WHERE authorised_value IS NOT NULL |
116 |
AND authorised_value!='' |
117 |
AND frameworkcode=?"); |
118 |
$sth->execute( $frameworkcode ); |
119 |
my $av = { }; |
120 |
while ( my ( $tag, $letter ) = $sth->fetchrow() ) { |
121 |
$av->{ $tag }->{ $letter } = 1; |
122 |
} |
123 |
$authval_per_framework{ $frameworkcode } = $av; |
124 |
} |
125 |
return $authval_per_framework{ $frameworkcode }; |
126 |
} |
127 |
|
128 |
=head2 XSLTParse4Display |
55 |
=head2 XSLTParse4Display |
129 |
|
56 |
|
130 |
Returns xml for biblionumber and requested XSLT transformation. |
57 |
Returns xml for biblionumber and requested XSLT transformation. |
Lines 245-252
sub XSLTParse4Display {
Link Here
|
245 |
my ( $params ) = @_; |
172 |
my ( $params ) = @_; |
246 |
|
173 |
|
247 |
my $biblionumber = $params->{biblionumber}; |
174 |
my $biblionumber = $params->{biblionumber}; |
248 |
my $orig_record = $params->{record}; |
175 |
my $record = $params->{record}; |
249 |
my $xslsyspref = $params->{xsl_syspref}; |
176 |
my $xslsyspref = $params->{xsl_syspref}; |
|
|
177 |
my $interface = ( $xslsyspref =~ /OPAC/ ) ? 'opac' : 'intranet' ; |
250 |
my $fixamps = $params->{fix_amps}; |
178 |
my $fixamps = $params->{fix_amps}; |
251 |
my $hidden_items = $params->{hidden_items} || []; |
179 |
my $hidden_items = $params->{hidden_items} || []; |
252 |
my $variables = $params->{xslt_variables}; |
180 |
my $variables = $params->{xslt_variables}; |
Lines 257-264
sub XSLTParse4Display {
Link Here
|
257 |
|
185 |
|
258 |
my $xslfilename = get_xsl_filename( $xslsyspref); |
186 |
my $xslfilename = get_xsl_filename( $xslsyspref); |
259 |
|
187 |
|
|
|
188 |
my $frameworkcode = GetFrameworkCode($biblionumber) || ''; |
189 |
my $record_processor = Koha::RecordProcessor->new( |
190 |
{ |
191 |
filters => [ 'ExpandCodedFields' ], |
192 |
options => { |
193 |
interface => $interface, |
194 |
frameworkcode => $frameworkcode |
195 |
} |
196 |
} |
197 |
); |
198 |
$record_processor->process($record); |
199 |
|
260 |
# grab the XML, run it through our stylesheet, push it out to the browser |
200 |
# grab the XML, run it through our stylesheet, push it out to the browser |
261 |
my $record = transformMARCXML4XSLT($biblionumber, $orig_record); |
|
|
262 |
my $itemsxml; |
201 |
my $itemsxml; |
263 |
if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) { |
202 |
if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) { |
264 |
$itemsxml = ""; #We don't use XSLT for items display on these pages |
203 |
$itemsxml = ""; #We don't use XSLT for items display on these pages |