function registration_is_registered in Entity Registration 8
Same name and namespace in other branches
- 8.2 registration.module \registration_is_registered()
- 7.2 registration.module \registration_is_registered()
- 7 registration.module \registration_is_registered()
Determine is a person has an active registration for a host entity.
A person may be Drupal user account, identified by user uid ($uid). Or a non-user, identified by an email address ($anon_mail).
One of $anon_mail or $uid is required.
Parameters
object $registration: A fully loaded registration object.
string $anon_mail: (optional) An email address.
int $uid: (optional) A user account uid.
array $states: (optional) An array of states to test against. Defaults to active states.
Return value
bool
2 calls to registration_is_registered()
- registration_access_people in ./
registration.module - Determine people types user may register for an entity.
- registration_form_validate in includes/
registration.forms.inc - Validation callback for registration_form().
File
- ./
registration.module, line 1398
Code
function registration_is_registered(Registration $registration, $anon_mail = NULL, $uid = NULL, $states = array()) {
// must provide an UID or anon_mail
// @todo: better course of action here?
if (!$anon_mail && !$uid) {
return FALSE;
}
if (empty($states)) {
$states = registration_get_active_states();
}
// Ensure we have active states before querying against them.
if (empty($states)) {
return FALSE;
}
$query = db_select('registration', 'r')
->condition('entity_id', $registration->entity_id)
->condition('entity_type', $registration->entity_type)
->condition('state', $states, 'IN');
if ($anon_mail) {
// There's a user with this email, check to make sure they're not registered.
if ($user = user_load_by_mail($anon_mail)) {
$query
->condition(db_or()
->condition('anon_mail', $anon_mail)
->condition('user_uid', $user->uid));
}
else {
$query
->condition('anon_mail', $anon_mail);
}
}
elseif ($uid) {
$query
->condition('user_uid', $uid);
}
// Exclude existing registration.
if (isset($registration->registration_id)) {
$query
->condition('registration_id', $registration->registration_id, '<>');
}
$count = $query
->countQuery()
->execute()
->fetchField();
return $count > 0;
}