From 4ea26c0a697fcd8e4f88feb9a4f43a8b02c06650 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 5 Nov 2018 14:22:27 +0200 Subject: [PATCH] Bug 11529: Use new biblio fields whenever possible Signed-off-by: Michal Denar Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Biblio.pm | 49 ++++++++++++------- C4/HoldsQueue.pm | 17 ++++--- C4/Overdues.pm | 4 ++ C4/Search.pm | 2 +- C4/ShelfBrowser.pm | 7 ++- Koha/Biblio.pm | 11 ++--- acqui/neworderbiblio.pl | 2 +- basket/basket.pl | 4 +- catalogue/detail.pl | 2 +- catalogue/moredetail.pl | 2 +- circ/branchoverdues.pl | 8 +-- circ/pendingreserves.pl | 11 +++-- circ/reserveratios.pl | 9 ++-- circ/transferstoreceive.pl | 7 +-- .../prog/en/includes/waiting_holds.inc | 2 +- .../prog/en/modules/circ/pendingreserves.tt | 2 +- .../prog/en/modules/circ/view_holdsqueue.tt | 6 ++- opac/opac-basket.pl | 2 +- opac/opac-detail.pl | 2 +- opac/opac-readingrecord.pl | 3 +- opac/opac-reserve.pl | 6 ++- opac/opac-sendshelf.pl | 2 +- opac/opac-shelves.pl | 2 +- opac/opac-showreviews.pl | 6 ++- opac/opac-tags.pl | 5 +- opac/opac-user.pl | 13 ++--- svc/checkouts | 14 ++++-- svc/holds | 17 ++++--- t/Biblio.t | 2 +- t/Biblio2.t | 16 ++++++ tags/list.pl | 5 +- tools/batch_delete_records.pl | 2 +- virtualshelves/sendshelf.pl | 3 +- virtualshelves/shelves.pl | 2 +- 34 files changed, 146 insertions(+), 101 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 35b8fbb672..e039fe71b1 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -67,6 +67,7 @@ BEGIN { TransformHtmlToMarc TransformHtmlToXml prepare_host_field + SplitSubtitle ); # Internal functions @@ -644,39 +645,33 @@ sub _check_valid_auth_link { =head2 GetRecordValue - my $values = GetRecordValue($field, $record, $frameworkcode); + my $values = GetRecordValue($field, $record); -Get MARC fields from a keyword defined in fieldmapping table. +Get MARC fields from the record using the framework mappings for biblio fields. =cut sub GetRecordValue { - my ( $field, $record, $frameworkcode ) = @_; + my ( $field, $record ) = @_; if (!$record) { carp 'GetRecordValue called with undefined record'; return; } - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?'); - $sth->execute( $frameworkcode, $field ); - - my @result = (); - - while ( my $row = $sth->fetchrow_hashref ) { - foreach my $field ( $record->field( $row->{fieldcode} ) ) { - if ( ( $row->{subfieldcode} ne "" && $field->subfield( $row->{subfieldcode} ) ) ) { - foreach my $subfield ( $field->subfield( $row->{subfieldcode} ) ) { - push @result, { 'subfield' => $subfield }; - } - } elsif ( $row->{subfieldcode} eq "" ) { - push @result, { 'subfield' => $field->as_string() }; + my @result; + my @mss = GetMarcSubfieldStructureFromKohaField("biblio.$field"); + foreach my $fldhash ( @mss ) { + my $tag = $fldhash->{tagfield}; + my $sub = $fldhash->{tagsubfield}; + foreach my $fld ( $record->field($tag) ) { + if( $sub eq '@' || $fld->is_control_field ) { + push @result, $fld->data if $fld->data; + } else { + push @result, grep { $_ } $fld->subfield($sub); } } } - return \@result; } @@ -3458,6 +3453,22 @@ sub RemoveAllNsb { return $record; } +=head2 SplitSubtitle + + $subtitles = SplitSubtitle($subtitle); + +Splits a subtitle field to an array of hashes like the one GetRecordValue returns + +=cut + +sub SplitSubtitle { + my $subtitle = shift; + + my @subtitles = map( { 'subfield' => $_ }, split(/ \| /, $subtitle // '' ) ); + + return \@subtitles; +} + 1; diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index d55e7e3161..650f1792da 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -132,7 +132,12 @@ sub GetHoldsQueueItems { my $dbh = C4::Context->dbh; my @bind_params = (); - my $query = q/SELECT tmp_holdsqueue.*, biblio.author, items.ccode, items.itype, biblioitems.itemtype, items.location, items.enumchron, items.cn_sort, biblioitems.publishercode,biblio.copyrightdate,biblioitems.publicationyear,biblioitems.pages,biblioitems.size,biblioitems.publicationyear,biblioitems.isbn,items.copynumber + my $query = q/SELECT tmp_holdsqueue.*, biblio.author, items.ccode, items.itype, biblioitems.itemtype, items.location, + items.enumchron, items.cn_sort, biblioitems.publishercode, + biblio.copyrightdate, biblio.subtitle, biblio.part_number, + biblio.part_name, + biblioitems.publicationyear, biblioitems.pages, biblioitems.size, biblioitems.publicationyear, + biblioitems.isbn, items.copynumber FROM tmp_holdsqueue JOIN biblio USING (biblionumber) LEFT JOIN biblioitems USING (biblionumber) @@ -147,19 +152,15 @@ sub GetHoldsQueueItems { $sth->execute(@bind_params); my $items = []; while ( my $row = $sth->fetchrow_hashref ){ - my $record = GetMarcBiblio({ biblionumber => $row->{biblionumber} }); - if ($record){ - $row->{subtitle} = [ map { $_->{subfield} } @{ GetRecordValue( 'subtitle', $record, '' ) } ]; - $row->{parts} = GetRecordValue('parts',$record,'')->[0]->{subfield}; - $row->{numbers} = GetRecordValue('numbers',$record,'')->[0]->{subfield}; - } - # return the bib-level or item-level itype per syspref if (!C4::Context->preference('item-level_itypes')) { $row->{itype} = $row->{itemtype}; } delete $row->{itemtype}; + my @subtitles = split(/ \| /, $row->{'subtitle'} // '' ); + $row->{'subtitle'} = \@subtitles; + push @$items, $row; } return $items; diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 2a617335bc..fa8d6e648a 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -701,6 +701,10 @@ sub GetOverduesForBranch { borrowers.phone, borrowers.email, biblio.title, + biblio.subtitle, + biblio.medium, + biblio.part_number, + biblio.part_name, biblio.author, biblio.biblionumber, issues.date_due, diff --git a/C4/Search.pm b/C4/Search.pm index 91af94caf4..6d7157c6ac 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1938,7 +1938,7 @@ sub searchResults { SetUTF8Flag($marcrecord); my $oldbiblio = TransformMarcToKoha( $marcrecord, $fw ); - $oldbiblio->{subtitle} = GetRecordValue('subtitle', $marcrecord, $fw); + $oldbiblio->{subtitle} = GetRecordValue('subtitle', $marcrecord); $oldbiblio->{result_number} = $i + 1; # add imageurl to itemtype if there is one diff --git a/C4/ShelfBrowser.pm b/C4/ShelfBrowser.pm index ee551d2c83..b5d19799b6 100644 --- a/C4/ShelfBrowser.pm +++ b/C4/ShelfBrowser.pm @@ -223,12 +223,15 @@ sub GetShelfInfo { my $this_biblio = GetBibData($item->{biblionumber}); next unless defined $this_biblio; $item->{'title'} = $this_biblio->{'title'}; + $item->{'subtitle'} = C4::Biblio::SplitSubtitle($this_biblio->{'subtitle'}), + $item->{'medium'} = $this_biblio->{'medium'}; + $item->{'part_number'} = $this_biblio->{'part_number'}; + $item->{'part_name'} = $this_biblio->{'part_name'}; my $this_record = GetMarcBiblio({ biblionumber => $this_biblio->{'biblionumber'} }); $item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour); $item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour); $item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour); $item->{'browser_normalized_ean'} = GetNormalizedEAN($this_record,$marcflavour); - $item->{'subtitle'} = GetRecordValue('subtitle', $this_record, GetFrameworkCode( $item->{biblionumber} )); push @valid_items, $item; } return @valid_items; @@ -239,7 +242,7 @@ sub GetBibData { my ($bibnum) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT biblionumber, title FROM biblio WHERE biblionumber=?"); + my $sth = $dbh->prepare("SELECT biblionumber, title, subtitle, medium, part_number, part_name FROM biblio WHERE biblionumber=?"); $sth->execute($bibnum); my $bib = $sth->fetchrow_hashref(); return $bib; diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index f38a101e27..d944cb06f7 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -84,20 +84,15 @@ sub metadata { my @subtitles = $biblio->subtitles(); -Returns list of subtitles for a record. - -Keyword to MARC mapping for subtitle must be set for this method to return any possible values. +Returns list of subtitles for a record according to the framework. =cut sub subtitles { my ( $self ) = @_; - return map { $_->{subfield} } @{ - C4::Biblio::GetRecordValue( - 'subtitle', - C4::Biblio::GetMarcBiblio({ biblionumber => $self->id }), - $self->frameworkcode ) }; + my @subtitles = split( / \| /, $self->subtitle // '' ); + return @subtitles; } =head3 can_article_request diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index b48737d79f..8333b4723f 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -129,8 +129,8 @@ my @results; foreach my $result ( @{$marcresults} ) { my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $result ); my $biblio = TransformMarcToKoha( $marcrecord, '' ); - $biblio->{subtitles} = GetRecordValue( 'subtitle', GetMarcBiblio({ biblionumber => $biblio->{biblionumber} }), GetFrameworkCode( $biblio->{biblionumber} ) ); + $biblio->{subtitles} = C4::Biblio::SplitSubtitle($biblio->{'subtitle'}); $biblio->{booksellerid} = $booksellerid; push @results, $biblio; diff --git a/basket/basket.pl b/basket/basket.pl index 4318a9560f..c6d317035b 100755 --- a/basket/basket.pl +++ b/basket/basket.pl @@ -59,12 +59,10 @@ if (C4::Context->preference('TagsEnabled')) { foreach my $biblionumber ( @bibs ) { $template->param( biblionumber => $biblionumber ); - my $fw = GetFrameworkCode($biblionumber); - my $dat = &GetBiblioData($biblionumber); next unless $dat; my $record = &GetMarcBiblio({ biblionumber => $biblionumber }); - $dat->{subtitle} = GetRecordValue('subtitle', $record, $fw); + $dat->{subtitle} = GetRecordValue('subtitle', $record); my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index b7e4d6eced..42846359e1 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -142,7 +142,7 @@ my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries($record,$marcflavour); my $marcurlsarray = GetMarcUrls ($record,$marcflavour); my $marchostsarray = GetMarcHosts($record,$marcflavour); -my $subtitle = GetRecordValue('subtitle', $record, $fw); +my $subtitle = GetRecordValue('subtitle', $record); my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 57647ed097..a4152b44bb 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -110,7 +110,7 @@ if (@hostitems){ push (@items,@hostitems); } -my $subtitle = GetRecordValue('subtitle', $record, $fw); +my $subtitle = GetRecordValue('subtitle', $record); my $totalcount=@all_items; my $showncount=@items; diff --git a/circ/branchoverdues.pl b/circ/branchoverdues.pl index 577ec2a706..e696d77ed7 100755 --- a/circ/branchoverdues.pl +++ b/circ/branchoverdues.pl @@ -76,13 +76,13 @@ if ($tagslib->{$tag}->{$subfield}->{authorised_value}) { # now display infos foreach my $num (@getoverdues) { my %overdueforbranch; - my $record = GetMarcBiblio({ biblionumber => $num->{biblionumber} }); - if ($record){ - $overdueforbranch{'subtitle'} = GetRecordValue('subtitle',$record,'')->[0]->{subfield}; - } my $dt = dt_from_string($num->{date_due}, 'sql'); $overdueforbranch{'date_due'} = output_pref($dt); $overdueforbranch{'title'} = $num->{'title'}; + $overdueforbranch{'subtitle'} = $num->{'subtitle'}; + $overdueforbranch{'medium'} = $num->{'medium'}; + $overdueforbranch{'part_number'} = $num->{'part_number'}; + $overdueforbranch{'part_name'} = $num->{'part_name'}; $overdueforbranch{'description'} = $num->{'description'}; $overdueforbranch{'barcode'} = $num->{'barcode'}; $overdueforbranch{'biblionumber'} = $num->{'biblionumber'}; diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 4fdfdacbd1..d890673490 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -198,6 +198,10 @@ my $strsth = GROUP_CONCAT(DISTINCT items.copynumber ORDER BY items.itemnumber SEPARATOR '|') l_copynumber, biblio.title, + biblio.subtitle, + biblio.medium, + biblio.part_number, + biblio.part_name, biblio.author, count(DISTINCT items.itemnumber) as icount, count(DISTINCT reserves.borrowernumber) as rcount, @@ -237,10 +241,6 @@ my $sth = $dbh->prepare($strsth); $sth->execute(@query_params); while ( my $data = $sth->fetchrow_hashref ) { - my $record = Koha::Biblios->find($data->{biblionumber}); - if ($record){ - $data->{subtitle} = [ $record->subtitles ]; - } push( @reservedata, { reservedate => $data->{l_reservedate}, @@ -248,6 +248,9 @@ while ( my $data = $sth->fetchrow_hashref ) { surname => $data->{surname}, title => $data->{title}, subtitle => $data->{subtitle}, + medium => $data->{medium}, + part_number => $data->{part_number}, + part_name => $data->{part_name}, author => $data->{author}, borrowernumber => $data->{borrowernumber}, biblionumber => $data->{biblionumber}, diff --git a/circ/reserveratios.pl b/circ/reserveratios.pl index 104928addc..15e68959fa 100755 --- a/circ/reserveratios.pl +++ b/circ/reserveratios.pl @@ -27,7 +27,6 @@ use C4::Context; use C4::Output; use C4::Auth; use C4::Debug; -use C4::Biblio qw/GetMarcBiblio GetRecordValue GetFrameworkCode/; use C4::Acquisition qw/GetOrdersByBiblionumber/; use Koha::DateUtils; use Koha::Acquisition::Baskets; @@ -125,6 +124,10 @@ my $strsth = reserves.found, biblio.title, + biblio.subtitle, + biblio.medium, + biblio.part_number, + biblio.part_name, biblio.author, count(DISTINCT reserves.borrowernumber) as reservecount, count(DISTINCT items.itemnumber) $include_aqorders_qty as itemcount @@ -154,8 +157,6 @@ while ( my $data = $sth->fetchrow_hashref ) { my $thisratio = $data->{reservecount} / $data->{itemcount}; my $ratiocalc = ($thisratio / $ratio); ($thisratio / $ratio) >= 1 or next; # TODO: tighter targeting -- get ratio limit into SQL using HAVING clause - my $record = GetMarcBiblio({ biblionumber => $data->{biblionumber} }); - $data->{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($data->{biblionumber})); push( @reservedata, { @@ -163,7 +164,7 @@ while ( my $data = $sth->fetchrow_hashref ) { priority => $data->{priority}, name => $data->{borrower}, title => $data->{title}, - subtitle => $data->{subtitle}, + subtitle => C4::Biblio::SplitSubtitle($data->{'subtitle'}); author => $data->{author}, itemnum => $data->{itemnumber}, biblionumber => $data->{biblionumber}, diff --git a/circ/transferstoreceive.pl b/circ/transferstoreceive.pl index a727dda165..f1c09ef013 100755 --- a/circ/transferstoreceive.pl +++ b/circ/transferstoreceive.pl @@ -99,6 +99,10 @@ while ( my $library = $libraries->next ) { %getransf = ( %getransf, title => $biblio->title, + subtitle => C4::Biblio::SplitSubtitle($biblio->{'subtitle'}), + medium => $biblio->medium, + part_number => $biblio->part_number, + part_name => $biblio->part_name, author => $biblio->author, biblionumber => $biblio->biblionumber, itemnumber => $item->itemnumber, @@ -108,9 +112,6 @@ while ( my $library = $libraries->next ) { itemcallnumber => $item->itemcallnumber, ); - my $record = GetMarcBiblio({ biblionumber => $biblio->biblionumber }); - $getransf{'subtitle'} = GetRecordValue('subtitle', $record, $biblio->frameworkcode); - # we check if we have a reserv for this transfer my $holds = $item->current_holds; if ( my $first_hold = $holds->next ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc index b635e03d12..f4606ac51e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/waiting_holds.inc @@ -22,7 +22,7 @@ [% reserveloo.waitingdate | $KohaDates %] [% reserveloo.reservedate | $KohaDates %] [% INCLUDE 'biblio-default-view.inc' biblionumber = reserveloo.biblionumber %] - [% reserveloo.biblio.title | html %] [% FOREACH subtitl IN reserveloo.biblio.subtitles %] [% subtitl.subfield | html %][% END %] + [% reserveloo.biblio.title | html %] [% FOREACH subtitl IN reserveloo.biblio.subtitles %] [% subtitl | html %] [% reserveloo.biblio.part_number | html %] [% reserveloo.biblio.part_name | html %][% END %] [% UNLESS ( item_level_itypes ) %] [% IF ( ItemTypes.GetDescription(reserveloo.item.effective_itemtype) ) %]  ([% ItemTypes.GetDescription(reserveloo.item.effective_itemtype) | html %]) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt index 331e0a155f..edf9d32058 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt @@ -77,7 +77,7 @@

