Lines 158-163
sub _get_best_default_xslt_filename {
Link Here
|
158 |
|
158 |
|
159 |
sub XSLTParse4Display { |
159 |
sub XSLTParse4Display { |
160 |
my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; |
160 |
my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; |
|
|
161 |
|
162 |
my $shouldIPullInComponentPartRecords; #We don't want to pull component part records if they are not needed! Show component part records only for detailed views. |
163 |
|
161 |
my $xslfilename = C4::Context->preference($xslsyspref); |
164 |
my $xslfilename = C4::Context->preference($xslsyspref); |
162 |
if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { |
165 |
if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { |
163 |
my $htdocs; |
166 |
my $htdocs; |
Lines 169-174
sub XSLTParse4Display {
Link Here
|
169 |
$theme = C4::Context->preference("template"); |
172 |
$theme = C4::Context->preference("template"); |
170 |
$xslfile = C4::Context->preference('marcflavour') . |
173 |
$xslfile = C4::Context->preference('marcflavour') . |
171 |
"slim2intranetDetail.xsl"; |
174 |
"slim2intranetDetail.xsl"; |
|
|
175 |
$shouldIPullInComponentPartRecords = 1; |
172 |
} elsif ($xslsyspref eq "XSLTResultsDisplay") { |
176 |
} elsif ($xslsyspref eq "XSLTResultsDisplay") { |
173 |
$htdocs = C4::Context->config('intrahtdocs'); |
177 |
$htdocs = C4::Context->config('intrahtdocs'); |
174 |
$theme = C4::Context->preference("template"); |
178 |
$theme = C4::Context->preference("template"); |
Lines 179-184
sub XSLTParse4Display {
Link Here
|
179 |
$theme = C4::Context->preference("opacthemes"); |
183 |
$theme = C4::Context->preference("opacthemes"); |
180 |
$xslfile = C4::Context->preference('marcflavour') . |
184 |
$xslfile = C4::Context->preference('marcflavour') . |
181 |
"slim2OPACDetail.xsl"; |
185 |
"slim2OPACDetail.xsl"; |
|
|
186 |
$shouldIPullInComponentPartRecords = 1; |
182 |
} elsif ($xslsyspref eq "OPACXSLTResultsDisplay") { |
187 |
} elsif ($xslsyspref eq "OPACXSLTResultsDisplay") { |
183 |
$htdocs = C4::Context->config('opachtdocs'); |
188 |
$htdocs = C4::Context->config('opachtdocs'); |
184 |
$theme = C4::Context->preference("opacthemes"); |
189 |
$theme = C4::Context->preference("opacthemes"); |
Lines 193-200
sub XSLTParse4Display {
Link Here
|
193 |
$xslfilename =~ s/\{langcode\}/$lang/; |
198 |
$xslfilename =~ s/\{langcode\}/$lang/; |
194 |
} |
199 |
} |
195 |
|
200 |
|
|
|
201 |
|
196 |
# grab the XML, run it through our stylesheet, push it out to the browser |
202 |
# grab the XML, run it through our stylesheet, push it out to the browser |
197 |
my $record = transformMARCXML4XSLT($biblionumber, $orig_record); |
203 |
my $record = transformMARCXML4XSLT($biblionumber, $orig_record); |
|
|
204 |
my $f001Data = $record->field('001'); |
205 |
$f001Data = $f001Data->data() if defined $f001Data; #Not all records have the field 001?? |
206 |
|
207 |
my $componentPartRecordsXML = ''; |
208 |
$componentPartRecordsXML = _prepareComponentPartRecords($f001Data) if $shouldIPullInComponentPartRecords && |
209 |
C4::Context->preference('AddComponentPartRecordsToDetailedViews');; |
210 |
|
198 |
#return $record->as_formatted(); |
211 |
#return $record->as_formatted(); |
199 |
my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); |
212 |
my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); |
200 |
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); |
213 |
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); |
Lines 214-220
sub XSLTParse4Display {
Link Here
|
214 |
$sysxml .= "<syspref name=\"$syspref\">$sp</syspref>\n"; |
227 |
$sysxml .= "<syspref name=\"$syspref\">$sp</syspref>\n"; |
215 |
} |
228 |
} |
216 |
$sysxml .= "</sysprefs>\n"; |
229 |
$sysxml .= "</sysprefs>\n"; |
217 |
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; |
230 |
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$componentPartRecordsXML\<\/record\>/; |
218 |
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs |
231 |
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs |
219 |
$xmlrecord =~ s/\&amp;/\&/g; |
232 |
$xmlrecord =~ s/\&amp;/\&/g; |
220 |
} |
233 |
} |
Lines 313-318
sub buildKohaItemsNamespace {
Link Here
|
313 |
return $xml; |
326 |
return $xml; |
314 |
} |
327 |
} |
315 |
|
328 |
|
|
|
329 |
=head |
330 |
|
331 |
Makes a C4::Search::SimpleSearch() to find all records from the index rcn=Record-control-number matching the given |
332 |
field 001 value. |
333 |
Strips some key identifiers from those records. |
334 |
Builds a XML presentation out of those, ready for the XSLT processing. |
335 |
|
336 |
$componentPartRecordsXML = &_prepareComponentPartRecords($field001Data); |
337 |
|
338 |
In Koha the field 001 is not the same as the biblionumber! |
339 |
|
340 |
Returns: a string containing an XML representation of component part records |
341 |
In XSL: componentPartRecords/componentPart/title |
342 |
in addition to title, elements can also be subtitle, biblionumber, author, publishercode, publicationyear |
343 |
eg. componentPartRecords/componentPart/biblionumber |
344 |
|
345 |
=cut |
346 |
sub _prepareComponentPartRecords { |
347 |
|
348 |
my $field001Data = shift; |
349 |
my $componentPartRecordsXML; |
350 |
my ($error, $componentPartRecordISOs, $resultSetSize) = C4::Search::SimpleSearch("rcn=$field001Data"); |
351 |
|
352 |
if ($resultSetSize && !$error) { |
353 |
|
354 |
#Collect the XML elements to a array instead of continuously concatenating a string. |
355 |
# There might be dozens of component part records and in such a case string concatenation is extremely slow. |
356 |
my @componentPartRecordXML = ('<componentPartRecords>'); #@@componentPartRecordXML vs $componentPartRecordsXML is a nice Perl curiosity! |
357 |
for my $cr ( @{$componentPartRecordISOs} ) { |
358 |
push @componentPartRecordXML, ' <componentPart>'; |
359 |
my $marcrecord = MARC::File::USMARC::decode($cr); |
360 |
my $componentPartBiblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,q{}); |
361 |
|
362 |
push @componentPartRecordXML, " <title>$componentPartBiblio->{'title'}</title>" if $componentPartBiblio->{'title'}; |
363 |
push @componentPartRecordXML, " <subtitle>$componentPartBiblio->{'subtitle'}</subtitle>" if $componentPartBiblio->{'subtitle'}; |
364 |
push @componentPartRecordXML, " <biblionumber>$componentPartBiblio->{'biblionumber'}</biblionumber>" if $componentPartBiblio->{'biblionumber'}; |
365 |
push @componentPartRecordXML, " <author>$componentPartBiblio->{'author'}</author>" if $componentPartBiblio->{'author'}; |
366 |
push @componentPartRecordXML, " <publishercode>$componentPartBiblio->{'publishercode'}</publishercode>" if $componentPartBiblio->{'publishercode'}; |
367 |
push @componentPartRecordXML, " <publicationyear>$componentPartBiblio->{'publicationyear'}</publicationyear>" if $componentPartBiblio->{'publicationyear'}; |
368 |
|
369 |
push @componentPartRecordXML, ' </componentPart>'; |
370 |
} |
371 |
push @componentPartRecordXML, '</componentPartRecords>'; |
372 |
push @componentPartRecordXML, ''; #Just to make the join operation end with a newline |
373 |
|
374 |
#Build the real XML string. |
375 |
$componentPartRecordsXML = join "\n", @componentPartRecordXML; |
376 |
|
377 |
return $componentPartRecordsXML; |
378 |
} |
379 |
return ''; #Instantiate this string so we don't get undefined errors when concatenating with this. |
380 |
} |
316 |
|
381 |
|
317 |
|
382 |
|
318 |
1; |
383 |
1; |