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