From e53b5e10edd6be90baf56bcea796bb69593ecac3 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Tue, 15 Sep 2009 11:03:45 +0200 Subject: [PATCH] Adding some fields in GetSubscriptions GetSubscriptions now searches string in notes internalnotes callnumber title --- C4/Serials.pm | 90 ++++++++----------- .../prog/en/includes/serials-search.inc | 2 +- t/db_dependent/Serials.t | 29 ++++++ 3 files changed, 68 insertions(+), 53 deletions(-) create mode 100644 t/db_dependent/Serials.t diff --git a/C4/Serials.pm b/C4/Serials.pm index 5077d83be6..f7e90e0c32 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -619,66 +619,52 @@ a table of hashref. Each hash containt the subscription. =cut sub GetSubscriptions { - my ( $title, $ISSN, $biblionumber ) = @_; + my ( $string, $issn,$biblionumber) = @_; #return unless $title or $ISSN or $biblionumber; my $dbh = C4::Context->dbh; my $sth; - if ($biblionumber) { - my $query = qq( + my $sql = qq( SELECT subscription.*,biblio.title,biblioitems.issn,biblio.biblionumber FROM subscription LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber - WHERE biblio.biblionumber=? - ); - $query.=" ORDER BY title"; - $debug and warn "GetSubscriptions query: $query"; - $sth = $dbh->prepare($query); - $sth->execute($biblionumber); - } - else { - if ( $ISSN and $title ) { - my $query = qq| - SELECT subscription.*,biblio.title,biblioitems.issn,biblio.biblionumber - FROM subscription - LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber - LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber - WHERE (biblioitems.issn = ? or|. join('and ',map{"biblio.title LIKE \"%$_%\""}split (" ",$title))." )"; - $query.=" ORDER BY title"; - $debug and warn "GetSubscriptions query: $query"; - $sth = $dbh->prepare($query); - $sth->execute( $ISSN ); - } - else { - if ($ISSN) { - my $query = qq( - SELECT subscription.*,biblio.title,biblioitems.issn,biblio.biblionumber - FROM subscription - LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber - LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber - WHERE biblioitems.issn LIKE ? - ); - $query.=" ORDER BY title"; - $debug and warn "GetSubscriptions query: $query"; - $sth = $dbh->prepare($query); - $sth->execute( "%" . $ISSN . "%" ); - } - else { - my $query = qq( - SELECT subscription.*,biblio.title,biblioitems.issn,biblio.biblionumber - FROM subscription - LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber - LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber - WHERE 1 - ).($title?" and ":""). join('and ',map{"biblio.title LIKE \"%$_%\""} split (" ",$title) ); - - $query.=" ORDER BY title"; - $debug and warn "GetSubscriptions query: $query"; - $sth = $dbh->prepare($query); - $sth->execute; - } - } + ); + my @bind_params; + my $sqlwhere; + if ($biblionumber) { + $sqlwhere=" WHERE biblio.biblionumber=?"; + push @bind_params,$biblionumber; } + if ($string){ + my @sqlstrings; + my @strings_to_search; + @strings_to_search=map {"%$_%"} split (/ /,$string); + foreach my $index qw(biblio.title subscription.callnumber subscription.location subscription.notes subscription.internalnotes){ + push @bind_params,@strings_to_search; + my $tmpstring= "AND $index LIKE ? "x scalar(@strings_to_search); + $debug && warn "$tmpstring"; + $tmpstring=~s/^AND //; + push @sqlstrings,$tmpstring; + } + $sqlwhere.= ($sqlwhere?" AND ":" WHERE ")."(".join(") OR (",@sqlstrings).")"; + } + if ($issn){ + my @sqlstrings; + my @strings_to_search; + @strings_to_search=map {"%$_%"} split (/ /,$issn); + foreach my $index qw(biblioitems.issn){ + push @bind_params,@strings_to_search; + my $tmpstring= "OR $index LIKE ? "x scalar(@strings_to_search); + $debug && warn "$tmpstring"; + $tmpstring=~s/^OR //; + push @sqlstrings,$tmpstring; + } + $sqlwhere.= ($sqlwhere?" AND ":" WHERE ")."(".join(") OR (",@sqlstrings).")"; + } + $sql.="$sqlwhere ORDER BY title"; + $debug and warn "GetSubscriptions query: $sql params : ", join (" ",@bind_params); + $sth = $dbh->prepare($sql); + $sth->execute(@bind_params); my @results; my $previoustitle = ""; my $odd = 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc index c4ed7bf423..e0e3e150a8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc @@ -3,7 +3,7 @@