X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=C4%2FMembers%2FAttributes.pm;h=33affa86cb0c10ae8c4243742031318d9a3e38cd;hb=b96c8b7ffa265251db3c0402adbfd68ec499cad9;hp=b89b03a64625079e17feb148ce382fb454614857;hpb=554c77569d5afe52912c085d0603b9d87a062d9b;p=koha_gimpoz diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index b89b03a646..33affa86cb 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -31,7 +31,7 @@ BEGIN { # set the version for version checking $VERSION = 3.01; @ISA = qw(Exporter); - @EXPORT_OK = qw(GetBorrowerAttributes CheckUniqueness SetBorrowerAttributes + @EXPORT_OK = qw(GetBorrowerAttributes GetBorrowerAttributeValue CheckUniqueness SetBorrowerAttributes extended_attributes_code_value_arrayref extended_attributes_merge SearchIdMatchingAttribute); %EXPORT_TAGS = ( all => \@EXPORT_OK ); @@ -72,7 +72,7 @@ sub GetBorrowerAttributes { my $opac_only = @_ ? shift : 0; my $dbh = C4::Context->dbh(); - my $query = "SELECT code, description, attribute, lib, password + my $query = "SELECT code, description, attribute, lib, password, display_checkout FROM borrower_attributes JOIN borrower_attribute_types USING (code) LEFT JOIN authorised_values ON (category = authorised_value_category AND attribute = authorised_value) @@ -89,30 +89,72 @@ sub GetBorrowerAttributes { value => $row->{'attribute'}, value_description => $row->{'lib'}, password => $row->{'password'}, + display_checkout => $row->{'display_checkout'}, } } 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); + +Retrieve the value of an extended attribute C<$attribute_code> associated with the +patron specified by C<$borrowernumber>. + +=cut + +sub GetBorrowerAttributeValue { + my $borrowernumber = shift; + my $code = shift; + + my $dbh = C4::Context->dbh(); + my $query = "SELECT attribute + FROM borrower_attributes + WHERE borrowernumber = ? + AND code = ?"; + my $value = $dbh->selectrow_array($query, undef, $borrowernumber, $code); + return $value; +} + =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 "%$finalfilter%"}; +AND (} . join (" OR ", map "attribute like ?", @$filter) .qq{)}; my $sth = $dbh->prepare_cached($query); - $sth->execute(); - return $sth->fetchall_arrayref; + $sth->execute(map "%$_%", @$filter); + return [map $_->[0], @{ $sth->fetchall_arrayref }]; } =head2 CheckUniqueness @@ -181,7 +223,12 @@ sub SetBorrowerAttributes { foreach my $attr (@$attr_list) { $attr->{password} = undef unless exists $attr->{password}; $sth->execute($borrowernumber, $attr->{code}, $attr->{value}, $attr->{password}); + if ($sth->err) { + warn sprintf('Database returned the following error: %s', $sth->errstr); + return; # bail immediately on errors + } } + return 1; # borower attributes successfully set } =head2 extended_attributes_code_value_arrayref