Bugzilla – Attachment 23598 Details for
Bug 10855
Custom fields for subscriptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10855: Search subscriptions by additional fields
Bug-10855-Search-subscriptions-by-additional-field.patch (text/plain), 15.27 KB, created by
Jonathan Druart
on 2013-12-17 12:49:40 UTC
(
hide
)
Description:
Bug 10855: Search subscriptions by additional fields
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-12-17 12:49:40 UTC
Size:
15.27 KB
patch
obsolete
>From 26a094e5716b22b5d33435dd643386adb8f58275 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 29 Aug 2013 13:58:34 +0200 >Subject: [PATCH] Bug 10855: Search subscriptions by additional fields > >Now you will abble to search subscriptions by additional fields. >The additional field values will be displayed in the table results. > >Test plan: >- go on the subscriptions advanced search page > (serials/serials-search.pl). >- verify all searchable additional fields are displayed on the form. >- combine 1 or more values and verify results are consistent. >- verify the values are displayed in new columns of the table. >- for field linked to an authorised value category, the description is > displayed (not the code). >--- > C4/Serials.pm | 33 ++++++++-- > .../prog/en/includes/serials-menu.inc | 1 + > .../prog/en/modules/serials/serials-search.tt | 67 +++++++++++++++++++- > serials/serials-search.pl | 17 +++++ > 4 files changed, 111 insertions(+), 7 deletions(-) > >diff --git a/C4/Serials.pm b/C4/Serials.pm >index e58aaec..47519b1 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -665,7 +665,17 @@ subscription expiration date. > sub SearchSubscriptions { > my ( $args ) = @_; > >- my $query = qq{ >+ my $additional_fields = $args->{additional_fields} // []; >+ my $matching_record_ids_for_additional_fields = []; >+ if ( @$additional_fields ) { >+ $matching_record_ids_for_additional_fields = Koha::AdditionalField->get_matching_record_ids({ >+ fields => $args->{additional_fields}, >+ tablename => 'subscription', >+ }); >+ return () unless @$matching_record_ids_for_additional_fields; >+ } >+ >+ my $query = q| > SELECT > subscription.notes AS publicnotes, > subscription.*, >@@ -679,13 +689,15 @@ sub SearchSubscriptions { > LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber > LEFT JOIN biblioitems ON biblioitems.biblionumber = subscription.biblionumber > LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id >- }; >+ |; >+ $query .= q| WHERE 1|; > my @where_strs; > my @where_args; > if( $args->{biblionumber} ) { > push @where_strs, "biblio.biblionumber = ?"; > push @where_args, $args->{biblionumber}; > } >+ > if( $args->{title} ){ > my @words = split / /, $args->{title}; > my (@strs, @args); >@@ -734,15 +746,20 @@ sub SearchSubscriptions { > push @where_strs, "subscription.closed = ?"; > push @where_args, "$args->{closed}"; > } >+ > if(@where_strs){ >- $query .= " WHERE " . join(" AND ", @where_strs); >+ $query .= ' AND ' . join(' AND ', @where_strs); >+ } >+ if ( @$additional_fields ) { >+ $query .= ' AND subscriptionid IN (' >+ . join( ', ', @$matching_record_ids_for_additional_fields ) >+ . ')'; > } > > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare($query); > $sth->execute(@where_args); >- my $results = $sth->fetchall_arrayref( {} ); >- $sth->finish; >+ my $results = $sth->fetchall_arrayref( {} ); > > for my $subscription ( @$results ) { > $subscription->{cannotedit} = not can_edit_subscription( $subscription ); >@@ -750,6 +767,12 @@ sub SearchSubscriptions { > ( C4::Context->preference("IndependentBranches") && > C4::Context->userenv && > $subscription->{branchcode} ne C4::Context->userenv->{'branch'} ) ? 1 : 0; >+ >+ my $additional_field_values = Koha::AdditionalField->fetch_all_values({ >+ record_id => $subscription->{subscriptionid}, >+ tablename => 'subscription' >+ }); >+ $subscription->{addition_fields} = $additional_field_values->{$subscription->{subscriptionid}}; > } > > return @$results; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc >index b6c4b32..21dff3a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc >@@ -30,4 +30,5 @@ > Manage numbering patterns > </a> > </li> >+ <li><a href="/cgi-bin/koha/serials/add_fields.pl">Add subscription fields</a></li> > </ul> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt >index f570669..ee2fc74 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt >@@ -17,6 +17,7 @@ > [% END %] > var osrlt = $("#osrlt").dataTable($.extend(true, {}, dataTablesDefaults, { > >+ // FIXME sort function of additional_fields! > "aoColumnDefs": [ > { "aTargets": [ -1, -2, -3 ], "bSortable": false, "bSearchable": false }, > ], >@@ -24,6 +25,7 @@ > } ) ); > > var csrlt = $("#csrlt").dataTable($.extend(true, {}, dataTablesDefaults, { >+ // FIXME sort function of additional_fields! > "aoColumnDefs": [ > { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false }, > ], >@@ -118,6 +120,21 @@ > <label for="to">Expires before:</label> > <input type="text" id="to" name="expiration_date_filter" value="[% expiration_date_filter | $KohaDates %]" size="10" maxlength="10" class="datepickerto" /> > </li> >+ [% FOR field IN additional_fields_for_subscription %] >+ <li> >+ <label for="additional_field_[% field.id %]"> [% field.name %]: </label> >+ [% IF field.authorised_value_choices %] >+ <select id="additional_field_[% field.id %]" name="additional_field_[% field.id %]_filter"> >+ <option value="">All</option> >+ [% FOREACH av IN field.authorised_value_choices %] >+ <option value="[% av.authorised_value %]">[% av.lib %]</option> >+ [% END %] >+ </select> >+ [% ELSE %] >+ <input id="additional_field_[% field.id %]" type="text" value="[% additional_fields.${field.name} %]" name="additional_field_[% field.id %]_filter" /> >+ [% END %] >+ </li> >+ [% END %] > </ol> > <input type="hidden" name="searched" value="1" /> > <fieldset class="action"> >@@ -146,6 +163,9 @@ > <th>Location</th> > <th>Call number</th> > <th>Expiration date</th> >+ [% FOR field IN additional_fields_for_subscription %] >+ <th>[% field.name %]</th> >+ [% END %] > [% IF ( routing && CAN_user_serials_routing ) %] > <th>Routing list</th> > [% END %] >@@ -162,6 +182,9 @@ > <td><input type="text" class="filter" data-column_num="4" placeholder="Search location" /></td> > <td><input type="text" class="filter" data-column_num="5" placeholder="Search callnumber" /></td> > <td><input type="text" class="filter" data-column_num="6" placeholder="Search expiration date" /></td> >+ [% FOR field IN additional_fields_for_subscription %] >+ <td><input type="text" class="filter" data-column_num="[% loop.count + 5 %]" placeholder="Search [% field.name %]" /></td> >+ [% END %] > [% IF ( routing && CAN_user_serials_routing ) %]<td></td>[% END %] > <td></td> > <td></td> >@@ -192,6 +215,15 @@ > <td> > [% IF ( subscription.enddate ) %][% subscription.enddate | $KohaDates %][% END %] > </td> >+ [% FOR field IN additional_fields_for_subscription %] >+ [% IF field.authorised_value_category %] >+ <td>[% AuthorisedValues.GetByCode( field.authorised_value_category, subscription.additional_fields.${field.name} ) %]</td> >+ [% ELSE %] >+ <td>[% subscription.additional_fields.${field.name} %]</td> >+ [% END %] >+ [% END %] >+ <td><a href="/cgi-bin/koha/serials/serials-collection.pl?subscriptionid=[% subscription.subscriptionid %]">Issue history</a> >+ </td> > [% IF ( routing && CAN_user_serials_routing ) %] > <td> > [% IF ( subscription.cannotedit ) %] >@@ -206,8 +238,6 @@ > [% END %] > </td> > [% END %] >- <td><a href="/cgi-bin/koha/serials/serials-collection.pl?subscriptionid=[% subscription.subscriptionid %]">Issue history</a> >- </td> > <td> > [% IF ( CAN_user_serials_receive_serials ) %] > <a href="/cgi-bin/koha/serials/serials-edit.pl?subscriptionid=[% subscription.subscriptionid %]&serstatus=1,3,7">Serial receive</a> >@@ -227,6 +257,7 @@ > <div id="closed"> > [% IF closedsubscriptions %] > <table id="csrlt"> >+ <!-- FIXME add additional_fields for closed subs --> > <thead> > <tr> > <th>ISSN</th> >@@ -235,6 +266,9 @@ > <th>Library</th> > <th>Location</th> > <th>Call number</th> >+ [% FOR field IN additional_fields_for_subscription %] >+ <th>[% field.name %]</th> >+ [% END %] > <th> </th> > <th> </th> > </tr> >@@ -247,6 +281,9 @@ > <td><input type="text" class="filter" data-column_num="3" placeholder="Search library" /></td> > <td><input type="text" class="filter" data-column_num="4" placeholder="Search location" /></td> > <td><input type="text" class="filter" data-column_num="5" placeholder="Search callnumber" /></td> >+ [% FOR field IN additional_fields_for_subscription %] >+ <td><input type="text" class="filter" data-column_num="[% loop.count + 5 %]" placeholder="Search [% field.name %]" /></td> >+ [% END %] > <td></td> > <td></td> > </tr> >@@ -276,6 +313,13 @@ > <td> > [% IF ( subscription.callnumber ) %][% subscription.callnumber %][% END %] > </td> >+ [% FOR field IN additional_fields_for_subscription %] >+ [% IF field.authorised_value_category %] >+ <td>[% KohaAuthorisedValues.GetByCode( field.authorised_value_category, subscription.additional_fields.${field.name} ) %]</td> >+ [% ELSE %] >+ <td>[% subscription.additional_fields.${field.name} %]</td> >+ [% END %] >+ [% END %] > <td> > [% UNLESS subscription.cannotedit %] > <a href="/cgi-bin/koha/serials/serials-search.pl?subscriptionid=[% subscription.subscriptionid %]&op=reopen&routing=[% subscription.routing %]&searched=1&title_filter=[% title_filter %]&ISSN_filter=[% ISSN_filter %]&EAN_filter=[% EAN_filter %]&published_filter=[% publisher_filter %]&bookseller_filter=[% bookseller_filter %]&branch_filter=[% branch_filter %]" id="reopensub">Reopen</a> >@@ -374,6 +418,25 @@ > <input type="text" id="to" name="expiration_date_filter" value="[% expiration_date_filter | $KohaDates %]" size="10" maxlength="10" class="datepickerto" /> > </li> > >+ [% FOR field IN additional_fields_for_subscription %] >+ <li> >+ <label for="additional_field_[% field.id %]ID"> [% field.name %]: </label> >+ [% IF field.authorised_value_choices %] >+ <select id="additional_field_[% field.id %]" name="additional_field_[% field.id %]_filter"> >+ <option value="">All</option> >+ [% FOREACH av IN field.authorised_value_choices %] >+ [% IF av.authorised_value == additional_field_filters.${field.name} %] >+ <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option> >+ [% ELSE %] >+ <option value="[% av.authorised_value %]">[% av.lib %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ [% ELSE %] >+ <input id="additional_field_[% field.id %]" type="text" value="[% additional_field_filters.${field.name} %]" name="additional_field_[% field.id %]_filter" /> >+ [% END %] >+ </li> >+ [% END %] > </ol> > <input type="hidden" name="searched" value="1" /> > <fieldset class="action"> >diff --git a/serials/serials-search.pl b/serials/serials-search.pl >index b4e7715..199eee2 100755 >--- a/serials/serials-search.pl >+++ b/serials/serials-search.pl >@@ -33,8 +33,10 @@ use CGI; > use C4::Auth; > use C4::Branch; > use C4::Context; >+use C4::Koha qw( GetAuthorisedValues ); > use C4::Output; > use C4::Serials; >+use Koha::AdditionalField; > > use Koha::DateUtils; > >@@ -75,6 +77,18 @@ if ( $op and $op eq "close" ) { > } > } > >+ >+my $additional_fields = Koha::AdditionalField->all( { table => 'subscription', searchable => 1 } ); >+my $additional_field_filters; >+for my $field ( @$additional_fields ) { >+ if ( my $filter_value = $query->param('additional_field_' . $field->{name} . '_filter') ) { >+ $additional_field_filters->{ $field->{name} } = $filter_value; >+ } >+ if ( $field->{authorised_value_category} ) { >+ $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} ); >+ } >+} >+ > my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef; > my @subscriptions; > if ($searched){ >@@ -88,6 +102,7 @@ if ($searched){ > publisher => $publisher, > bookseller => $bookseller, > branch => $branch, >+ additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}} } keys %$additional_field_filters ], > location => $location, > expiration_date => $expiration_date_dt, > } >@@ -141,6 +156,8 @@ $template->param( > branches_loop => \@branches_loop, > done_searched => $searched, > routing => $routing, >+ additional_field_filters => $additional_field_filters, >+ additional_fields_for_subscription => $additional_fields, > marcflavour => (uc(C4::Context->preference("marcflavour"))) > ); > >-- >1.7.10.4
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 10855
:
20937
|
20938
|
20939
|
20940
|
20941
|
20942
|
20943
|
20944
|
21184
|
21185
|
21186
|
21187
|
21188
|
21189
|
21190
|
21191
|
21663
|
22049
|
22050
|
22051
|
22052
|
22053
|
22054
|
22055
|
22056
|
22057
|
22359
|
22360
|
22600
|
22601
|
22602
|
22603
|
22604
|
22605
|
22606
|
22607
|
22608
|
22616
|
22698
|
22699
|
22700
|
22701
|
22702
|
22703
|
22722
|
22768
|
22769
|
22869
|
23052
|
23053
|
23142
|
23143
|
23301
|
23302
|
23594
|
23595
|
23596
|
23597
|
23598
|
23599
|
23600
|
23601
|
23602
|
23774
|
23775
|
23961
|
23962
|
23963
|
23964
|
24452
|
24453
|
24454
|
24455
|
24456
|
24457
|
24569
|
24570
|
26091
|
26092
|
26093
|
26094
|
26095
|
26096
|
26097
|
26254
|
26255
|
26256
|
26257
|
26258
|
26259
|
26260
|
26276
|
26651
|
26655
|
28929
|
28930
|
28931
|
28932
|
28933
|
28934
|
28935
|
28936
|
28937
|
28938
|
28939
|
28940
|
28941
|
29095
|
29161
|
35211
|
35212
|
35213
|
35214
|
35215
|
35216
|
35217
|
35218
|
35219
|
35220
|
35221
|
35309
|
35310
|
35369
|
35556
|
36359
|
36362
|
36363
|
36364
|
36365
|
36366
|
36367
|
36368
|
36369
|
36370
|
36371
|
36372
|
36373
|
36374
|
38549
|
38550
|
38551
|
38552
|
38553
|
38554
|
38555
|
38556
|
38557
|
38558
|
38559
|
38560
|
38561
|
42296
|
42297
|
42298
|
42299
|
42300
|
42301
|
42302
|
42303
|
42304
|
42305
|
42306
|
42307
|
42308
|
42309
|
42310
|
42332
|
42333
|
43076