Bugzilla – Attachment 168069 Details for
Bug 32742
Add sorting options to patron list export
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32742: Patron's lists option are not in alphabetical
Bug-32742-Patrons-lists-option-are-not-in-alphabet.patch (text/plain), 13.52 KB, created by
Alexandre Noel
on 2024-06-25 13:44:18 UTC
(
hide
)
Description:
Bug 32742: Patron's lists option are not in alphabetical
Filename:
MIME Type:
Creator:
Alexandre Noel
Created:
2024-06-25 13:44:18 UTC
Size:
13.52 KB
patch
obsolete
>From 65f64b4143fb5765cf1ce3d9cc9194b1061adcef Mon Sep 17 00:00:00 2001 >From: Alexandre Noel <alexandre.noel@inlibro.com> >Date: Fri, 21 Jun 2024 07:53:53 -0400 >Subject: [PATCH] Bug 32742: Patron's lists option are not in alphabetical >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch add sorting feature to the patron card lists export option > >To test > >1. Go to Tools > Patron lists >2. Create a new patron list >3. Add 10 patrons in a random order (not in alphabetical nor in cardnumber sequence) >4. Go back to Tools > Patron lists management page >5. Find your list, click on 'Action' and select 'Print patron cards' >6. Check the cards order in the pdf > --> notice these cards aren't in alphabetical order. >7. Apply the patch >8. Repeat step 4, 5 >9. Fill the «Order by» field and submit >10. Check the cards order in the pdf > --> notice the cards are now ordered. > >It's also working for export in Patron card creator page. > >To test > >1. Go to Tools > Patron card creator >2. Create a new patron card batch >3. Add some patrons >4. Test the "Order by" option for different export button > 5. In an export form, Select the "Order by" field and submit > 6. Check that it's ordered > >Export buttons : >--> manage > card batches (or /cgi-bin/koha/patroncards/manage.pl?card_element=batch) > > Export (from the table) > > Select few batches > Export selected batches > > Export from patron list >--> Click "Edit" of your batch in the table > > Export card batch > > Export (from a row of the patrons table) note that this export > doesn't need the order by option. > > Select few patrons > Export selected card(s) >--- > .../prog/en/modules/patroncards/print.tt | 29 ++++---- > patroncards/create-pdf.pl | 71 ++++++++++++------- > patroncards/print.pl | 30 ++++---- > 3 files changed, 73 insertions(+), 57 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt >index 545a05879b..7a6f2edf1f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/print.tt >@@ -23,17 +23,17 @@ > [% IF ( batche.label_ids ) %] > <legend>[% batche.card_count | html %] Single patron cards</legend> > <p> >- <a class="document pdf" href="/cgi-bin/koha/patroncards/[% batche.create_script | html %]?batch_id=[% batche.batch_id | html %]&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]]&layout_back_id=[% batche.layout_back_id | html %]&start_card=[% batche.start_card | html %][% batche.label_ids | html %]">label_single_[% batche.card_count | html %].pdf</a> >+ <a class="document pdf" href="/cgi-bin/koha/patroncards/[% batche.create_script | html %]?batch_id=[% batche.batch_id | html %]&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]]&layout_back_id=[% batche.layout_back_id | html %]&start_card=[% batche.start_card | html %][% batche.label_ids | html %]&order_by=[% order_by | html %]">label_single_[% batche.card_count | html %].pdf</a> > </p> > [% ELSIF ( batche.borrower_numbers ) %] > <legend>[% batche.card_count | html %] Single patron cards</legend> > <p> >- <a class="document pdf" href="/cgi-bin/koha/patroncards/[% batche.create_script | html %]?template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&layout_back_id=[% batche.layout_back_id | html %]&start_card=[% batche.start_card | html %][% batche.borrower_numbers | html %]">label_single_[% batche.card_count | html %].pdf</a> >+ <a class="document pdf" href="/cgi-bin/koha/patroncards/[% batche.create_script | html %]?template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&layout_back_id=[% batche.layout_back_id | html %]&start_card=[% batche.start_card | html %][% batche.borrower_numbers | html %]&order_by=[% order_by | html %]">label_single_[% batche.card_count | html %].pdf</a> > </p> > [% ELSE %] > <legend>Card batch number [% batche.batch_id | html %]</legend> > <p> >- <a class="document pdf" href="/cgi-bin/koha/patroncards/create-pdf.pl?batch_id=[% batche.batch_id | html %]&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&layout_back_id=[% batche.layout_back_id | html %]&start_card=[% batche.start_card | html %]">label_batch_[% batche.batch_id | html %].pdf</a> >+ <a class="document pdf" href="/cgi-bin/koha/patroncards/create-pdf.pl?batch_id=[% batche.batch_id | html %]&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&layout_back_id=[% batche.layout_back_id | html %]&start_card=[% batche.start_card | html %]&order_by=[% order_by | html %]">label_batch_[% batche.batch_id | html %].pdf</a> > </p> > [% END %] > [% END %] >@@ -77,17 +77,6 @@ > [% IF (patronlist_id) %] <input type="hidden" name="patronlist_id" value="[% patronlist_id | html %]" /> [% END %] > <fieldset class="rows"> > <ol> >- [% IF (patronlist_id) %] >- <li> >- <label style="width:9em" for="order_by">Order by: </label> >- <select name="order_by" id="order_by"> >- <option value=""></option> >- <option value="cardnumber">Card number</option> >- <option value="firstname">First name</option> >- <option value="surname">Surname</option> >- </select> >- </li> >- [% END %] > <li> > <label style="width:9em" for="template_id">Select a template to be applied: </label> > <select name="template_id" id="template_id"> >@@ -114,7 +103,17 @@ > </select> > <span class="hint">Used for duplex printers (needs a '1 up template')</span> > </li> >- >+ [% IF ( card_count != 1 ) %] >+ <li> >+ <label style="width:9em" for="order_by">Order by: </label> >+ <select name="order_by" id="order_by"> >+ <option value=""></option> >+ <option value="cardnumber">Card number</option> >+ <option value="firstname">First name</option> >+ <option value="surname">Surname</option> >+ </select> >+ </li> >+ [% END %] > <li> > <label style="width:9em" for="start_card">Enter starting card position: </label> > <input type="text" size="5" id="start_card" name="start_card" class="focus" title="Starting card number" value="1" /> >diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl >index 5e86deac45..9aed0ab022 100755 >--- a/patroncards/create-pdf.pl >+++ b/patroncards/create-pdf.pl >@@ -81,33 +81,50 @@ my $upper_right_y = $pc_template->get_attr('page_height'); > $pdf->Compress(1); # comment this out to debug pdf files, but be sure to uncomment it in production or you may be very sorry... > $pdf->Mbox($lower_left_x, $lower_left_y, $upper_right_x, $upper_right_y); > >-my ($llx, $lly) = 0,0; >-(undef, undef, $llx, $lly) = $pc_template->get_label_position($start_card); >- >-if (@label_ids) { >- my $batch_items = $batch->get_attr('items'); >- grep { >- my $label_id = $_; >- push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items}); >- } @label_ids; >-} >-elsif (@borrower_numbers) { >- grep { >- push(@{$items}, {borrower_number => $_}); >- } @borrower_numbers; >-} >-elsif ( $patronlist_id ) { >- my ($list) = GetPatronLists( { patron_list_id => $patronlist_id } ); >- my @borrowerlist = $list->patron_list_patrons()->search_related('borrowernumber') >- ->get_column('borrowernumber')->all(); >- @borrowerlist = map { $_->borrowernumber } Koha::Patrons->search( {borrowernumber => { -in => \@borrowerlist }}, { order_by => [$order_by]} )->as_list if($order_by); >- grep { >- push(@{$items}, {borrower_number => $_}); >- } @borrowerlist; >-} >-else { >- $items = $batch->get_attr('items'); >-} >+ my ( $llx, $lly ) = 0, 0; >+ ( undef, undef, $llx, $lly ) = $pc_template->get_label_position($start_card); >+ >+ # sort the borrower list by the order_by field >+ sub sort_borrowerlist { >+ my ( $list, $order_by ) = @_; # $list is a reference to an array of borrower numbers >+ my @borrower_list = @$list; >+ if ($order_by) { >+ @borrower_list = >+ map { $_->borrowernumber } >+ Koha::Patrons->search( { borrowernumber => { -in => \@borrower_list } }, { order_by => [$order_by] } ) >+ ->as_list; >+ } >+ return @borrower_list; >+ } >+ >+ if (@label_ids) { >+ my $batch_items = $batch->get_attr('items'); >+ my @selected_borrower; >+ grep { >+ my $label_id = $_; >+ push( @selected_borrower, grep { $_->{'label_id'} == $label_id; } @{$batch_items} ); >+ } @label_ids; >+ @selected_borrower = map { $_->{borrower_number} } @selected_borrower; >+ @selected_borrower = sort_borrowerlist( \@selected_borrower, $order_by ) if ($order_by); >+ grep { push( @{$items}, { borrower_number => $_ } ); } @selected_borrower; >+ } elsif (@borrower_numbers) { >+ @borrower_numbers = sort_borrowerlist( \@borrower_numbers, $order_by ) if ($order_by); >+ grep { push( @{$items}, { borrower_number => $_ } ); } @borrower_numbers; >+ } elsif ($patronlist_id) { >+ my ($list) = GetPatronLists( { patron_list_id => $patronlist_id } ); >+ my @borrowerlist = >+ $list->patron_list_patrons()->search_related('borrowernumber')->get_column('borrowernumber')->all(); >+ @borrowerlist = sort_borrowerlist( \@borrowerlist, $order_by ) if ($order_by); >+ grep { push( @{$items}, { borrower_number => $_ } ); } @borrowerlist; >+ } elsif ($batch_id) { >+ $items = $batch->get_attr('items'); >+ my @borrowerlist = map { $_->{'borrower_number'} } @{$items}; >+ @borrowerlist = sort_borrowerlist( \@borrowerlist, $order_by ) if ($order_by); >+ @{$items} = map { { borrower_number => $_ } } @borrowerlist; >+ >+ } else { >+ $items = $batch->get_attr('items'); >+ } > > my $layout_xml = XMLin($layout->get_attr('layout_xml'), ForceArray => 1); > my $layout_back_xml = defined $layout_back ? XMLin($layout_back->get_attr('layout_xml'), ForceArray => 1) : undef; >diff --git a/patroncards/print.pl b/patroncards/print.pl >index 8efbe6dca5..356f9d814b 100755 >--- a/patroncards/print.pl >+++ b/patroncards/print.pl >@@ -71,11 +71,11 @@ if ($op eq 'cud-export') { #FIXME Seems like a GET operation? > card_count => scalar(@label_ids), > }); > $template->param( >- batches => \@batches, >- referer => $referer, >- ); >- } >- elsif (@borrower_numbers) { >+ batches => \@batches, >+ referer => $referer, >+ order_by => $order_by, >+ ); >+ } elsif (@borrower_numbers) { > my $borrower_number_param = '&borrower_number='; > $borrower_number_param .= join ('&borrower_number=',@borrower_numbers); > push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'), #FIXME csv not supported, no script? >@@ -87,11 +87,11 @@ if ($op eq 'cud-export') { #FIXME Seems like a GET operation? > card_count => scalar(@borrower_numbers), > }); > $template->param( >- batches => \@batches, >- referer => $referer, >- ); >- } >- elsif (@batch_ids) { >+ batches => \@batches, >+ referer => $referer, >+ order_by => $order_by, >+ ); >+ } elsif (@batch_ids) { > foreach my $batch_id (@batch_ids) { > push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'), #FIXME csv not supported, no script? > batch_id => $batch_id, >@@ -102,11 +102,11 @@ if ($op eq 'cud-export') { #FIXME Seems like a GET operation? > }); > } > $template->param( >- batches => \@batches, >- referer => $referer, >- ); >- } >- elsif ($patronlist_id ) { >+ batches => \@batches, >+ referer => $referer, >+ order_by => $order_by, >+ ); >+ } elsif ($patronlist_id) { > $template->param( > patronlist_id => $patronlist_id, > template_id => $template_id, >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32742
:
155468
|
155469
|
155572
|
167956
|
168069
|
170786
|
170787
|
170882
|
170883
|
170884
|
170916
|
170917
|
170918
|
176400
|
176401
|
176402