You are here

function registration_registrant_load_by_mail in Entity Registration 7.2

Same name and namespace in other branches
  1. 8.2 registration.module \registration_registrant_load_by_mail()

Fetch a registrant entity for a given email address, or NULL if no entity found.

Parameters

object $registration_type: Registration type object.

string $mail: Email address.

Return value

object Entity object.

2 calls to registration_registrant_load_by_mail()
registration_form_submit in includes/registration.forms.inc
Submit callback for registration_form().
registration_get_registrations in ./registration.module
Load registrations for a host entity, optionally filtered to a particular registrant email.

File

./registration.module, line 1634

Code

function registration_registrant_load_by_mail($registration_type, $mail) {
  $registrant_entity_type = $registration_type->registrant_entity_type;
  $property_parts = explode(':', $registration_type->registrant_email_property);
  $email_property = $property_parts[0];
  $email_field_col = isset($property_parts[1]) ? $property_parts[1] : NULL;
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $registrant_entity_type);
  if ($email_field_col) {
    $query
      ->fieldCondition($email_property, $email_field_col, $mail, '=');
  }
  else {
    $query
      ->propertyCondition($email_property, $mail, '=');
  }
  $result = $query
    ->execute();
  if (!empty($result[$registrant_entity_type])) {
    $ids = array_keys($result[$registrant_entity_type]);
    $registrant = entity_load_single($registrant_entity_type, reset($ids));
    if ($registrant) {
      return entity_metadata_wrapper($registrant_entity_type, $registrant);
    }
  }
  return NULL;
}