From 662f5625c2a87c9d2c738c7f0c0022fc493288a6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 4 Nov 2016 15:12:53 +0000 Subject: [PATCH] Bug 17556: Koha::Patrons - Remove GetHideLostItemsPreference The subroutine C4::Members::GetHideLostItemsPreference can easily be replaced with Koha::Patron->find(42)->category->hidelostitems Test plan: Create 2 patron categories, 1 with "Lost items in staff client" set to "shown" and another one to "Hidden by default" Create 2 patrons using them On the result search page, the detail page of a record, the item list page and the page to place a hold, make sure the lost items are shown/hidden as expected Signed-off-by: Josef Moravec Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- C4/Members.pm | 21 --------------------- C4/Search.pm | 5 +++-- catalogue/detail.pl | 4 +++- catalogue/moredetail.pl | 5 +++-- reserve/request.pl | 5 ++++- 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 9b44b323a4..57d1fbd2d0 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -72,8 +72,6 @@ BEGIN { &GetAge - &GetHideLostItemsPreference - &GetMemberAccountRecords &GetBorNotifyAcctRecord @@ -1283,25 +1281,6 @@ sub SetAge{ return $borrower; } # sub SetAge -=head2 GetHideLostItemsPreference - - $hidelostitemspref = &GetHideLostItemsPreference($borrowernumber); - -Returns the HideLostItems preference for the patron category of the supplied borrowernumber -C<&$hidelostitemspref>return value of function, 0 or 1 - -=cut - -sub GetHideLostItemsPreference { - my ($borrowernumber) = @_; - my $dbh = C4::Context->dbh; - my $query = "SELECT hidelostitems FROM borrowers,categories WHERE borrowers.categorycode = categories.categorycode AND borrowernumber = ?"; - my $sth = $dbh->prepare($query); - $sth->execute($borrowernumber); - my $hidelostitems = $sth->fetchrow; - return $hidelostitems; -} - =head2 GetBorrowersToExpunge $borrowers = &GetBorrowersToExpunge( diff --git a/C4/Search.pm b/C4/Search.pm index 998e8e3504..4d89d23891 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -26,13 +26,13 @@ use Koha::Libraries; use Lingua::Stem; use C4::Search::PazPar2; use XML::Simple; -use C4::Members qw(GetHideLostItemsPreference); use C4::XSLT; use C4::Reserves; # GetReserveStatus use C4::Debug; use C4::Charset; use Koha::AuthorisedValues; use Koha::Libraries; +use Koha::Patrons; use YAML; use URI::Escape; use Business::ISBN; @@ -2089,7 +2089,8 @@ sub searchResults { # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item my $userenv = C4::Context->userenv; if ( $item->{onloan} - && !( C4::Members::GetHideLostItemsPreference( $userenv->{'number'} ) && $item->{itemlost} ) ) + && $userenv + && !( Koha::Patrons->find($userenv->{number})->category->hidelostitems && $item->{itemlost} ) ) { $onloan_count++; my $key = $prefix . $item->{onloan} . $item->{barcode}; diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 2bf81c2f78..a31a0c5fac 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -42,6 +42,7 @@ use C4::HTML5Media; use C4::CourseReserves qw(GetItemCourseReservesInfo); use C4::Acquisition qw(GetOrdersByBiblionumber); use Koha::AuthorisedValues; +use Koha::Patrons; use Koha::Virtualshelves; my $query = CGI->new(); @@ -132,8 +133,9 @@ my $dbh = C4::Context->dbh; my @all_items = GetItemsInfo( $biblionumber ); my @items; +my $patron = Koha::Patrons->find( $borrowernumber ); for my $itm (@all_items) { - push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems); + push @items, $itm unless ( $itm->{itemlost} && $patron->category->hidelostitems && !$showallitems); } # flag indicating existence of at least one item linked via a host record diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 1d50d504b6..b5b13d5453 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -32,13 +32,13 @@ use C4::Auth; use C4::Serials; use C4::Members; # to use GetMember use C4::Search; # enabled_staff_search_views -use C4::Members qw/GetHideLostItemsPreference/; use C4::Reserves qw(GetReservesFromBiblionumber); use Koha::Acquisition::Bookseller; use Koha::AuthorisedValues; use Koha::DateUtils; use Koha::Items; +use Koha::Patrons; my $query=new CGI; @@ -93,9 +93,10 @@ my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); my $fw = GetFrameworkCode($biblionumber); my @all_items= GetItemsInfo($biblionumber); my @items; +my $patron = Koha::Patrons->find( $loggedinuser ); for my $itm (@all_items) { push @items, $itm unless ( $itm->{itemlost} && - GetHideLostItemsPreference($loggedinuser) && + $patron->category->hidelostitems && !$showallitems && ($itemnumber != $itm->{itemnumber})); } diff --git a/reserve/request.pl b/reserve/request.pl index bc55fdf1d0..3f4dba3c12 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -45,6 +45,7 @@ use C4::Search; # enabled_staff_search_views use Koha::DateUtils; use Koha::Holds; use Koha::Libraries; +use Koha::Patrons; my $dbh = C4::Context->dbh; my $input = new CGI; @@ -201,6 +202,8 @@ $template->param( messageborrower => $messageborrower ); # FIXME launch another time GetMember perhaps until my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold ); +my $logged_in_patron = Koha::Patrons->find( $borrowernumber ); + my $itemdata_enumchron = 0; my @biblioloop = (); foreach my $biblionumber (@biblionumbers) { @@ -412,7 +415,7 @@ foreach my $biblionumber (@biblionumbers) { : $item->{itemlost} == 2 ? "(long overdue)" : ""; $item->{backgroundcolor} = 'other'; - if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) { + if ($logged_in_patron->category->hidelostitems && !$showallitems) { $item->{hide} = 1; $hiddencount++; } -- 2.39.5