From 4428d086575cf2df94261f33b89b37150b4215f9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Jul 2018 20:34:42 -0300 Subject: [PATCH] Bug 20443: Remove SearchIdMatchingAttribute - prove we are not cheating Tests are still passing that way, we can continue Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Members/Attributes.pm | 17 ++++------------- Koha/Patrons.pm | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index 17c6286626..19b5b9e6ef 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -51,21 +51,12 @@ C4::Members::Attributes - manage extend patron attributes my $matching_borrowernumbers = C4::Members::Attributes::SearchIdMatchingAttribute($filter); =cut - +use Koha::Patrons; sub SearchIdMatchingAttribute{ my $filter = shift; - $filter = [$filter] unless ref $filter; - - my $dbh = C4::Context->dbh(); - my $query = qq{ -SELECT DISTINCT borrowernumber -FROM borrower_attributes -JOIN borrower_attribute_types USING (code) -WHERE staff_searchable = 1 -AND (} . join (" OR ", map "attribute like ?", @$filter) .qq{)}; - my $sth = $dbh->prepare_cached($query); - $sth->execute(map "%$_%", @$filter); - return [map $_->[0], @{ $sth->fetchall_arrayref }]; + + my @borrowernumbers = Koha::Patrons->filter_by_attribute_value($filter)->get_column('borrowernumber'); + return \@borrowernumbers; } =head2 extended_attributes_code_value_arrayref diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index ce732e00d4..0b65756945 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -442,6 +442,27 @@ sub filter_by_attribute_type { return Koha::Patrons->_new_from_dbic($rs); } +=head3 filter_by_attribute_value + +my $patrons = Koha::Patrons->filter_by_attribute_value($attribute_value); + +Return a Koha::Patrons set with patrong having the attribute value passed in paramter. + +=cut + +sub filter_by_attribute_value { + my ( $self, $attribute_value ) = @_; + my $rs = Koha::Patron::Attributes->search( + { + 'borrower_attribute_types.staff_searchable' => 1, + attribute => { like => "%$attribute_value%" } + }, + { join => 'borrower_attribute_types' } + )->_resultset()->search_related('borrowernumber'); + return Koha::Patrons->_new_from_dbic($rs); +} + + =head3 _type =cut -- 2.39.5