Bug 15635: Koha::Patron::Images - Remove GetPatronImage

To retrieve a patron image, we can call Koha::Patron::Images->find or
Koha::Patrons->find->image
Both will return a Koha::Patron::Image object.

Test plan:
1/ From the patron/member module, open all tabs on the left (Checkouts,
detail, fines, etc.)
The image should be correctly displayed.
2/ At the OPAC, on the patron details page (opac-memberentry.pl) the
image should be displayed as well.
3/ Same on the sco module.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-01-21 13:04:09 +00:00 committed by Kyle M Hall
parent 85633155f4
commit 545b64f869
29 changed files with 103 additions and 112 deletions

View File

@ -74,8 +74,6 @@ BEGIN {
&GetSortDetails
&GetTitles
&GetPatronImage
&GetHideLostItemsPreference
&IsMemberBlocked
@ -998,6 +996,7 @@ sub UpdateGuarantees {
$sth->execute($data{'address'},$data{'fax'},$data{'B_city'},$data{'mobile'},$data{'city'},$data{'phone'},$guarantee->{'borrowernumber'});
}
}
=head2 GetPendingIssues
my $issues = &GetPendingIssues(@borrowernumber);
@ -1011,7 +1010,6 @@ The keys include C<biblioitems> fields except marc and marcxml.
=cut
#'
sub GetPendingIssues {
my @borrowernumbers = @_;
@ -1828,26 +1826,6 @@ sub GetTitles {
}
}
=head2 GetPatronImage
my ($imagedata, $dberror) = GetPatronImage($borrowernumber);
Returns the mimetype and binary image data of the image for the patron with the supplied borrowernumber.
=cut
sub GetPatronImage {
my ($borrowernumber) = @_;
warn "Borrowernumber passed to GetPatronImage is $borrowernumber" if $debug;
my $dbh = C4::Context->dbh;
my $query = 'SELECT mimetype, imagefile FROM patronimage WHERE borrowernumber = ?';
my $sth = $dbh->prepare($query);
$sth->execute($borrowernumber);
my $imagedata = $sth->fetchrow_hashref;
warn "Database error!" if $sth->errstr;
return $imagedata, $sth->errstr;
}
=head2 GetHideLostItemsPreference
$hidelostitemspref = &GetHideLostItemsPreference($borrowernumber);

View File

@ -22,6 +22,7 @@ use Modern::Perl;
use Carp;
use Koha::Database;
use Koha::Patron::Images;
use base qw(Koha::Object);
@ -47,6 +48,12 @@ sub guarantor {
return Koha::Patrons->find( $self->guarantorid() );
}
sub image {
my ( $self ) = @_;
return Koha::Patron::Images->find( $self->borrowernumber )
}
=head3 type
=cut

View File

