Bug 17556: Koha::Patrons - Remove GetHideLostItemsPreference
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 4 Nov 2016 15:12:53 +0000 (15:12 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 9 Dec 2016 18:53:40 +0000 (18:53 +0000)
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 <josef.moravec@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Members.pm
C4/Search.pm
catalogue/detail.pl
catalogue/moredetail.pl
reserve/request.pl

index 9b44b32..57d1fbd 100644 (file)
@@ -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(
index 998e8e3..4d89d23 100644 (file)
@@ -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};
index 2bf81c2..a31a0c5 100755 (executable)
@@ -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
index 1d50d50..b5b13d5 100755 (executable)
@@ -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}));
 }
index bc55fdf..3f4dba3 100755 (executable)
@@ -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++;
                 }