You are here

function Messaging_Message::set_destination in Messaging 6.4

Set destination object or figure out a destination if not set

Parameters

$destination: Destination object, single address, or array of addresses

10 calls to Messaging_Message::set_destination()
Messaging_Message::build in includes/messaging_message.class.inc
Check parameters and go for alter hook
Messaging_Message::check_destination in includes/messaging_message.class.inc
Check we have a sending method and a destination
Messaging_Message::get_addresses in includes/messaging_message.class.inc
Get addresses for this to be sent to
Messaging_Message::get_destination in includes/messaging_message.class.inc
Get destination object
Messaging_Message::prepare in includes/messaging_message.class.inc
Prepare for sending through given method

... See full list

File

includes/messaging_message.class.inc, line 420
Drupal Messaging Framework - Message class file

Class

Messaging_Message
Message class

Code

function set_destination($destination = NULL) {
  if (isset($destination)) {
    if (is_object($destination)) {
      $this->uid = $destination->uid;
      $this->destination = $destination->address;
      $this->mdid = $destination->mdid;
      $this->_destination = $destination;
    }
    else {

      // Set destination value but not destination object
      $this->destination = $destination;
      $this->mdid = 0;
      $this->_destination = FALSE;
    }
  }
  else {
    if (empty($this->method)) {

      // If we don't have a method we can get it from the user account
      $this->method = messaging_method_default($this
        ->get_user());
    }

    // If we've got a send method we can try filling the rest of the values
    if ($this
      ->send_method() && !isset($this->_destination)) {
      if (!empty($this->mdid) && ($destination = Messaging_Destination::load($this->mdid))) {
        return $this
          ->set_destination($destination);
      }
      elseif (empty($this->destination) && $this->uid && ($address = $this
        ->send_method()
        ->get_user_address($this
        ->get_user()))) {
        return $this
          ->set_destination($address);
      }
      else {
        return $this->_destination = FALSE;
      }
    }
  }
}