Bug 7700: Cart's more details view shows identity numbers
[koha_gimpoz] / C4 / Members / Attributes.pm
index 29a31e6..33affa8 100644 (file)
@@ -95,6 +95,24 @@ sub GetBorrowerAttributes {
     return \@results;
 }
 
+=head2 GetAttributes
+
+  my $attributes = C4::Members::Attributes::GetAttributes([$opac_only]);
+
+Retrieve an arrayref of extended attribute codes
+
+=cut
+
+sub GetAttributes {
+    my ($opac_only) = @_;
+
+    my $dbh = C4::Context->dbh();
+    my $query = "SELECT code FROM borrower_attribute_types";
+    $query .= "\nWHERE opac_display = 1" if $opac_only;
+    $query .= "\nORDER BY code";
+    return $dbh->selectcol_arrayref($query);
+}
+
 =head2 GetBorrowerAttributeValue
 
   my $value = C4::Members::Attributes::GetBorrowerAttributeValue($borrowernumber, $attribute_code);
@@ -119,23 +137,24 @@ sub GetBorrowerAttributeValue {
 
 =head2 SearchIdMatchingAttribute
 
-  my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter);
+  my $matching_borrowernumbers = C4::Members::Attributes::SearchIdMatchingAttribute($filter);
 
 =cut
 
 sub SearchIdMatchingAttribute{
     my $filter = shift;
-    my $finalfilter=$filter->[0];
+    $filter = [$filter] unless ref $filter;
+
     my $dbh   = C4::Context->dbh();
     my $query = qq{
-SELECT borrowernumber
+SELECT DISTINCT borrowernumber
 FROM borrower_attributes
 JOIN borrower_attribute_types USING (code)
 WHERE staff_searchable = 1
-AND attribute like ?};
+AND (} . join (" OR ", map "attribute like ?", @$filter) .qq{)};
     my $sth = $dbh->prepare_cached($query);
-    $sth->execute("%$finalfilter%");
-    return $sth->fetchall_arrayref;
+    $sth->execute(map "%$_%", @$filter);
+    return [map $_->[0], @{ $sth->fetchall_arrayref }];
 }
 
 =head2 CheckUniqueness