View | Details | Raw Unified | Return to bug 20443
Collapse All | Expand All

(-)a/C4/Members/Attributes.pm (-13 / +4 lines)
Lines 51-71 C4::Members::Attributes - manage extend patron attributes Link Here
51
  my $matching_borrowernumbers = C4::Members::Attributes::SearchIdMatchingAttribute($filter);
51
  my $matching_borrowernumbers = C4::Members::Attributes::SearchIdMatchingAttribute($filter);
52
52
53
=cut
53
=cut
54
54
use Koha::Patrons;
55
sub SearchIdMatchingAttribute{
55
sub SearchIdMatchingAttribute{
56
    my $filter = shift;
56
    my $filter = shift;
57
    $filter = [$filter] unless ref $filter;
57
58
58
    my @borrowernumbers = Koha::Patrons->filter_by_attribute_value($filter)->get_column('borrowernumber');
59
    my $dbh   = C4::Context->dbh();
59
    return \@borrowernumbers;
60
    my $query = qq{
61
SELECT DISTINCT borrowernumber
62
FROM borrower_attributes
63
JOIN borrower_attribute_types USING (code)
64
WHERE staff_searchable = 1
65
AND (} . join (" OR ", map "attribute like ?", @$filter) .qq{)};
66
    my $sth = $dbh->prepare_cached($query);
67
    $sth->execute(map "%$_%", @$filter);
68
    return [map $_->[0], @{ $sth->fetchall_arrayref }];
69
}
60
}
70
61
71
=head2 extended_attributes_code_value_arrayref 
62
=head2 extended_attributes_code_value_arrayref 
(-)a/Koha/Patrons.pm (-1 / +21 lines)
Lines 442-447 sub filter_by_attribute_type { Link Here
442
    return Koha::Patrons->_new_from_dbic($rs);
442
    return Koha::Patrons->_new_from_dbic($rs);
443
}
443
}
444
444
445
=head3 filter_by_attribute_value
446
447
my $patrons = Koha::Patrons->filter_by_attribute_value($attribute_value);
448
449
Return a Koha::Patrons set with patrong having the attribute value passed in paramter.
450
451
=cut
452
453
sub filter_by_attribute_value {
454
    my ( $self, $attribute_value ) = @_;
455
    my $rs = Koha::Patron::Attributes->search(
456
        {
457
            'borrower_attribute_types.staff_searchable' => 1,
458
            attribute => { like => "%$attribute_value%" }
459
        },
460
        { join => 'borrower_attribute_types' }
461
    )->_resultset()->search_related('borrowernumber');
462
    return Koha::Patrons->_new_from_dbic($rs);
463
}
464
465
445
=head3 _type
466
=head3 _type
446
467
447
=cut
468
=cut
448
- 

Return to bug 20443