From e0c43b5825b71163151f512ac0c7a94a5dcd6d36 Mon Sep 17 00:00:00 2001 From: Jonathan Druart 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). Signed-off-by: Brendan Gallagher Signed-off-by: Tomas Cohen Arazi --- C4/Serials.pm | 33 ++++++++-- .../prog/en/includes/serials-menu.inc | 1 + .../prog/en/modules/serials/serials-search.tt | 63 +++++++++++++++++++ serials/serials-search.pl | 17 +++++ 4 files changed, 109 insertions(+), 5 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 03362fc951..e078344e2a 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -558,7 +558,17 @@ subscription expiration date. sub SearchSubscriptions { my ( $args ) = @_; - my $query = q{ + 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, subscriptionhistory.*, @@ -573,13 +583,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); @@ -628,8 +640,14 @@ 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 ) + . ')'; } $query .= " ORDER BY " . $args->{orderby} if $args->{orderby}; @@ -637,12 +655,17 @@ sub SearchSubscriptions { 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 ); $subscription->{cannotdisplay} = not can_show_subscription( $subscription ); + + 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 b6c4b323c5..21dff3aa99 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 +
  • Add subscription fields
  • 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 3b97849d93..31eea9afbc 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 @@ -20,6 +20,7 @@ } ) ); var csrlt = $("#csrlt").dataTable($.extend(true, {}, dataTablesDefaults, { + // FIXME sort function of additional_fields! "sPaginationType": "four_button", "aoColumnDefs": [ { 'bSortable': false, 'aTargets': [ 'NoSort' ] }, @@ -116,6 +117,21 @@ + [% FOR field IN additional_fields_for_subscription %] +
  • + + [% IF field.authorised_value_choices %] + + [% ELSE %] + + [% END %] +
  • + [% END %]
    @@ -144,6 +160,9 @@ Location Call number Expiration date + [% FOR field IN additional_fields_for_subscription %] + [% field.name %] + [% END %] Actions @@ -156,6 +175,9 @@ + [% FOR field IN additional_fields_for_subscription %] + + [% END %] @@ -189,6 +211,14 @@ [% END %] + [% FOR field IN additional_fields_for_subscription %] + [% IF field.authorised_value_category %] + [% AuthorisedValues.GetByCode( field.authorised_value_category, subscription.additional_fields.${field.name} ) %] + [% ELSE %] + [% subscription.additional_fields.${field.name} %] + [% END %] + [% END %] +