You are here

function Notifications_Subscription::validate_destination in Notifications 6.4

Validate destination for this subscription

1 call to Notifications_Subscription::validate_destination()
Notifications_Subscription::create_destination in includes/notifications_subscription.class.inc
Create destination for this subscription

File

includes/notifications_subscription.class.inc, line 381
Drupal Notifications Framework - Default class file

Class

Notifications_Subscription
Message destination class

Code

function validate_destination($method = NULL, $address = NULL, $create = FALSE) {
  $account = $this
    ->get_user();
  if ($method && $address) {
    if ($create) {
      $destination = Messaging_Destination::create_method($method, $address, $account->uid);
      $this
        ->set_destination($destination);
      return $destination;
    }
    else {

      // Just validate
      return Messaging_Destination::validate_method($method, $address, $account->uid);
    }
  }
  elseif ($account->uid) {

    // For registered users we have other ways to create a destination
    if ($method) {
      if ($address = messaging_user_destination($account, $method)) {

        // We have a method and address for this user account, fine
        return $this
          ->validate_destination($method, $address, $create);
      }
    }
    else {

      // We still can have a send method or get it from account
      $method = !empty($this->send_method) ? $this->send_method : messaging_method_default($account);
      if ($method) {
        return $this
          ->validate_destination($method, NULL, $create);
      }
    }
  }
}