@@ -, +, @@ items but that the title is now just text instead of a hyperlink. --- C4/Members.pm | 54 +++++++++++++--------- Koha/BiblioItem.pm | 8 ++++ Koha/Config/SysPref.pm | 5 +- Koha/Patron.pm | 52 +++++++++++++++++++++ installer/data/mysql/atomicupdate/bug_8483.sql | 1 + installer/data/mysql/kohastructure.sql | 4 +- .../prog/en/modules/members/readingrec.tt | 8 +++- 7 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_8483.sql --- a/C4/Members.pm +++ a/C4/Members.pm @@ -36,6 +36,7 @@ use C4::NewsChannels; #get slip news use DateTime; use Koha::Database; use Koha::DateUtils; +use Koha::Patrons; use Koha::Patron::Debarments qw(IsDebarred); use Text::Unaccent qw( unac_string ); use Koha::AuthUtils qw(hash_password); @@ -998,31 +999,42 @@ sub GetAllIssues { my ( $borrowernumber, $order, $limit ) = @_; return unless $borrowernumber; + $order = 'date_due desc' unless $order; + my ( $column, $sort ) = split( / /, $order ); + $column ||= 'date_due'; + $sort ||= 'desc'; - my $dbh = C4::Context->dbh; - my $query = -'SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp - FROM issues - LEFT JOIN items on items.itemnumber=issues.itemnumber - LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber - LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber - WHERE borrowernumber=? - UNION ALL - SELECT *, old_issues.timestamp as issuestimestamp, old_issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp - FROM old_issues - LEFT JOIN items on items.itemnumber=old_issues.itemnumber - LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber - LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber - WHERE borrowernumber=? AND old_issues.itemnumber IS NOT NULL - order by ' . $order; - if ($limit) { - $query .= " limit $limit"; + my $borrower = Koha::Patrons->find( $borrowernumber ); + my $checkouts = $borrower->all_checkouts( { order => { column => $column, sort => $sort } , limit => $limit } ); + + my @results; + foreach my $checkout (@$checkouts) { + my $item = $checkout->item( { deleted => 1 } ); + next unless $item; + + my $biblio = $item->biblio( { deleted => 1 } ); + next unless $biblio; + + my $biblioitem = $item->biblioitem( { deleted => 1 } ); + next unless $biblioitem; + + my $checkout_hashref = $checkout->unblessed(); + my $item_hashref = $item->unblessed(); + my $biblio_hashref = $biblio->unblessed(); + my $biblioitem_hashref = $biblioitem->unblessed(); + + my $hashref = { %$checkout_hashref, %$item_hashref, %$biblio_hashref, %$biblioitem_hashref }; + $hashref->{issuestimestamp} = $checkout->timestamp(); + $hashref->{renewals} = $checkout->renewals(); + $hashref->{totalrenewals} = $item->renewals(); + $hashref->{itemstimestamp} = $item->timestamp(); + $hashref->{record_is_deleted} = ref($biblio) eq 'Koha::Deleted::Biblio'; + + push( @results, $hashref ); } - my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $borrowernumber ); - return $sth->fetchall_arrayref( {} ); + return \@results; } --- a/Koha/BiblioItem.pm +++ a/Koha/BiblioItem.pm @@ -1,5 +1,7 @@ package Koha::BiblioItem; +# Copyright ByWater Solutions 2015 +# # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the @@ -41,4 +43,10 @@ sub _type { return 'Biblioitem'; } +=head1 AUTHOR + +Kyle M Hall + +=cut + 1; --- a/Koha/Config/SysPref.pm +++ a/Koha/Config/SysPref.pm @@ -23,6 +23,9 @@ use Carp; use Koha::Database; +use Koha::Checkouts; +use Koha::Old::Checkouts; + use base qw(Koha::Object); =head1 NAME @@ -35,7 +38,7 @@ Koha::Config::SysPref - Koha System Preference Object class =cut -=head3 type +=head3 _type =cut --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -94,6 +94,58 @@ sub siblings { ); } +=head3 all_checkouts + +=cut + +sub all_checkouts { + my ( $self, $params ) = @_; + + my $limit = $params->{limit}; + + my $order_by_column = $params->{order} ? $params->{order}->{column} : 'date_due'; + my $order_by_sort = $params->{order} ? $params->{order}->{sort} : 'desc'; + + my @results; + my $results_found = 0; + + my $issues = Koha::Checkouts->search( + { + borrowernumber => $self->borrowernumber(), + }, + { + order_by => { "-$order_by_sort" => $order_by_column } + } + ); + + while ( my $i = $issues->next() ) { + push( @results, $i ); + $results_found++; + last if ( $limit && $results_found >= $limit ); + } + + if ( !$limit || $results_found < $limit ) { + + $issues = Koha::Old::Checkouts->search( + { + borrowernumber => $self->borrowernumber(), + }, + { + order_by => { "-$order_by_sort" => $order_by_column } + } + ); + + while ( my $i = $issues->next() ) { + push( @results, $i ); + $results_found++; + last if ( $limit && $results_found >= $limit ); + } + + } + + return wantarray ? @results : \@results; +} + =head3 type =cut --- a/installer/data/mysql/atomicupdate/bug_8483.sql +++ a/installer/data/mysql/atomicupdate/bug_8483.sql @@ -0,0 +1, @@ +ALTER TABLE `old_issues` DROP FOREIGN KEY `old_issues_ibfk_2` ; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1176,7 +1176,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues KEY `branchcode_idx` (`branchcode`), KEY `bordate` (`borrowernumber`,`timestamp`), CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE + CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE, ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- @@ -1675,8 +1675,6 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r KEY `branchcode_idx` (`branchcode`), KEY `old_bordate` (`borrowernumber`,`timestamp`), CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) - ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -97,7 +97,13 @@ [% issue.issuestimestamp | $KohaDates with_hours => 1 %] - [% issue.title |html %] + + [% IF issue.record_is_deleted %] + [% issue.title |html %] + [% ELSE %] + [% issue.title |html %] + [% END %] + [% issue.author %] --