From c5c83ed8d7235a773617688d088d74c88ce5c05d Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 15 Feb 2010 17:03:33 +0100 Subject: [PATCH] (MT #2920) fix reading record scripts This patch fix some perl ugly code to be more readable and lesser complex. And it allow in intranet to order by issues.timestamp. Signed-off-by: Galen Charlton --- C4/Members.pm | 16 +++----- .../prog/en/modules/members/readingrec.tmpl | 18 +++++---- members/readingrec.pl | 40 +++++++++++++------ opac/opac-readingrecord.pl | 24 ++++++++--- 4 files changed, 61 insertions(+), 37 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index b9391a9416..6878d2fd47 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1040,16 +1040,15 @@ sub GetAllIssues { #FIXME: sanity-check order and limit my $dbh = C4::Context->dbh; - my $count = 0; my $query = - "SELECT *,issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp + "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.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp + 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 @@ -1066,9 +1065,7 @@ sub GetAllIssues { my @result; my $i = 0; while ( my $data = $sth->fetchrow_hashref ) { - $result[$i] = $data; - $i++; - $count++; + push @result, $data; } # get all issued items for borrowernumber from oldissues table @@ -1086,7 +1083,7 @@ sub GetAllIssues { WHERE borrowernumber=? ORDER BY $order"; if ( $limit != 0 ) { - $limit = $limit - $count; + $limit = $limit - scalar(@result); $query2 .= " limit $limit"; } @@ -1094,12 +1091,11 @@ sub GetAllIssues { $sth2->execute($borrowernumber); while ( my $data2 = $sth2->fetchrow_hashref ) { - $result[$i] = $data2; - $i++; + push @result, $data2; } } - return ( $i, \@result ); + return \@result; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tmpl index 66ad408125..13e954679d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tmpl @@ -21,6 +21,9 @@ &limit=full">Show All Items

+ @@ -42,21 +45,20 @@ - - + - + - + - + diff --git a/members/readingrec.pl b/members/readingrec.pl index 076b1a4325..b899ac17f9 100755 --- a/members/readingrec.pl +++ b/members/readingrec.pl @@ -29,6 +29,8 @@ use C4::Auth; use C4::Output; use C4::Members; use C4::Branch; +use List::MoreUtils qw/any/; + use C4::Dates qw/format_date/; my $input = CGI->new; @@ -54,6 +56,17 @@ if ($order2 eq ''){ $order2="date_due desc"; } my $limit=$input->param('limit'); +======= +my $borrowernumber = $input->param('borrowernumber'); +my $limit = $input->param('limit'); +my $order = $input->param('order') || ''; + +$order = "issuestimestamp desc" if not any { $order =~ $_ } ('issuestimestamp', 'title', 'author', 'returndate'); + +#get borrower details +my $data=GetMember('borrowernumber'=>$borrowernumber); + +>>>>>>> (MT #2920) fix reading record scripts:members/readingrec.pl if ($limit){ if ($limit eq 'full'){ @@ -63,7 +76,7 @@ if ($limit){ else { $limit=50; } -my ($count,$issues)=GetAllIssues($borrowernumber,$order2,$limit); +my ( $issues ) = GetAllIssues($borrowernumber,$order,$limit); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "members/readingrec.tmpl", @@ -76,18 +89,19 @@ my ($template, $loggedinuser, $cookie) my @loop_reading; -for (my $i=0;$i<$count;$i++){ +foreach my $issue (@{$issues}){ my %line; - $line{biblionumber}=$issues->[$i]->{'biblionumber'}; - $line{title}=$issues->[$i]->{'title'}; - $line{author}=$issues->[$i]->{'author'}; - $line{classification} = $issues->[$i]->{'classification'} || $issues->[$i]->{'itemcallnumber'}; - $line{date_due}=format_date($issues->[$i]->{'date_due'}); - $line{returndate}=format_date($issues->[$i]->{'returndate'}); - $line{issuedate}=format_date($issues->[$i]->{'issuedate'}); - $line{renewals}=$issues->[$i]->{'renewals'}; - $line{barcode}=$issues->[$i]->{'barcode'}; - $line{volumeddesc}=$issues->[$i]->{'volumeddesc'}; + $line{issuestimestamp} = format_date($issue->{'issuestimestamp'}); + $line{biblionumber} = $issue->{'biblionumber'}; + $line{title} = $issue->{'title'}; + $line{author} = $issue->{'author'}; + $line{classification} = $issue->{'classification'} || $issue->{'itemcallnumber'}; + $line{date_due} = format_date($issue->{'date_due'}); + $line{returndate} = format_date($issue->{'returndate'}); + $line{issuedate} = format_date($issue->{'issuedate'}); + $line{renewals} = $issue->{'renewals'}; + $line{barcode} = $issue->{'barcode'}; + $line{volumeddesc} = $issue->{'volumeddesc'}; push(@loop_reading,\%line); } @@ -130,7 +144,7 @@ $template->param( branchcode => $data->{'branchcode'}, is_child => ($data->{'category_type'} eq 'C'), branchname => GetBranchName($data->{'branchcode'}), - showfulllink => ($count > 50), + showfulllink => (scalar @loop_reading > 50), loop_reading => \@loop_reading); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index b09a78b9c7..21a90b61ef 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -72,7 +72,7 @@ else { $limit = 50; } -my ( $count, $issues ) = GetAllIssues( $borrowernumber, $order, $limit ); +my ( $issues ) = GetAllIssues( $borrowernumber, $order, $limit ); my @bordat; $bordat[0] = $borr; @@ -80,14 +80,15 @@ $template->param( BORROWER_INFO => \@bordat ); my @loop_reading; -for ( my $i = 0 ; $i < $count ; $i++ ) { +foreach my $issue (@{$issues} ) { my %line; my $record = GetMarcBiblio($issues->[$i]->{'biblionumber'}); # XISBN Stuff - my $isbn = GetNormalizedISBN($issues->[$i]->{'isbn'}); + my $isbn = GetNormalizedISBN($issue->{'isbn'}); $line{normalized_isbn} = $isbn; +<<<<<<< HEAD:opac/opac-readingrecord.pl $line{biblionumber} = $issues->[$i]->{'biblionumber'}; $line{title} = $issues->[$i]->{'title'}; $line{author} = $issues->[$i]->{'author'}; @@ -100,6 +101,17 @@ for ( my $i = 0 ; $i < $count ; $i++ ) { $line{'itypedescription'} = $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'description'}; $line{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'imageurl'} ); } +======= + $line{biblionumber} = $issue->{'biblionumber'}; + $line{title} = $issue->{'title'}; + $line{author} = $issue->{'author'}; + $line{itemcallnumber} = $issue->{'itemcallnumber'}; + $line{date_due} = format_date( $issue->{'date_due'} ); + $line{returndate} = format_date( $issue->{'returndate'} ); + $line{volumeddesc} = $issue->{'volumeddesc'}; + $line{'description'} = $itemtypes->{ $issue->{'itemtype'} }->{'description'}; + $line{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $issue->{'itemtype'} }->{'imageurl'} ); +>>>>>>> (MT #2920) fix reading record scripts:opac/opac-readingrecord.pl push( @loop_reading, \%line ); $line{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($issues->[$i]->{'biblionumber'})); } @@ -128,11 +140,11 @@ for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above } $template->param( - count => $count, READING_RECORD => \@loop_reading, limit => $limit, showfulllink => 1, - readingrecview => 1 + readingrecview => 1, + count => scalar @loop_reading, ); -output_html_with_http_headers $query, $cookie, $template->output; \ No newline at end of file +output_html_with_http_headers $query, $cookie, $template->output; -- 2.39.5
+ &order=issuestimestamp&limit=">Date + &order=title&limit=">Title
+ + + "> - - -