From 1556f57f40d0f4b8fd3061706e4ac0d97c731c5f Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Wed, 30 Oct 2013 20:32:47 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 11175 - Show the parent records child records (aka. component parts) in the detailed views. TERMINOLOGY: "Child record" or "Component part": A Bibliographic record connected to it's host record via $773w -> 001 or via other Record-control-number-index relation. "Host record": A bibliographic record which contains child records. Host record doesn't have a link to the child record. USEFUL: For music cataloguers whose jobs depend on these. For browsing the contents of a musical record. Provides the basis for a high quality music library service. Because Koha has the building blocks to create these child records out of box, it is odd that they can't be displayed out of box. This patch adds a system preference AddChildRecordsToDetailedViews. This controls if child records data is appended after the bibliographic data for XSLT parsing. Also makes sure that child records are not pulled needlessly for non-detailed views as this would cripple performance. Modifies the default XSLT templates: MARC21slim2intranetDetail.xsl and MARC21slim2OPACDetail.xsl to display the child record data as HTML and link to the detailed views fopr the child records. Modifies .css files as well. An extra container div is added to opac-detail.tt, mimicking presentation in detail.tt, to prevent a possible long child records list from breaking the opac-details -view. -------------------------------------- TEST PLAN -------------------------------------- PREREQUISITES: -AddChildRecordsToDetailedViews system preference needs to be activated. -Catalog a bunch of child records for a host record. --Search a record and go to detailed view. --Use the existing functionality "+ New" -> "New Child Record" to catalog child records. ------------------------ TEST CASE1 - Staff client ------------------------ -Search for the record you just made and display it in the normal detail.pl -view. -Verify that a list of child records are displayed on the right side of the browser window. ------------------------ TEST CASE2 - OPAC ------------------------ -Search for the record you just made and display it in the opac-detail.pl -view. -Verify that a list of child records are displayed on the right side of the browser window. ------------------------ Thank you! Signed-off-by: Garming Sam Needs follow up to work with bootstrap theme. Otherwise, appears to work as intended. --- C4/XSLT.pm | 68 +++++++++++++++++++- installer/data/mysql/sysprefs.sql | 1 + .../intranet-tmpl/prog/en/css/staff-global.css | 3 + .../en/modules/admin/preferences/cataloguing.pref | 7 ++ .../prog/en/xslt/MARC21slim2intranetDetail.xsl | 29 +++++++++ koha-tmpl/opac-tmpl/prog/en/css/opac.css | 3 + koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 3 +- .../prog/en/xslt/MARC21slim2OPACDetail.xsl | 33 +++++++++- 8 files changed, 142 insertions(+), 5 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index d85b048..a014e4f 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -158,6 +158,9 @@ sub _get_best_default_xslt_filename { sub XSLTParse4Display { my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; + + my $shouldIPullChildRecords; #We don't want to pull child records if they are not needed! Show child records only for detailed views. + my $xslfilename = C4::Context->preference($xslsyspref); if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my $htdocs; @@ -169,6 +172,7 @@ sub XSLTParse4Display { $theme = C4::Context->preference("template"); $xslfile = C4::Context->preference('marcflavour') . "slim2intranetDetail.xsl"; + $shouldIPullChildRecords = 1; } elsif ($xslsyspref eq "XSLTResultsDisplay") { $htdocs = C4::Context->config('intrahtdocs'); $theme = C4::Context->preference("template"); @@ -179,6 +183,7 @@ sub XSLTParse4Display { $theme = C4::Context->preference("opacthemes"); $xslfile = C4::Context->preference('marcflavour') . "slim2OPACDetail.xsl"; + $shouldIPullChildRecords = 1; } elsif ($xslsyspref eq "OPACXSLTResultsDisplay") { $htdocs = C4::Context->config('opachtdocs'); $theme = C4::Context->preference("opacthemes"); @@ -192,9 +197,16 @@ sub XSLTParse4Display { my $lang = C4::Templates::_current_language(); $xslfilename =~ s/\{langcode\}/$lang/; } + # grab the XML, run it through our stylesheet, push it out to the browser my $record = transformMARCXML4XSLT($biblionumber, $orig_record); + my $f001Data = $record->field('001'); + $f001Data = $f001Data->data() if defined $f001Data; #Not all records have the field 001?? + + my $childRecordsXML = _prepareChildRecords($f001Data) if $shouldIPullChildRecords && + C4::Context->preference('AddChildRecordsToDetailedViews');; + #return $record->as_formatted(); my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); @@ -214,7 +226,7 @@ sub XSLTParse4Display { $sysxml .= "$sp\n"; } $sysxml .= "\n"; - $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; + $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$childRecordsXML\<\/record\>/; if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs $xmlrecord =~ s/\&amp;/\&/g; } @@ -313,6 +325,60 @@ sub buildKohaItemsNamespace { return $xml; } +=head + + Makes a C4::Search::SimpleSearch() to find all records from the index rcn=Record-control-number matching the given + field 001 value. + Strips some key identifiers from those records. + Builds a XML presentation out of those, ready for the XSLT processing. + + $childRecordsXML = &_prepareChildRecords($field001Data); + + In Koha the field 001 is not the same as the biblionumber! + + Returns: a string containing an XML representation of child records + In XSL: childRecords/child/title + in addition to title, elements can also be subtitle, biblionumber, author, publishercode, publicationyear + eg. childRecords/child/biblionumber + +=cut +sub _prepareChildRecords { + + my $field001Data = shift; + my $childRecordsXML; + my ($error, $childRecordISOs, $resultSetSize) = C4::Search::SimpleSearch("rcn=$field001Data"); + #TODO my ($error, $childRecordISOs, $resultSetSize) = C4::Search::SimpleSearch("rcn=$biblionumber title-sort-az"); + # how the hell do I sort the result set? BTW I cant sort it by title. le fuuu! + + if ($resultSetSize && !$error) { + + #Collect the XML elements to a array instead of continuously concatenating a string. + # There might be dozens of child records and in such a case string concatenation is extremely slow. + my @childRecordsXML = (''); #@childRecordsXML vs $childRecordsXML is a nice Perl curiosity! + for my $cr ( @{$childRecordISOs} ) { + push @childRecordsXML, ' '; + my $marcrecord = MARC::File::USMARC::decode($cr); + my $childBiblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,q{}); + + push @childRecordsXML, " $childBiblio->{'title'}" if $childBiblio->{'title'}; + push @childRecordsXML, " $childBiblio->{'subtitle'}" if $childBiblio->{'subtitle'}; + push @childRecordsXML, " $childBiblio->{'biblionumber'}" if $childBiblio->{'biblionumber'}; + push @childRecordsXML, " $childBiblio->{'author'}" if $childBiblio->{'author'}; + push @childRecordsXML, " $childBiblio->{'publishercode'}" if $childBiblio->{'publishercode'}; + push @childRecordsXML, " $childBiblio->{'publicationyear'}" if $childBiblio->{'publicationyear'}; + + push @childRecordsXML, ' '; + } + push @childRecordsXML, ''; + push @childRecordsXML, ''; #Just to make the join operation end with a newline + + #Build the real XML string. + $childRecordsXML = join "\n", @childRecordsXML; + + return $childRecordsXML; + } + return ''; #Instantiate this string so we don't get undefined errors when concatenating with this. +} 1; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index a07103a..c036325 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -3,6 +3,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AcqItemSetSubfieldsWhenReceived','0','','This syspref set a status for item when items are created when receiving (e.g. 995\$o=5)','Free'), ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'), ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'), +('AddChildRecordsToDetailedViews','1',NULL,'Show child records in the detailed views.','YesNo'), ('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'), ('advancedMARCeditor','0','','If ON, the MARC editor won\'t display field/subfield descriptions','YesNo'), ('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 755a02a..6ad7454 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -1871,6 +1871,9 @@ span.permissiondesc { .results_summary a { font-weight: normal; } +.childRecordsContainer { + float: right; +} ul.budget_hierarchy { margin-left: 0px; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index 96f3603..393ba43 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -161,6 +161,13 @@ Cataloging: class: short - (Leave blank if not used. Define a range like 192.168..) - + - "Requires XSLTDetailsDisplay and/or OPACXSLTDetailsDisplay system preferences to be active. " + - pref: AddChildRecordsToDetailedViews + choices: + yes: Show + no: "Don't show" + - child records in the detailed views. This might cause a performance penalty for records with lots of child records. Technical explanation: This enables appending child records to the bibliographic record data for the XSLT parsing. + - - pref: SeparateHoldings choices: yes: Separate diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl index 14ff809..c086a00 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl +++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl @@ -99,7 +99,36 @@ + + + + + +
Child records:
+ + + + + /cgi-bin/koha/catalogue/detail.pl?biblionumber= + + + + + + - + + + + + +
+
+
+
+ + +

diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css b/koha-tmpl/opac-tmpl/prog/en/css/opac.css index c2902c1..31bb0d8 100644 --- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css +++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css @@ -1144,6 +1144,9 @@ table#marc div.results_summary ul { table#marc div.results_summary ul li { display : inline; } +.childRecordsContainer { + float: right; +} #basketcount { display : inline; diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index 05c4010..bc3c9ec 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -528,6 +528,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
+
[%# This prevents overflow from component childrens list from breaking the detail view. %]
@@ -933,7 +934,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% END %]
- +
[%# End of div class="yui-g" %]
    diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl index c3a846c..8a05eb0 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl @@ -145,6 +145,33 @@

+ + + + + +
Child records:
+ + + + + /cgi-bin/koha/opac-detail.pl?biblionumber= + + + + + + - + + + + + +
+
+
+
+ @@ -175,8 +202,8 @@ - - + + @@ -982,7 +1009,7 @@ - + -- 1.7.9.5