@ -47,6 +47,7 @@ use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
use Koha::DateUtils;
use Koha::Database;
use Koha::Patron::Messages;
use Koha::Patron::Images;
use Date::Calc qw(
Today
@ -637,8 +638,8 @@ $template->param(
relatives_borrowernumbers => \@relatives,
);
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
# get authorised values with type of BOR_NOTES

View File

@ -32,6 +32,7 @@ use C4::Members;
use C4::Branch;
use C4::Accounts;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
my $input=new CGI;
@ -93,8 +94,8 @@ foreach my $accountline ( @{$accts}) {
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if (C4::Context->preference('ExtendedPatronAttributes')) {
my $attributes = GetBorrowerAttributes($borrowernumber);

View File

@ -31,6 +31,7 @@ use C4::Auth;
use C4::Members;
use C4::Branch; # GetBranches
use Module::Load;
use Koha::Patron::Images;
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
load Koha::NorwegianPatronDB, qw( NLMarkForDeletion NLSync );
}
@ -107,8 +108,8 @@ my $data=$sth->fetchrow_hashref;
if ($countissues > 0 or $flags->{'CHARGES'} or $data->{'borrowernumber'} or $deletelocal == 0){
# print $input->header;
my ($picture, $dberror) = GetPatronImage($bor->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
$template->param(borrowernumber => $member,
surname => $bor->{'surname'},

View File

@ -37,6 +37,7 @@ use C4::Members;
use C4::Reserves;
use C4::Letters;
use Koha::Patron::Discharge;
use Koha::Patron::Images;
use Koha::DateUtils;
@ -102,8 +103,8 @@ if ( $input->param('borrowernumber') ) {
borrowernumber => $borrowernumber,
});
my ($picture, $dberror) = GetPatronImage($borrowernumber);
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrowernumber);
$template->param( picture => 1 ) if $patron_image;
$template->param(
borrowernumber => $borrowernumber,

View File

@ -31,6 +31,7 @@ use C4::Debug;
use Koha::DateUtils;
use Koha::Patron::Files;
use Koha::Patron::Images;
my $cgi = CGI->new;
@ -115,8 +116,8 @@ else {
);
}
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
$template->param(
files => Koha::Patron::Files->new( borrowernumber => $borrowernumber )

View File

@ -34,6 +34,7 @@ use C4::Branch;
use C4::Accounts;
use C4::Items;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
my $input=new CGI;
my $flagsrequired = { borrowers => 1, updatecharges => 1 };
@ -80,8 +81,8 @@ if ($add){
}
$template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' );
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if (C4::Context->preference('ExtendedPatronAttributes')) {
my $attributes = GetBorrowerAttributes($borrowernumber);

View File

@ -33,6 +33,7 @@ use C4::Accounts;
use C4::Items;
use C4::Branch;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
my $input=new CGI;
my $flagsrequired = { borrowers => 1 };
@ -106,8 +107,8 @@ if ($add){
}
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if (C4::Context->preference('ExtendedPatronAttributes')) {
my $attributes = GetBorrowerAttributes($borrowernumber);

View File

@ -17,6 +17,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes);
#use C4::Acquisitions;
use C4::Output;
use Koha::Patron::Images;
my $input = new CGI;
@ -157,8 +158,8 @@ if ($input->param('newflags')) {
}
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
my ($picture, $dberror) = GetPatronImage($bor->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if (C4::Context->preference('ExtendedPatronAttributes')) {
my $attributes = GetBorrowerAttributes($bor->{'borrowernumber'});

View File

@ -16,6 +16,7 @@ use C4::Branch;
use C4::Circulation;
use CGI qw ( -utf8 );
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
use Digest::MD5 qw(md5_base64);
@ -100,8 +101,8 @@ if ( $bor->{'category_type'} eq 'C' ) {
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
my ( $picture, $dberror ) = GetPatronImage( $bor->{'borrowernumber'} );
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
my $attributes = GetBorrowerAttributes( $bor->{'borrowernumber'} );

View File

@ -52,6 +52,7 @@ use C4::Form::MessagingPreferences;
use List::MoreUtils qw/uniq/;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
use Koha::Patron::Images;
use Module::Load;
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber );
@ -287,8 +288,8 @@ if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen
# check to see if patron's image exists in the database
# basically this gives us a template var to condition the display of
# patronimage related interface on
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
my $branch=C4::Context->userenv->{'branch'};

View File

@ -28,6 +28,7 @@ use C4::Members;
use C4::Branch;
use C4::Letters;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
my $input=new CGI;
@ -46,8 +47,8 @@ my ($template, $loggedinuser, $cookie)
});
$template->param( $borrower );
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
# Allow resending of messages in Notices tab
my $op = $input->param('op') || q{};

View File

@ -26,6 +26,7 @@ use CGI qw ( -utf8 );
use C4::Auth qw( check_api_auth );
use C4::Context;
use C4::Members;
use Koha::Patron::Images;
$|=1;
@ -65,18 +66,13 @@ if ($query->param('borrowernumber')) {
warn "Borrowernumber passed in: $borrowernumber" if $DEBUG;
my ($imagedata, $dberror) = GetPatronImage($borrowernumber);
if ($dberror) {
warn "Database Error!";
exit;
}
my $patron_image = Koha::Patron::Images->find($borrowernumber);
# NOTE: Never dump the contents of $imagedata->{'patronimage'} via a warn to a log or nasty
# things will result... you have been warned!
if ($imagedata) {
print $query->header (-type => $imagedata->{'mimetype'}, -'Cache-Control' => 'no-store', -Content_Length => length ($imagedata->{'imagefile'})), $imagedata->{'imagefile'};
if ($patron_image) {
print $query->header (-type => $patron_image->mimetype, -'Cache-Control' => 'no-store', -Content_Length => length ($patron_image->imagefile)), $patron_image->imagefile;
exit;
} else {
warn "No image exists for $borrowernumber";

View File

@ -41,6 +41,7 @@ use C4::Koha;
use C4::Overdues;
use C4::Branch;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
our $input = CGI->new;
@ -135,8 +136,8 @@ sub add_accounts_to_template {
$template->param(%$borrower);
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
$template->param(
accounts => $accounts,
borrower => $borrower,
@ -226,11 +227,6 @@ sub borrower_add_additional_fields {
$b_ref->{adultborrower} = 1;
}
my ( $picture, $dberror ) = GetPatronImage( $b_ref->{borrowernumber} );
if ($picture) {
$b_ref->{has_picture} = 1;
}
if (C4::Context->preference('ExtendedPatronAttributes')) {
$b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber);
$template->param(

View File

@ -29,6 +29,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes);
use C4::Accounts;
use C4::Koha;
use C4::Branch;
use Koha::Patron::Images;
my $input = CGI->new();
@ -175,8 +176,8 @@ sub borrower_add_additional_fields {
$b_ref->{adultborrower} = 1;
}
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if (C4::Context->preference('ExtendedPatronAttributes')) {
$b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber);

View File

@ -32,6 +32,7 @@ use C4::Members;
use C4::Branch;
use C4::Accounts;
use Koha::DateUtils;
use Koha::Patron::Images;
my $input=new CGI;
@ -113,8 +114,8 @@ for (my $i=0;$i<$numaccts;$i++){
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
$template->param(
finesview => 1,

View File

@ -30,6 +30,7 @@ use CGI qw ( -utf8 );
use C4::Members;
use C4::Branch;
use C4::Accounts;
use Koha::Patron::Images;
my $input = new CGI;
@ -112,8 +113,8 @@ for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
my ( $picture, $dberror ) = GetPatronImage( $data->{'borrowernumber'} );
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
$template->param(
finesview => 1,

View File

@ -27,6 +27,7 @@ use C4::Branch;
use C4::Members;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use C4::Suggestions;
use Koha::Patron::Images;
my $input = new CGI;
@ -62,8 +63,8 @@ if (C4::Context->preference('ExtendedPatronAttributes')) {
);
}
my ($picture, $dberror) = GetPatronImage($borrowernumber);
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrowernumber);
$template->param( picture => 1 ) if $patron_image;
my $suggestions = SearchSuggestion( { suggestedby => $borrowernumber } );

View File

@ -32,6 +32,7 @@ use C4::Branch qw(GetBranches);
use List::MoreUtils qw/any uniq/;
use Koha::DateUtils;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Patron::Images;
my $input = CGI->new;
@ -107,9 +108,8 @@ if (! $limit){
$limit = 'full';
}
my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if (C4::Context->preference('ExtendedPatronAttributes')) {
my $attributes = GetBorrowerAttributes($borrowernumber);

View File

@ -27,6 +27,7 @@ use C4::Members;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use C4::Context;
use C4::Serials;
use Koha::Patron::Images;
use CGI::Session;
my $query = new CGI;
@ -121,7 +122,7 @@ if (C4::Context->preference('ExtendedPatronAttributes')) {
);
}
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
output_html_with_http_headers $query, $cookie, $template->output;

View File

@ -32,6 +32,7 @@ use C4::Members;
use C4::Members::Statistics;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use C4::Output;
use Koha::Patron::Images;
my $input = new CGI;
@ -93,8 +94,8 @@ if (C4::Context->preference('ExtendedPatronAttributes')) {
);
}
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
$template->param(%$borrower);

View File

@ -31,6 +31,7 @@ use C4::Branch qw(GetBranchesLoop);
use C4::Scrubber;
use Email::Valid;
use Koha::DateUtils;
use Koha::Patron::Images;
my $cgi = new CGI;
my $dbh = C4::Context->dbh;
@ -244,12 +245,8 @@ elsif ( $action eq 'edit' ) { #Display logged in borrower's data
);
if (C4::Context->preference('OPACpatronimages')) {
my ($image, $dberror) = GetPatronImage($borrower->{borrowernumber});
if ($image) {
$template->param(
display_patron_image => 1
);
}
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param( display_patron_image => 1 ) if $patron_image;
}
}

View File

@ -24,6 +24,7 @@ use C4::Members;
use CGI qw ( -utf8 );
use CGI::Cookie; # need to check cookies before having CGI parse the POST request
use C4::Auth qw(:DEFAULT check_cookie_auth);
use Koha::Patron::Images;
my $query = new CGI;
@ -38,16 +39,14 @@ my $sessid = $cookies{'CGISESSID'}->value;
my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags);
my $borrowernumber = C4::Context->userenv->{'number'};
my ($imagedata, $dberror) = GetPatronImage($borrowernumber);
my $patron_image = Koha::Patron::Images->find($borrowernumber);
if ($dberror) {
print $query->header(status => '500 internal error');
}
if ($imagedata) {
print $query->header(-type => $imagedata->{'mimetype'},
-Content_Length => length ($imagedata->{'imagefile'})),
$imagedata->{'imagefile'};
if ($patron_image) {
print $query->header(
-type => $patron_image->mimetype,
-Content_Length => length( $patron_image->imagefile )
),
$patron_image->imagefile;
} else {
print $query->header(status => '404 patron image not found');
}

View File

@ -46,6 +46,7 @@ use C4::Members;
use C4::Biblio;
use C4::Items;
use Koha::Acquisition::Currencies;
use Koha::Patron::Images;
my $query = new CGI;
@ -254,13 +255,11 @@ if ($borrower->{cardnumber}) {
);
if (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) {
my ($image, $dberror) = GetPatronImage($borrower->{borrowernumber});
if ($image) {
$template->param(
display_patron_image => 1,
cardnumber => $borrower->{cardnumber},
);
}
my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
$template->param(
display_patron_image => 1,
cardnumber => $borrower->{cardnumber},
) if $patron_image;
}
} else {
$template->param(

View File

@ -21,6 +21,7 @@ use strict;
use warnings;
use C4::Service;
use C4::Members;
use Koha::Patron::Images;
my ($query, $response) = C4::Service->init(circulate => 'self_checkout');
@ -35,16 +36,14 @@ unless (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) {
my ($borrowernumber) = C4::Service->require_params('borrowernumber');
my ($imagedata, $dberror) = GetPatronImage($borrowernumber);
my $patron_image = Koha::Patron::Images->find($borrowernumber);
if ($dberror) {
print $query->header(status => '500 internal error');
}
if ($imagedata) {
print $query->header(-type => $imagedata->{'mimetype'},
-Content_Length => length ($imagedata->{'imagefile'})),
$imagedata->{'imagefile'};
if ($patron_image) {
print $query->header(
-type => $patron_image->mimetype,
-Content_Length => length( $patron_image->imagefile )
),
$patron_image->imagefile;
} else {
print $query->header(status => '404 patron image not found');
}

View File

@ -29,10 +29,11 @@ use autouse 'Data::Dumper' => qw(Dumper);
use C4::Debug;
use C4::Context;
use autouse 'C4::Members' => qw(GetPatronImage GetMember);
use autouse 'C4::Members' => qw(GetMember);
use C4::Creators;
use C4::Patroncards;
use Koha::List::Patron;
use Koha::Patron::Images;
my $cgi = new CGI;
@ -156,9 +157,9 @@ foreach my $item (@{$items}) {
next PROCESS_IMAGES;
}
elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'patronimages') {
($image_data, $error) = GetPatronImage($borrower_number);
warn sprintf('No image exists for borrower number %s.', $borrower_number) if !$image_data;
next PROCESS_IMAGES if !$image_data;
my $patron_image = Koha::Patron::Images->find($borrower_number);
warn sprintf('No image exists for borrower number %s.', $borrower_number) unless $patron_image;
next PROCESS_IMAGES unless $patron_image;
}
elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'creator_images') {
my $dbh = C4::Context->dbh();

View File

@ -33,6 +33,7 @@ use C4::Debug;
use Koha::Patrons;
use Koha::Patron::Image;
use Koha::Patron::Images;
my $input = new CGI;

View File

@ -31,6 +31,7 @@ use C4::Items;
use C4::Branch;
use C4::Debug;
use C4::Search; # enabled_staff_search_views
use Koha::Patron::Images;
use vars qw($debug $cgi_debug);
@ -73,8 +74,8 @@ if ( $src eq 'circ' ) {
use C4::Members::Attributes qw(GetBorrowerAttributes);
my $borrowernumber = $object;
my $data = GetMember( 'borrowernumber' => $borrowernumber );
my ( $picture, $dberror ) = GetPatronImage( $data->{'borrowernumber'} );
$template->param( picture => 1 ) if $picture;
my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
$template->param( picture => 1 ) if $patron_image;
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
my $attributes = GetBorrowerAttributes( $data->{'borrowernumber'} );