Browse Source

Bug 20443: Remove SearchIdMatchingAttribute - prove we are not cheating

Tests are still passing that way, we can continue

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Jonathan Druart 6 years ago
committed by Martin Renvoize
parent
commit
4428d08657
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 17
      C4/Members/Attributes.pm
  2. 21
      Koha/Patrons.pm

17
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

21
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

Loading…
Cancel
Save