getPreferredEmailAddress: initial implementation.
This commit is contained in:
parent
2e39065c3e
commit
5a37adc626
1 changed files with 47 additions and 0 deletions
|
@ -288,10 +288,57 @@ sub setPreferredEmailAddress($$$) {
|
||||||
$self->dbh->do("UPDATE supporter_email_address_mapping " .
|
$self->dbh->do("UPDATE supporter_email_address_mapping " .
|
||||||
"SET preferred = " . $self->dbh->quote(1, 'SQL_BOOLEAN') . " " .
|
"SET preferred = " . $self->dbh->quote(1, 'SQL_BOOLEAN') . " " .
|
||||||
"WHERE email_address_id = " . $self->dbh->quote($emailAddressId, 'SQL_INTEGER'));
|
"WHERE email_address_id = " . $self->dbh->quote($emailAddressId, 'SQL_INTEGER'));
|
||||||
|
$self->_commit;
|
||||||
return $emailAddressId;
|
return $emailAddressId;
|
||||||
}
|
}
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
=begin getPreferredEmailAddress
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item $supporterId
|
||||||
|
|
||||||
|
Valid supporter id number currently in the database. die() will occur if
|
||||||
|
the id number is not in the database already as a supporter id.
|
||||||
|
|
||||||
|
|
||||||
|
=item $emailAddress
|
||||||
|
|
||||||
|
Scalar string that contains an email address. undef is returned if the
|
||||||
|
email address is not already in the database for this supporter.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
Returns the email_address_id of the preferred email address. undef can be
|
||||||
|
returned; it means the preferred email address wasn't selected for some reason.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getPreferredEmailAddress($$) {
|
||||||
|
my($self, $supporterId) = @_;
|
||||||
|
|
||||||
|
die "setPreferredEmailAddress: invalid supporter id, $supporterId" unless $self->_verifyId($supporterId);
|
||||||
|
|
||||||
|
my $ems = $self->dbh()->selectall_hashref("SELECT email_address FROM email_address em, supporter_email_address_mapping sem " .
|
||||||
|
"WHERE preferred AND sem.email_address_id = em.id AND " .
|
||||||
|
"sem.supporter_id = " . $self->dbh->quote($supporterId, 'SQL_INTEGER'),
|
||||||
|
'email_address');
|
||||||
|
my $rowCount = scalar keys %{$ems};
|
||||||
|
die "setPreferredEmailAddress: DATABASE INTEGRITY ERROR: more than one email address is preferred for supporter, \"$supporterId\""
|
||||||
|
if $rowCount > 1;
|
||||||
|
|
||||||
|
if ($rowCount != 1) {
|
||||||
|
return undef;
|
||||||
|
} else {
|
||||||
|
my ($emailAddress) = keys %$ems;
|
||||||
|
return $emailAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
######################################################################
|
||||||
|
|
||||||
=begin addPostalAddress
|
=begin addPostalAddress
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
Loading…
Reference in a new issue