[% INCLUDE 'biblio-default-view.inc' biblionumber = reserveloo.biblionumber %] - [% reserveloo.title | html %] [% FOREACH s IN reserveloo.subtitle %] [% s | html %][% END %]

+ [% reserveloo.title | html %] [% FOREACH s IN reserveloo.subtitle %] [% s | html %][% END %] [% reserveloo.part_number | html %] [% reserveloo.part_name | html %]

[% IF ( reserveloo.author ) %]

by [% reserveloo.author | html %]

[% END %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt index 691b63161c..cd7c0df373 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt @@ -123,7 +123,11 @@ [% FOREACH itemsloo IN itemsloop %] -

[% itemsloo.title | html %] [% FOREACH s IN itemsloo.subtitle %] [% s | html %][% END %]

+

+ + [% itemsloo.title | html %] [% FOREACH s IN itemsloo.subtitle %] [% s | html %][% END %] [% itemsloo.part_number | html %] [% itemsloo.part_name | html %] + +

[% itemsloo.biblionumber | html %]
[% itemsloo.author | html %]
diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index c2d57f2f5e..7d7baf1155 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -108,7 +108,7 @@ foreach my $biblionumber ( @bibs ) { } } - my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber)); + my $subtitle = GetRecordValue('subtitle', $record); my $hasauthors = 0; if($dat->{'author'} || @$marcauthorsarray) { diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 8f044f5c1a..dfa459859d 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -767,7 +767,7 @@ if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) { } my $marcnotesarray = GetMarcNotes ($record,$marcflavour); -my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber)); +my $subtitle = GetRecordValue('subtitle', $record); if( C4::Context->preference('ArticleRequests') ) { my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef; diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index c01409a700..00c7c436d8 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -98,8 +98,7 @@ foreach my $issue ( @{$issues} ) { my $marc_rec = MARC::Record::new_from_xml( $marcxml, 'utf8', C4::Context->preference('marcflavour') ); - $issue->{subtitle} = - GetRecordValue( 'subtitle', $marc_rec, $issue->{frameworkcode} ); + $issue->{subtitle} = GetRecordValue( 'subtitle', $marc_rec ); $issue->{normalized_upc} = GetNormalizedUPC( $marc_rec, C4::Context->preference('marcflavour') ); } # My Summary HTML diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 472d0f5519..a7631d328b 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -400,7 +400,6 @@ $template->param('item_level_itypes' => $itemLevelTypes); foreach my $biblioNum (@biblionumbers) { - my $record = GetMarcBiblio({ biblionumber => $biblioNum }); # Init the bib item with the choices for branch pickup my %biblioLoopIter; @@ -420,7 +419,10 @@ foreach my $biblioNum (@biblionumbers) { my $frameworkcode = GetFrameworkCode( $biblioData->{biblionumber} ); $biblioLoopIter{biblionumber} = $biblioData->{biblionumber}; $biblioLoopIter{title} = $biblioData->{title}; - $biblioLoopIter{subtitle} = GetRecordValue('subtitle', $record, $frameworkcode); + $biblioLoopIter{subtitle} = C4::Biblio::SplitSubtitle($biblioData->{'subtitle'}); + $biblioLoopIter{medium} = $biblioData->{medium}; + $biblioLoopIter{part_number} = $biblioData->{part_number}; + $biblioLoopIter{part_name} = $biblioData->{part_name}; $biblioLoopIter{author} = $biblioData->{author}; $biblioLoopIter{rank} = $biblioData->{rank}; $biblioLoopIter{reservecount} = $biblioData->{reservecount}; diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index 1df7a672fd..0b115ec169 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -101,7 +101,7 @@ if ( $email ) { my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); - my $subtitle = GetRecordValue('subtitle', $record, $fw); + my $subtitle = GetRecordValue('subtitle', $record); my @items = GetItemsInfo( $biblionumber ); diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index cca12f2bb2..2a391a0e48 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -295,7 +295,7 @@ if ( $op eq 'view' ) { $this_item->{notforloan} = $itemtype->notforloan; } $this_item->{'coins'} = $biblio->get_coins; - $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) ); + $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record ), $this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour ); $this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour ); $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour ); diff --git a/opac/opac-showreviews.pl b/opac/opac-showreviews.pl index fc6dc6cac1..05432a611e 100755 --- a/opac/opac-showreviews.pl +++ b/opac/opac-showreviews.pl @@ -91,13 +91,15 @@ for my $result (@$reviews){ my $biblio = Koha::Biblios->find( $biblionumber ); my $biblioitem = $biblio->biblioitem; my $record = GetMarcBiblio({ biblionumber => $biblionumber }); - my $frameworkcode = GetFrameworkCode($biblionumber); $result->{normalized_upc} = GetNormalizedUPC($record,$marcflavour); $result->{normalized_ean} = GetNormalizedEAN($record,$marcflavour); $result->{normalized_oclc} = GetNormalizedOCLCNumber($record,$marcflavour); $result->{normalized_isbn} = GetNormalizedISBN(undef,$record,$marcflavour); $result->{title} = $biblio->title; - $result->{subtitle} = GetRecordValue('subtitle', $record, $frameworkcode); + $result->{subtitle} = GetRecordValue('subtitle', $record ); + $result->{medium} = $biblio->medium; + $result->{part_number} = $biblio->part_number; + $result->{part_name} = $biblio->part_name; $result->{author} = $biblio->author; $result->{place} = $biblioitem->place; $result->{publishercode} = $biblioitem->publishercode; diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index d9c5add813..2d7dfae5ec 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -256,8 +256,11 @@ if ($loggedinuser) { $hidden_items = \@hidden_itemnumbers; } next if ( $should_hide && scalar @all_items == scalar @hidden_itemnumbers ); - $tag->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $tag->{biblionumber} ) ); $tag->{title} = $biblio->title; + $tag->{subtitle} = C4::Biblio::SplitSubtitle($biblio->subtitle); + $tag->{medium} = $biblio->medium; + $tag->{part_number} = $biblio->part_number; + $tag->{part_name} = $biblio->part_name; $tag->{author} = $biblio->author; my $xslfile = C4::Context->preference('OPACXSLTResultsDisplay'); diff --git a/opac/opac-user.pl b/opac/opac-user.pl index d7b1355a9d..56ae5ad22c 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -201,12 +201,8 @@ if ( $pending_checkouts->count ) { # Useless test ); $issue->{rentalfines} = $rental_fines->total_outstanding; - my $marcrecord = GetMarcBiblio({ - biblionumber => $issue->{'biblionumber'}, - embed_items => 1, - opac => 1, - borcat => $borcat }); - $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'})); + $issue->{'subtitle'} = C4::Biblio::SplitSubtitle($issue->{'subtitle'}); + # check if item is renewable my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} ); ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'}); @@ -258,6 +254,11 @@ if ( $pending_checkouts->count ) { # Useless test my $isbn = GetNormalizedISBN($issue->{'isbn'}); $issue->{normalized_isbn} = $isbn; + my $marcrecord = GetMarcBiblio({ + biblionumber => $issue->{'biblionumber'}, + embed_items => 1, + opac => 1, + borcat => $borcat }); $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') ); # My Summary HTML diff --git a/svc/checkouts b/svc/checkouts index 9a1b3a5648..8aecac1cb0 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -23,7 +23,7 @@ use CGI; use JSON qw(to_json); use C4::Auth qw(check_cookie_auth haspermission get_session); -use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue ); +use C4::Biblio qw(SplitSubtitle); use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate); use C4::Overdues qw(GetFine); use C4::Context; @@ -74,6 +74,10 @@ my $sql = ' biblionumber, biblio.title, + biblio.subtitle, + biblio.medium, + biblio.part_number, + biblio.part_name, author, itemnumber, @@ -174,6 +178,10 @@ while ( my $c = $sth->fetchrow_hashref() ) { my $checkout = { DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber}, title => $c->{title}, + subtitle => C4::Biblio::SplitSubtitle($c->{'subtitle'}), + medium => $c->{medium} // '', + part_number => $c->{part_number} // '', + part_name => $c->{part_name} // '', author => $c->{author}, barcode => $c->{barcode}, itemtype => $item_level_itypes ? $c->{itype} : $c->{itemtype}, @@ -216,10 +224,6 @@ while ( my $c = $sth->fetchrow_hashref() ) { as_due_date => 1 } ), - subtitle => GetRecordValue( - 'subtitle', - GetMarcBiblio({ biblionumber => $c->{biblionumber} }), - GetFrameworkCode( $c->{biblionumber} ) ), lost => $lost, damaged => $damaged, borrower => { diff --git a/svc/holds b/svc/holds index 062109d40c..8b9a27b310 100755 --- a/svc/holds +++ b/svc/holds @@ -23,7 +23,7 @@ use CGI; use JSON qw(to_json); use C4::Auth qw(check_cookie_auth); -use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue ); +use C4::Biblio qw(SplitSubtitle); use C4::Charset; use C4::Circulation qw(GetTransfers); use C4::Context; @@ -84,11 +84,17 @@ while ( my $h = $holds_rs->next() ) { for my $library ( @$libraries ) { $library->{selected} = 1 if $library->{branchcode} eq $h->branchcode(); } + + my $biblio = $h->biblio(); my $hold = { DT_RowId => $h->reserve_id(), biblionumber => $biblionumber, - title => $h->biblio()->title(), - author => $h->biblio()->author(), + title => $biblio->title(), + subtitle => $biblio->subtitle() // '', + medium => $biblio->medium() // '', + part_number => $biblio->part_number() // '', + part_name => $biblio->part_name() // '', + author => $biblio->author(), reserve_id => $h->reserve_id(), branchcode => $h->branch()->branchname(), branches => $libraries, @@ -102,11 +108,6 @@ while ( my $h = $holds_rs->next() ) { waiting_here => $h->branch()->branchcode() eq $branch, priority => $h->priority(), itemtype_limit => $itemtype_limit, - subtitle => GetRecordValue( - 'subtitle', - GetMarcBiblio({ biblionumber => $biblionumber }), - GetFrameworkCode($biblionumber) - ), reservedate_formatted => $h->reservedate() ? output_pref( { dt => dt_from_string( $h->reservedate() ), dateonly => 1 } ) diff --git a/t/Biblio.t b/t/Biblio.t index da34dca4ee..4400017e1e 100755 --- a/t/Biblio.t +++ b/t/Biblio.t @@ -51,7 +51,7 @@ warning_is { $ret = BiblioAutoLink(undef, q{}) } is( $ret, 0, 'BiblioAutoLink returns zero if not passed rec'); -warning_is { $ret = GetRecordValue('100', undef, q{}) } +warning_is { $ret = GetRecordValue('100', undef) } { carped => 'GetRecordValue called with undefined record'}, "GetRecordValue returns carped warning on undef record"; diff --git a/t/Biblio2.t b/t/Biblio2.t index 3cb0cb051c..21354eb578 100644 --- a/t/Biblio2.t +++ b/t/Biblio2.t @@ -52,4 +52,20 @@ sub _koha_marc_update_bib_ids_control { is($r->field('004')->data(), 20, 'Biblioitemnumber to control field'); } +subtest 'SplitSubtitle' => sub { + plan tests => 4; + + my $res = C4::Biblio::SplitSubtitle(undef); + is_deeply($res, [], 'undef returned as an array'); + + $res = C4::Biblio::SplitSubtitle(''); + is_deeply($res, [], 'Empty string returned as an array'); + + $res = C4::Biblio::SplitSubtitle('Single'); + is_deeply($res, [{'subfield' => 'Single'}], 'Single subtitle returns an array'); + + $res = C4::Biblio::SplitSubtitle('First | Second'); + is_deeply($res, [{'subfield' => 'First'}, {'subfield' => 'Second'}], 'Two subtitles returns an array'); +}; + done_testing(); diff --git a/tags/list.pl b/tags/list.pl index 862327862f..6f39da509e 100755 --- a/tags/list.pl +++ b/tags/list.pl @@ -61,10 +61,7 @@ else { my $taglist = get_tag_rows( { term => $tag } ); for ( @{$taglist} ) { my $dat = &GetBiblioData( $_->{biblionumber} ); - my $record = &GetMarcBiblio({ biblionumber => $_->{biblionumber} }); - $dat->{'subtitle'} = - GetRecordValue( 'subtitle', $record, - GetFrameworkCode( $_->{biblionumber} ) ); + $dat->{'subtitle'} = C4::Biblio::SplitSubtitles($dat->{'subtitle'}), my @items = GetItemsInfo( $_->{biblionumber} ); $dat->{biblionumber} = $_->{biblionumber}; $dat->{tag_id} = $_->{tag_id}; diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index 34c6b5a8ac..9eba7354a4 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -94,7 +94,7 @@ if ( $op eq 'form' ) { my $holds_count = $biblio->holds->count; $biblio = $biblio->unblessed; my $record = &GetMarcBiblio({ biblionumber => $record_id }); - $biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) ); + $biblio->{subtitle} = C4::Biblio::SplitSubtitle( $biblio->{subtitle} ); $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')]; $biblio->{holds_count} = $holds_count; $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl index 3c077ef35d..c8d3cab1d2 100755 --- a/virtualshelves/sendshelf.pl +++ b/virtualshelves/sendshelf.pl @@ -77,14 +77,13 @@ if ($email) { while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; - my $fw = GetFrameworkCode($biblionumber); my $dat = GetBiblioData($biblionumber); my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); - my $subtitle = GetRecordValue( 'subtitle', $record, $fw ); + my $subtitle = GetRecordValue( 'subtitle', $record ); my @items = GetItemsInfo($biblionumber); diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 5fddf374a4..49e7d5c725 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -280,7 +280,7 @@ if ( $op eq 'view' ) { $this_item->{description} = $itemtype ? $itemtype->description : q{}; #FIXME Should this be translated_description ? $this_item->{notforloan} = $itemtype->notforloan if $itemtype; $this_item->{'coins'} = $biblio->get_coins; - $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) ); + $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record ); $this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour ); $this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour ); $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour ); -- 2.39.5