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 $shouldIPullChildRecords; #We don't want to pull child records if they are not needed! Show child 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 |
$shouldIPullChildRecords = 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 |
$shouldIPullChildRecords = 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 192-200
sub XSLTParse4Display {
Link Here
|
192 |
my $lang = C4::Templates::_current_language(); |
197 |
my $lang = C4::Templates::_current_language(); |
193 |
$xslfilename =~ s/\{langcode\}/$lang/; |
198 |
$xslfilename =~ s/\{langcode\}/$lang/; |
194 |
} |
199 |
} |
|
|
200 |
|
195 |
|
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 $childRecordsXML = _prepareChildRecords($f001Data) if $shouldIPullChildRecords && |
208 |
C4::Context->preference('AddChildRecordsToDetailedViews');; |
209 |
|
198 |
#return $record->as_formatted(); |
210 |
#return $record->as_formatted(); |
199 |
my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); |
211 |
my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); |
200 |
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); |
212 |
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); |
Lines 214-220
sub XSLTParse4Display {
Link Here
|
214 |
$sysxml .= "<syspref name=\"$syspref\">$sp</syspref>\n"; |
226 |
$sysxml .= "<syspref name=\"$syspref\">$sp</syspref>\n"; |
215 |
} |
227 |
} |
216 |
$sysxml .= "</sysprefs>\n"; |
228 |
$sysxml .= "</sysprefs>\n"; |
217 |
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; |
229 |
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$childRecordsXML\<\/record\>/; |
218 |
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs |
230 |
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs |
219 |
$xmlrecord =~ s/\&amp;/\&/g; |
231 |
$xmlrecord =~ s/\&amp;/\&/g; |
220 |
} |
232 |
} |
Lines 313-318
sub buildKohaItemsNamespace {
Link Here
|
313 |
return $xml; |
325 |
return $xml; |
314 |
} |
326 |
} |
315 |
|
327 |
|
|
|
328 |
=head |
329 |
|
330 |
Makes a C4::Search::SimpleSearch() to find all records from the index rcn=Record-control-number matching the given |
331 |
field 001 value. |
332 |
Strips some key identifiers from those records. |
333 |
Builds a XML presentation out of those, ready for the XSLT processing. |
334 |
|
335 |
$childRecordsXML = &_prepareChildRecords($field001Data); |
336 |
|
337 |
In Koha the field 001 is not the same as the biblionumber! |
338 |
|
339 |
Returns: a string containing an XML representation of child records |
340 |
In XSL: childRecords/child/title |
341 |
in addition to title, elements can also be subtitle, biblionumber, author, publishercode, publicationyear |
342 |
eg. childRecords/child/biblionumber |
343 |
|
344 |
=cut |
345 |
sub _prepareChildRecords { |
346 |
|
347 |
my $field001Data = shift; |
348 |
my $childRecordsXML; |
349 |
my ($error, $childRecordISOs, $resultSetSize) = C4::Search::SimpleSearch("rcn=$field001Data"); |
350 |
#TODO my ($error, $childRecordISOs, $resultSetSize) = C4::Search::SimpleSearch("rcn=$biblionumber title-sort-az"); |
351 |
# how the hell do I sort the result set? BTW I cant sort it by title. le fuuu! |
352 |
|
353 |
if ($resultSetSize && !$error) { |
354 |
|
355 |
#Collect the XML elements to a array instead of continuously concatenating a string. |
356 |
# There might be dozens of child records and in such a case string concatenation is extremely slow. |
357 |
my @childRecordsXML = ('<childRecords>'); #@childRecordsXML vs $childRecordsXML is a nice Perl curiosity! |
358 |
for my $cr ( @{$childRecordISOs} ) { |
359 |
push @childRecordsXML, ' <child>'; |
360 |
my $marcrecord = MARC::File::USMARC::decode($cr); |
361 |
my $childBiblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,q{}); |
362 |
|
363 |
push @childRecordsXML, " <title>$childBiblio->{'title'}</title>" if $childBiblio->{'title'}; |
364 |
push @childRecordsXML, " <subtitle>$childBiblio->{'subtitle'}</subtitle>" if $childBiblio->{'subtitle'}; |
365 |
push @childRecordsXML, " <biblionumber>$childBiblio->{'biblionumber'}</biblionumber>" if $childBiblio->{'biblionumber'}; |
366 |
push @childRecordsXML, " <author>$childBiblio->{'author'}</author>" if $childBiblio->{'author'}; |
367 |
push @childRecordsXML, " <publishercode>$childBiblio->{'publishercode'}</publishercode>" if $childBiblio->{'publishercode'}; |
368 |
push @childRecordsXML, " <publicationyear>$childBiblio->{'publicationyear'}</publicationyear>" if $childBiblio->{'publicationyear'}; |
369 |
|
370 |
push @childRecordsXML, ' </child>'; |
371 |
} |
372 |
push @childRecordsXML, '</childRecords>'; |
373 |
push @childRecordsXML, ''; #Just to make the join operation end with a newline |
374 |
|
375 |
#Build the real XML string. |
376 |
$childRecordsXML = join "\n", @childRecordsXML; |
377 |
|
378 |
return $childRecordsXML; |
379 |
} |
380 |
return ''; #Instantiate this string so we don't get undefined errors when concatenating with this. |
381 |
} |
316 |
|
382 |
|
317 |
|
383 |
|
318 |
1; |
384 |
1; |