Bug 33167: Cleanup staff detail page

This patch begins reduing some of the extra things we are doing in
detail.pl that could easily be handled in the templates - fetching
authorised values and branches etc

It also removes a loop to find items that should be hidden, and instead
uses a searh parameter

The template changes either use item object rather than passed
variables, or utilize plugins to fetch authorised valued

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-03-09 20:37:28 +00:00 committed by Tomas Cohen Arazi
parent aded943792
commit d650f8c2a6
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 45 additions and 103 deletions

View file

@ -190,15 +190,10 @@ $template->param(
); );
my $itemtypes = { map { $_->itemtype => $_ } @{ Koha::ItemTypes->search_with_localization->as_list } }; my $itemtypes = { map { $_->itemtype => $_ } @{ Koha::ItemTypes->search_with_localization->as_list } };
my $all_items = $biblio->items->search_ordered; my $params;
my @items;
my $patron = Koha::Patrons->find( $borrowernumber ); my $patron = Koha::Patrons->find( $borrowernumber );
while ( my $item = $all_items->next ) { $params->{ itemlost } = 0 if $patron->category->hidelostitems && !$showallitems;
push @items, $item my @items = $biblio->items->search_ordered( $params )->as_list;
unless $item->itemlost
&& $patron->category->hidelostitems
&& !$showallitems;
}
# flag indicating existence of at least one item linked via a host record # flag indicating existence of at least one item linked via a host record
my $hostrecords; my $hostrecords;
@ -210,6 +205,9 @@ if ( $hostitems->count ) {
} }
my $dat = &GetBiblioData($biblionumber); my $dat = &GetBiblioData($biblionumber);
$dat->{'count'} = $biblio->items->count + $hostitems->count;
$dat->{'showncount'} = scalar @items;
$dat->{'hiddencount'} = $dat->{'count'} - $dat->{'showncount'};
#is biblio a collection and are bundles enabled #is biblio a collection and are bundles enabled
my $leader = $marc_record->leader(); my $leader = $marc_record->leader();
@ -320,16 +318,6 @@ if ( defined $dat->{'itemtype'} ) {
$dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }->imageurl ); $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }->imageurl );
} }
$dat->{'count'} = $all_items->count + $hostitems->count;
$dat->{'showncount'} = scalar @items + $hostitems->count;
$dat->{'hiddencount'} = $all_items->count + $hostitems->count - scalar @items;
my $shelflocations =
{ map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.location' } ) };
my $collections =
{ map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
my $copynumbers =
{ map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
my (@itemloop, @otheritemloop, %itemfields); my (@itemloop, @otheritemloop, %itemfields);
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] }); my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
@ -371,14 +359,6 @@ foreach my $item (@items) {
my $item_info = $item->unblessed; my $item_info = $item->unblessed;
$item_info->{itemtype} = $itemtypes->{$item->effective_itemtype}; $item_info->{itemtype} = $itemtypes->{$item->effective_itemtype};
#get shelf location and collection code description if they are authorised value.
# same thing for copy number
my $shelfcode = $item->location;
$item_info->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
my $ccode = $item->ccode;
$item_info->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
my $copynumber = $item->copynumber;
$item_info->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri )) { foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri )) {
$itemfields{$_} = 1 if $item->$_; $itemfields{$_} = 1 if $item->$_;
} }
@ -399,21 +379,6 @@ foreach my $item (@items) {
$item_info->{first_hold} = $first_hold; $item_info->{first_hold} = $first_hold;
} }
$item_info->{checkout} = $item->checkout;
# Check the transit status
my $transfer = $item->get_transfer;
if ( $transfer ) {
$item_info->{transfer} = $transfer;
}
foreach my $f (qw( itemnotes )) {
if ($item_info->{$f}) {
$item_info->{$f} =~ s|\n|<br />|g;
$itemfields{$f} = 1;
}
}
#item has a host number if its biblio number does not match the current bib #item has a host number if its biblio number does not match the current bib
if ($item->biblionumber ne $biblionumber){ if ($item->biblionumber ne $biblionumber){
@ -445,23 +410,6 @@ foreach my $item (@items) {
$item_info->{can_be_edited} = $patron->can_edit_items_from( $item->homebranch ); $item_info->{can_be_edited} = $patron->can_edit_items_from( $item->homebranch );
if ( C4::Context->preference("LocalCoverImages") == 1 ) {
$item_info->{cover_images} = $item->cover_images;
}
if ( C4::Context->preference('UseRecalls') ) {
$item_info->{recall} = $item->recall;
}
if ( C4::Context->preference('IndependentBranches') ) {
my $userenv = C4::Context->userenv();
if ( not C4::Context->IsSuperLibrarian()
and $userenv->{branch} ne $item->homebranch ) {
$item_info->{cannot_be_edited} = 1;
$item_info->{not_same_branch} = 1;
}
}
if ( $item->is_bundle ) { if ( $item->is_bundle ) {
$item_info->{bundled} = $item_info->{bundled} =
$item->bundle_items->search( { itemlost => { '!=' => 0 } } ) $item->bundle_items->search( { itemlost => { '!=' => 0 } } )

View file

@ -386,7 +386,7 @@
<td class="cover"> <td class="cover">
<div class="bookcoverimg"> <div class="bookcoverimg">
<div class="cover-slider"> <div class="cover-slider">
[% FOREACH image IN item.cover_images %] [% FOREACH image IN item.object.cover_images %]
<div class="cover-image local-coverimg"> <div class="cover-image local-coverimg">
<a href="/cgi-bin/koha/catalogue/image.pl?itemnumber=[% image.itemnumber | uri %]&amp;imagenumber=[% image.imagenumber | uri %]" title="Local cover image"> <a href="/cgi-bin/koha/catalogue/image.pl?itemnumber=[% image.itemnumber | uri %]&amp;imagenumber=[% image.imagenumber | uri %]" title="Local cover image">
<img src="/cgi-bin/koha/catalogue/image.pl?thumbnail=1&amp;imagenumber=[% image.imagenumber | uri %]" alt="Local cover image" data-link="/cgi-bin/koha/catalogue/imageviewer.pl?itemnumber=[% item.itemnumber | uri %]&amp;imagenumber=[% image.imagenumber | uri %]" /> <img src="/cgi-bin/koha/catalogue/image.pl?thumbnail=1&amp;imagenumber=[% image.imagenumber | uri %]" alt="Local cover image" data-link="/cgi-bin/koha/catalogue/imageviewer.pl?itemnumber=[% item.itemnumber | uri %]&amp;imagenumber=[% image.imagenumber | uri %]" />
@ -411,22 +411,23 @@
<td class="homebranch"> <td class="homebranch">
<span class="homebranchdesc">[% Branches.GetName(item.homebranch) | html %]</span> <span class="homebranchdesc">[% Branches.GetName(item.homebranch) | html %]</span>
<span class="shelvingloc"> <span class="shelvingloc">
<!-- [%# If permanent location is defined, show description or code and
If permanent location is defined, show description or code and display current location in parentheses. If not, display current location. display current location in parentheses. If not, display current location.
Note that permanent location is a code, and location may be an authval. Note that permanent location is a code, and location may be an authval.
--> %]
[% IF item.permanent_location %] [% IF item.permanent_location %]
[% SET permloc_authval = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.permanent_location ) %] [% SET permloc_authval = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.permanent_location ) %]
[% permloc_authval | html %] [% permloc_authval | html %]
[% IF item.location AND item.location != permloc_authval AND item.location != item.permanent_location %] [% SET item_location = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.location ) %]
([% item.location | html %]) [% IF item_location AND item_location != permloc_authval AND item.location != item.permanent_location %]
([% item_location | html %])
[% END %] [% END %]
[% ELSE %] [% ELSE %]
[% item.location | html %] [% item_location | html %]
[% END %] [% END %]
</span> </span>
</td> </td>
[% IF ( itemdata_ccode ) %]<td>[% item.ccode | html %]</td>[% END %] [% IF ( itemdata_ccode ) %]<td>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => item.ccode ) | html %]</td>[% END %]
[% IF Koha.Preference('EnableItemGroups') %]<td class="item_group">[% item.object.item_group.description | html %]</td>[% END %] [% IF Koha.Preference('EnableItemGroups') %]<td class="item_group">[% item.object.item_group.description | html %]</td>[% END %]
<td class="itemcallnumber">[% IF ( item.itemcallnumber ) %] [% item.itemcallnumber | html %][% END %]</td> <td class="itemcallnumber">[% IF ( item.itemcallnumber ) %] [% item.itemcallnumber | html %][% END %]</td>
[% IF ( volinfo ) %] [% IF ( volinfo ) %]
@ -457,62 +458,53 @@ Note that permanent location is a code, and location may be an authval.
[% END %] [% END %]
<td class="status"> <td class="status">
[% IF item.checkout %] [% IF item.object.checkout %]
[% IF item.checkout.onsite_checkout %] [% IF item.object.checkout.onsite_checkout %]
<span>Currently in local use <span>Currently in local use
[% ELSE %] [% ELSE %]
<span class="datedue">Checked out <span class="datedue">Checked out
[% END %] [% END %]
[% UNLESS ( item.not_same_branch) %] [% IF item.can_be_edited %]
[% IF item.checkout.onsite_checkout %] [% IF item.object.checkout.onsite_checkout %]
by by
[% ELSE %] [% ELSE %]
to to
[% END %] [% END %]
[% INCLUDE 'patron-title.inc' patron=item.checkout.patron hide_patron_infos_if_needed=1 %] [% INCLUDE 'patron-title.inc' patron=item.object.checkout.patron hide_patron_infos_if_needed=1 %]
[% END %] [% END %]
: due [% item.checkout.date_due | $KohaDates as_due_date => 1 %] : due [% item.object.checkout.date_due | $KohaDates as_due_date => 1 %]
</span> </span>
[% ELSIF ( item.transfer ) %] [% ELSIF ( transfer = item.object.get_transfer ) %]
[% IF (item.transfer.datesent) %] [% IF (transfer.datesent) %]
<span class="intransit">In transit from [% Branches.GetName( item.transfer.frombranch ) | html %] to [% Branches.GetName( item.transfer.tobranch ) | html %] since [% item.transfer.datesent | $KohaDates %]</span> <span class="intransit">In transit from [% Branches.GetName( transfer.frombranch ) | html %] to [% Branches.GetName( transfer.tobranch ) | html %] since [% transfer.datesent | $KohaDates %]</span>
[% ELSE %] [% ELSE %]
<span class="transitrequested">Transit pending from [% Branches.GetName( item.transfer.frombranch ) | html %] to [% Branches.GetName( item.transfer.tobranch ) | html %] since [% item.transfer.daterequested | $KohaDates %]</span> <span class="transitrequested">Transit pending from [% Branches.GetName( transfer.frombranch ) | html %] to [% Branches.GetName( transfer.tobranch ) | html %] since [% item.transfer.daterequested | $KohaDates %]</span>
[% END %] [% END %]
[% END %] [% END %]
[% IF ( item.itemlost ) %] [% IF ( item.itemlost ) %]
[% SET itemlost_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.itemlost', authorised_value => item.itemlost ) %]
[% IF itemlostloop %] [% IF itemlostloop %]
[% FOREACH itemlostloo IN itemlostloop %] <span class="lost">[% itemlost_description | html %]</span>
[% IF itemlostloo.authorised_value == item.itemlost %]
<span class="lost">[% itemlostloo.lib | html %]</span>
[% END %]
[% END %]
[% ELSE %] [% ELSE %]
<span class="lost">Unavailable (lost or missing)</span> <span class="lost">Unavailable (lost or missing)</span>
[% END %] [% END %]
[% END %] [% END %]
[% IF ( item.withdrawn ) %] [% IF ( item.withdrawn ) %]
[% IF itemwithdrawnloop %] [% SET withdrawn_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => item.withdrawn ) %]
[% FOREACH itemwithdrawnloo IN itemwithdrawnloop %] [% IF withdrawn_description %]
[% IF itemwithdrawnloo.authorised_value == item.withdrawn %] <span class="wdn">[% withdrawn_description | html %]</span>
<span class="wdn">[% itemwithdrawnloo.lib | html %]</span>
[% END %]
[% END %]
[% ELSE %] [% ELSE %]
<span class="wdn">Withdrawn</span> <span class="wdn">Withdrawn</span>
[% END %] [% END %]
[% END %] [% END %]
[% IF ( item.damaged ) %] [% IF ( item.damaged ) %]
[% IF itemdamagedloop %] [% SET damaged_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.damaged', authorised_value => item.damaged ) %]
[% FOREACH itemdamagedloo IN itemdamagedloop %] [% IF damaged_description %]
[% IF itemdamagedloo.authorised_value == item.damaged %] <span class="dmg">[% damaged_description | html %]</span>
<span class="dmg">[% itemdamagedloo.lib | html %]</span>
[% END %]
[% END %]
[% ELSE %] [% ELSE %]
<span class="dmg">Damaged</span> <span class="dmg">Damaged</span>
[% END %] [% END %]
@ -540,13 +532,15 @@ Note that permanent location is a code, and location may be an authval.
[% END %] [% END %]
[% END %] [% END %]
[% SET recall = item.recall %] [% IF Koha.Preference('UseRecalls') %]
[% IF recall %] [% SET recall = item.object.recall %]
[% IF recall.waiting_date %] [% IF recall %]
<span>Waiting at [% Branches.GetName( recall.pickup_library_id ) | html %] since [% recall.waiting_date | $KohaDates %]</span> [% IF recall.waiting_date %]
[% ELSE %] <span>Waiting at [% Branches.GetName( recall.pickup_library_id ) | html %] since [% recall.waiting_date | $KohaDates %]</span>
[% patron_link = BLOCK %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% recall.patron_id | uri %]">[% recall.patron.firstname | html %] [% recall.patron.surname | html %] ([% recall.patron.cardnumber | html %])</a>[% END %] [% ELSE %]
<span>recalled by [% patron_link| $raw %] on [% recall.created_date | $KohaDates %]</span> [% patron_link = BLOCK %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% recall.patron_id | uri %]">[% recall.patron.firstname | html %] [% recall.patron.surname | html %] ([% recall.patron.cardnumber | html %])</a>[% END %]
<span>recalled by [% patron_link| $raw %] on [% recall.created_date | $KohaDates %]</span>
[% END %]
[% END %] [% END %]
[% END %] [% END %]
@ -583,7 +577,7 @@ Note that permanent location is a code, and location may be an authval.
[% END %] [% END %]
[% END %] [% END %]
[% IF ( itemdata_copynumber ) %] [% IF ( itemdata_copynumber ) %]
<td class="copynumber">[% item.copynumber | html %]</td> <td class="copynumber">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.copynumber', authorised_value => item.copynumber ) | html %]</td>
[% END %] [% END %]
[% IF ( itemdata_stocknumber ) %] [% IF ( itemdata_stocknumber ) %]
<td class="stocknumber">[% item.stocknumber | html %]</td> <td class="stocknumber">[% item.stocknumber | html %]</td>
@ -592,7 +586,7 @@ Note that permanent location is a code, and location may be an authval.
<td class="materials"> [% item.materials | html %] </td> <td class="materials"> [% item.materials | html %] </td>
[% END %] [% END %]
[% IF ( itemdata_itemnotes ) %] [% IF ( itemdata_itemnotes ) %]
<td><div class="itemnotes">[% item.itemnotes | $raw %]</div></td> <td><div class="itemnotes">[% item.object.itemnotes.replace('\n','<br />') | $raw %]</div></td>
[% END %] [% END %]
[% IF itemdata_nonpublicnotes %] [% IF itemdata_nonpublicnotes %]
<td class="nonpublicnote">[% item.itemnotes_nonpublic | html %]</td> <td class="nonpublicnote">[% item.itemnotes_nonpublic | html %]</td>