diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 59f70c97d0..b5a092332a 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -300,6 +300,8 @@ sub get_items { return try { + # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number + # Should we use search_ordered here? Maybe as well in Koha::REST::V1::Items::list? # FIXME Do we always need host_items => 1 or depending on a flag? # FIXME Should we prefetch => ['issue','branchtransfer']? my $items_rs = $biblio->items( { host_items => 1 } )->search( {}, { join => 'biblioitem' } ) ); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 4bed0bc700..774dab7c10 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -190,21 +190,18 @@ $template->param( ); my $itemtypes = { map { $_->itemtype => $_ } @{ Koha::ItemTypes->search_with_localization->as_list } }; -my $params; my $patron = Koha::Patrons->find( $borrowernumber ); -$params->{ itemlost } = 0 if $patron->category->hidelostitems && !$showallitems; +my $include_lost_items = !$patron->category->hidelostitems || $showallitems; my $items_params = { ( $invalid_marc_record ? () : ( host_items => 1 ) ), }; -my $items = $biblio->items($items_params)->search_ordered( $params, { prefetch => ['issue','current_branchtransfers'] } ); +my $all_items = $biblio->items($items_params); +my $items_to_display = $all_items->search({ $include_lost_items ? () : ( itemlost => 0 ) }); # flag indicating existence of at least one item linked via a host record my $hostrecords = $biblio->host_items->count; my $dat = &GetBiblioData($biblionumber); -$dat->{'count'} = $biblio->items($items_params)->count; -$dat->{'showncount'} = $items->count; -$dat->{'hiddencount'} = $dat->{'count'} - $dat->{'showncount'}; #is biblio a collection and are bundles enabled my $leader = $marc_record->leader(); @@ -321,138 +318,18 @@ if ( defined $dat->{'itemtype'} ) { $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }->imageurl ); } -my (@itemloop, @otheritemloop, %itemfields); - -my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] }); -if ( $mss->count ) { - $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) ); +if ( C4::Context->preference('SeparateHoldings') ) { + my $SeparateHoldingsBranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch'; + my $other_holdings_count = $items_to_display->search({ $SeparateHoldingsBranch => { '!=' => C4::Context->userenv->{branch} } })->count; + $template->param( other_holdings_count => $other_holdings_count ); } -$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] }); -if ( $mss->count ) { - $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) ); -} -$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => { not => undef } }); -if ( $mss->count ) { - $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) ); -} - -$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] }); -my %materials_map; -if ($mss->count) { - my $materials_authvals = GetAuthorisedValues($mss->next->authorised_value); - if ($materials_authvals) { - foreach my $value (@$materials_authvals) { - $materials_map{$value->{authorised_value}} = $value->{lib}; - } - } -} - -my $analytics_flag; -my $materials_flag; # set this if the items have anything in the materials field -my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef; -if ($currentbranch and C4::Context->preference('SeparateHoldings')) { - $template->param(SeparateHoldings => 1); -} -my $separatebranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch'; -my ( $itemloop_has_images, $otheritemloop_has_images ); - -while ( my $item = $items->next ) { - my $itembranchcode = $item->$separatebranch; - - my $item_info = $item->unblessed; - $item_info->{itemtype} = $itemtypes->{$item->effective_itemtype}; - - foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri )) { - $itemfields{$_} = 1 if $item->$_; - } - - # FIXME The following must be Koha::Item->serial - my $serial_item = Koha::Serial::Items->find($item->itemnumber); - if ( $serial_item ) { - my $serial = Koha::Serials->find($serial_item->serialid); - $item_info->{serial} = $serial if $serial; - $itemfields{publisheddate} = 1; - } - - $item_info->{object} = $item; - - # checking for holds - my $holds = $item->current_holds; - if ( my $first_hold = $holds->next ) { - $item_info->{first_hold} = $first_hold; - } - - #item has a host number if its biblio number does not match the current bib - - if ($item->biblionumber ne $biblionumber){ - $item_info->{hostbiblionumber} = $item->biblionumber; - $item_info->{hosttitle} = $item->biblio->title; - } - - - if ( $analyze ) { - # count if item is used in analytical bibliorecords - # The 'countanalytics' flag is only used in the templates if analyze is set - my $countanalytics = GetAnalyticsCount( $item->itemnumber ); - if ($countanalytics > 0){ - $analytics_flag=1; - $item_info->{countanalytics} = $countanalytics; - } - } - - if (defined($item->materials) && $item->materials =~ /\S/){ - $materials_flag = 1; - if (defined $materials_map{ $item->materials }) { - $item_info->{materials} = $materials_map{ $item->materials }; - } - } - - if ( C4::Context->preference('UseCourseReserves') ) { - $item_info->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber ); - } - - $item_info->{can_be_edited} = $patron->can_edit_items_from( $item->homebranch ); - - if ( $item->is_bundle ) { - $item_info->{bundled} = - $item->bundle_items->search( { itemlost => { '!=' => 0 } } ) - ->count; - $item_info->{bundled_lost} = - $item->bundle_items->search( { itemlost => 0 } )->count; - $item_info->{is_bundle} = 1; - } - - if ($item->in_bundle) { - $item_info->{bundle_host} = $item->bundle_host; - } - - if ($currentbranch and C4::Context->preference('SeparateHoldings')) { - if ($itembranchcode and $itembranchcode eq $currentbranch) { - push @itemloop, $item_info; - $itemloop_has_images++ if $item->cover_images->count; - } else { - push @otheritemloop, $item_info; - $otheritemloop_has_images++ if $item->cover_images->count; - } - } else { - push @itemloop, $item_info; - $itemloop_has_images++ if $item->cover_images->count; - } -} - $template->param( - itemloop_has_images => $itemloop_has_images, - otheritemloop_has_images => $otheritemloop_has_images, + count => $all_items->count, # FIXME 'count' is used in catalog-strings.inc + # But it's not a meaningful variable, we should rename it there + all_items_count => $all_items->count, + items_to_display_count => $items_to_display->count, ); -# Display only one tab if one items list is empty -if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { - $template->param(SeparateHoldings => 0); - if (scalar(@itemloop) == 0) { - @itemloop = @otheritemloop; - } -} - my $some_private_shelves = Koha::Virtualshelves->get_some_shelves( { borrowernumber => $borrowernumber, @@ -476,23 +353,12 @@ $template->param( $template->param( MARCNOTES => !$invalid_marc_record ? $biblio->get_marc_notes() : undef, - itemdata_ccode => $itemfields{ccode}, - itemdata_enumchron => $itemfields{enumchron}, - itemdata_uri => $itemfields{uri}, - itemdata_copynumber => $itemfields{copynumber}, - itemdata_stocknumber => $itemfields{stocknumber}, - itemdata_publisheddate => $itemfields{publisheddate}, - volinfo => $itemfields{enumchron}, - itemdata_itemnotes => $itemfields{itemnotes}, - itemdata_nonpublicnotes => $itemfields{itemnotes_nonpublic}, z3950_search_params => C4::Search::z3950_search_args($dat), hostrecords => $hostrecords, - analytics_flag => $analytics_flag, C4::Search::enabled_staff_search_views, - materials => $materials_flag, ); -if (C4::Context->preference("AlternateHoldingsField") && $items->count == 0) { +if (C4::Context->preference("AlternateHoldingsField") && $items_to_display->count == 0) { my $fieldspec = C4::Context->preference("AlternateHoldingsField"); my $subfields = substr $fieldspec, 3; my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' '; @@ -528,8 +394,6 @@ foreach ( keys %{$dat} ) { # method query not found?!?! $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages")); $template->param( - itemloop => \@itemloop, - otheritemloop => \@otheritemloop, biblionumber => $biblionumber, ($analyze? 'analyze':'detailview') =>1, subscriptions => \@subs, @@ -634,7 +498,7 @@ if ( C4::Context->preference('UseCourseReserves') ) { $template->param( course_reserves => $course_reserves ); } -my @libraries = $biblio->items({ host_items => 1 })->get_column('homebranch'); +my @libraries = $biblio->items($items_params)->get_column('homebranch'); my %can_edit_items_from = map { $_ => $patron->can_edit_items_from($_) } @libraries; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index b0d29e87c0..d9851e03c8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -284,16 +284,17 @@
| [% END %] - [% IF Koha.Preference('LocalCoverImages') && ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] - | Cover image | - [% END %] - [% IF ( item_level_itypes ) %]Item type | [% END %] -Current library | -Home library | - [% IF ( itemdata_ccode ) %]Collection | [% END %] - [% IF Koha.Preference('EnableItemGroups') %] -Item group | - [% END %] -Call number | - [% IF volinfo %] -Serial enumeration / chronology | - [% END %] -Status | -Last seen | -Checkouts | -Renewals | -Date accessioned | -Date last borrowed | -Barcode | - [% IF ( itemdata_uri ) %]URL | [% END %] - [% IF ( itemdata_copynumber ) %]Copy number | [% END %] - [% IF ( itemdata_stocknumber ) %]Inventory number | [% END %] - [% IF materials %]Materials specified | [% END %] - [% IF ( itemdata_itemnotes ) %]Public notes | [% END %] - [% IF ( itemdata_nonpublicnotes ) %]Non-public notes | [% END %] - [% IF ( hostrecords ) %]Host records | [% END %] - [% IF ( analyze ) %]Used in | [% END %] - [% IF ( ShowCourseReserves ) %] | Course reserves | [% END %] - [% IF ( SpineLabelShowPrintOnBibDetails ) %]Spine label | [% END %] - [% IF ( CAN_user_editcatalogue_edit_items ) %][% END %] + [% IF (StaffDetailItemSelection) %] | [% END %] + [% IF Koha.Preference('LocalCoverImages') %] + | Cover image | + [% END %] + [% IF ( item_level_itypes ) %]Item type | [% END %] +Current library | +Home library | +Collection | + [% IF Koha.Preference('EnableItemGroups') %] +Item group | + [% END %] +Call number | +Serial enumeration / chronology | +Status | +Last seen | +Checkouts | +Renewals | +Date accessioned | +Date last borrowed | +Barcode | +URL | +Copy number | +Inventory number | +Materials specified | +Public notes | +Non-public notes | + [% IF ( hostrecords ) %]Host records | [% END %] + [% IF ( analyze ) %]Used in | [% END %] + [% IF ( ShowCourseReserves ) %] | Course reserves | [% END %] + [% IF ( SpineLabelShowPrintOnBibDetails ) %]Spine label | [% END %] + [% IF ( CAN_user_editcatalogue_edit_items ) %][% END %] |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| - [% IF item.can_be_edited %] - - [% END %] - | - [% END %] - [% IF Koha.Preference('LocalCoverImages') && ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] -
-
-
-
- |
- [% END %]
-
- [% IF ( item_level_itypes ) %]
-
- [% SET itemtype = item.itemtype %]
- [% IF !noItemTypeImages && itemtype.image_location('intranet') %]
- |
- [% END %]
- [% UNLESS ( singlebranchmode ) %][% Branches.GetName( item.holdingbranch ) | html %] [% END %] | -- [% Branches.GetName(item.homebranch) | html %] - - [%# If permanent location is defined, show description or code and %] - [%# display current location in parentheses. If not, display current location. %] - [%# Note that permanent location is a code, and location may be an authval. %] - [% SET item_location = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.location ) %] - [% IF item.permanent_location %] - [% SET permloc_authval = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.permanent_location ) %] - [% permloc_authval | html %] - [% IF item_location AND item_location != permloc_authval AND item.location != item.permanent_location %] - ([% item_location | html %]) - [% END %] - [% ELSE %] - [% item_location | html %] - [% END %] - - | - [% IF ( itemdata_ccode ) %][% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => item.ccode ) | html %] | [% END %] - [% IF Koha.Preference('EnableItemGroups') %][% item.object.item_group.description | html %] | [% END %] -[% IF ( item.itemcallnumber ) %] [% item.itemcallnumber | html %][% END %] | - [% IF ( volinfo ) %] - [% SET serial = item.serial %] - [% IF itemdata_publisheddate #If there is at least one published date, use it for sorting %] -- [% ELSE %] - | - [% END %] - [% IF ( itemdata_enumchron ) %] - [% IF item.enumchron && serial.serialseq %] - [% item.enumchron | html %] - [% IF ( serial.serialseq && item.enumchron != serial.serialseq ) %] - -- - [% serial.serialseq | html %] - [% END %] - [% ELSIF item.enumchron %] - [% item.enumchron | html %] - [% ELSIF item.serialseq %] - [% serial.serialseq | html %] - [% END %] - [% IF serial.publisheddate %] - ([% serial.publisheddate | $KohaDates %]) - [% END %] - [% END %] - - | - [% END %] -
-
- [% IF item.object.checkout %]
- [% IF item.object.checkout.onsite_checkout %]
- Currently in local use
- [% ELSE %]
- Checked out
- [% END %]
- [% IF item.object.checkout.onsite_checkout %]
- by
- [% ELSE %]
- to
- [% END %]
- [% INCLUDE 'patron-title.inc' patron=item.object.checkout.patron hide_patron_infos_if_needed=1 %]
- : due [% date_due | $KohaDates as_due_date => 1 %]
-
- [% ELSIF ( transfer = item.object.get_transfer ) %]
- [% IF (transfer.datesent) %]
- In transit from [% Branches.GetName( transfer.frombranch ) | html %] to [% Branches.GetName( transfer.tobranch ) | html %] since [% transfer.datesent | $KohaDates %]
- [% ELSE %]
- Transit pending from [% Branches.GetName( transfer.frombranch ) | html %] to [% Branches.GetName( transfer.tobranch ) | html %] since [% transfer.daterequested | $KohaDates %]
- [% END %]
- [% END %]
-
- [% IF ( item.itemlost ) %]
- [% SET itemlost_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.itemlost', authorised_value => item.itemlost ) %]
- [% IF itemlostloop %]
- [% itemlost_description | html %]
- [% ELSE %]
- Unavailable (lost or missing)
- [% END %]
- [% END %]
-
- [% IF ( item.withdrawn ) %]
- [% SET withdrawn_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => item.withdrawn ) %]
- [% IF withdrawn_description %]
- [% withdrawn_description | html %]
- [% ELSE %]
- Withdrawn
- [% END %]
- [% END %]
-
- [% IF ( item.damaged ) %]
- [% SET damaged_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.damaged', authorised_value => item.damaged ) %]
- [% IF damaged_description %]
- [% damaged_description | html %]
- [% ELSE %]
- Damaged
- [% END %]
- [% END %]
-
- [% IF ( item.notforloan || item.itemtype.notforloan ) %]
- Not for loan
- [% SET not_for_loan_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => item.notforloan ) %]
- [% IF not_for_loan_description %]
- ([% not_for_loan_description | html %])
- [% END %]
-
- [% END %]
-
- [% SET hold = item.first_hold %]
- [% IF hold %]
- [% IF hold.waitingdate %]
- Waiting at [% Branches.GetName( hold.branchcode ) | html %][% IF ( hold.desk_id ) %], [% hold.desk.desk_name | html %][% END %] since [% hold.waitingdate | $KohaDates %].
- [% IF canreservefromotherbranches AND ( hold.waitingdate OR hold.priority == 1 ) %]
- Hold for:
- [% INCLUDE 'patron-title.inc' patron=hold.borrower hide_patron_infos_if_needed=1 %]
- [% END %]
- [% ELSE %]
- There is an item level hold on this item (priority = [% hold.priority | html %]).
- [% END %]
- [% END %]
-
- [% IF Koha.Preference('UseRecalls') %]
- [% SET recall = item.object.recall %]
- [% IF recall %]
- [% IF recall.waiting_date %]
- Waiting at [% Branches.GetName( recall.pickup_library_id ) | html %] since [% recall.waiting_date | $KohaDates %]
- [% ELSE %]
- [% patron_link = BLOCK %][% recall.patron.firstname | html %] [% recall.patron.surname | html %] ([% recall.patron.cardnumber | html %])[% END %]
- recalled by [% patron_link| $raw %] on [% recall.created_date | $KohaDates %]
- [% END %]
- [% END %]
- [% END %]
-
- [% UNLESS ( item.notforloan || item.itemtype.notforloan || item.onloan || item.itemlost || item.withdrawn || item.damaged || transfer || hold || ( Koha.Preference('UseRecalls') && recall ) ) %]
- Available
- [% END %]
-
- [% IF ( item.restricted ) %]
- ([% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.restricted', authorised_value => item.restricted ) | html %])
- [% END %]
-
- [% IF ( item.bundle_host ) %]
- In bundle: [% INCLUDE 'biblio-title.inc' biblio = item.bundle_host.biblio link = 1 %]
- [% END %]
-
- |
- [% item.datelastseen | $KohaDates with_hours => 1 %] | -[% item.issues || 0 | html %] | -[% item.renewals || 0 | html %] | -[% item.dateaccessioned | $KohaDates %] | -[% item.datelastborrowed | $KohaDates %] | -[% item.barcode | html %] | - [% IF ( itemdata_uri ) %] - [% IF item.uri.split(' \| ').size > 1 %] -
- [% FOREACH uri IN item.uri.split(' \| ') %][% uri | html %] [% END %] - |
- [% ELSE %]
- - [% IF item.uri %] - [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] - [% END %] - | - [% END %] - [% END %] - [% IF ( itemdata_copynumber ) %] -[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.copynumber', authorised_value => item.copynumber ) | html %] | - [% END %] - [% IF ( itemdata_stocknumber ) %] -[% item.stocknumber | html %] | - [% END %] - [% IF materials %] -[% item.materials | html %] | - [% END %] - [% IF ( itemdata_itemnotes ) %] -[% item.object.itemnotes.replace('\n',' ') | $raw %] |
- [% END %]
- [% IF itemdata_nonpublicnotes %]
- [% item.itemnotes_nonpublic | html %] | - [% END %] - [% IF ( hostrecords ) %] -[% IF ( item.hostbiblionumber) %][% item.hosttitle | html %][% END %] | - [% END %] - [% IF ( analyze ) %] -- [% IF ( item.countanalytics ) %] - [% item.countanalytics | html %] analytics - [% END %] - | - [% END %] - [% IF ( analyze ) %] -Create analytics | - [% END %] - - [% IF ShowCourseReserves %] -- [% IF item.course_reserves %] - [% FOREACH r IN item.course_reserves %] - [% IF r.course.enabled == 'yes' %] - - [% END %] - [% END %] - [% END %] - | - [% END %] - - [% IF ( SpineLabelShowPrintOnBibDetails ) %] -Print label | - [% END %] - - [% IF CAN_user_editcatalogue_edit_items %] -
- [% IF item.can_be_edited %]
- [% IF Koha.Preference('LocalCoverImages') OR Koha.Preference('OPACLocalCoverImages') %]
-
- Edit
-
-
- [% ELSE %]
- Edit
- [% END %]
- [% END %]
- [% IF bundlesEnabled %]
-
- [% END %]
- |
- [% END %]
-
| [% END %] - [% IF Koha.Preference('LocalCoverImages') %] - | Cover image | - [% END %] - [% IF ( item_level_itypes ) %]Item type | [% END %] -Current library | -Home library | -Collection | - [% IF Koha.Preference('EnableItemGroups') %] -Item group | - [% END %] -Call number | -Serial enumeration / chronology | -Status | -Last seen | -Checkouts | -Renewals | -Date accessioned | -Date last borrowed | -Barcode | -URL | -Copy number | -Inventory number | -Materials specified | -Public notes | -Non-public notes | - [% IF ( hostrecords ) %]Host records | [% END %] - [% IF ( analyze ) %]Used in | [% END %] - [% IF ( ShowCourseReserves ) %] | Course reserves | [% END %] - [% IF ( SpineLabelShowPrintOnBibDetails ) %]Spine label | [% END %] - [% IF ( CAN_user_editcatalogue_edit_items ) %][% END %] - - - |
|---|
Show all items ([% hiddencount | html %] hidden) + [% IF hidden_count %] + [%# FIXME We could deal with that in JS and prevent a full refresh %] +
Show all items ([% hidden_count | html %] hidden) [% END %] [% ELSE %] [% IF ( ALTERNATEHOLDINGS ) %] @@ -757,13 +442,9 @@ [% END %] -[% IF (SeparateHoldings) %] +[% IF Koha.Preference('SeparateHoldings') %]