You are here

class Messaging_Send_Method in Messaging 7

Same name and namespace in other branches
  1. 6.4 includes/messaging_method.class.inc \Messaging_Send_Method
  2. 6.3 classes/messaging_method.class.inc \Messaging_Send_Method

Sending method, implements all specific method functionality

Old callback functions are

  • send
  • destination

Hierarchy

Expanded class hierarchy of Messaging_Send_Method

1 string reference to 'Messaging_Send_Method'
messaging_send_method in ./messaging.module
Get send method object

File

./messaging.method.inc, line 121
Drupal Messaging Framework - Send_Method class file

View source
class Messaging_Send_Method extends Messaging_Method {

  // Default parameters for send method
  public $method = 'send';
  public $type = 'web';
  public $enabled = TRUE;

  // Available for anonymous users
  public $anonymous = FALSE;

  // Qeueue messages instead of sending
  public $queue = FALSE;

  // Whether we want all messages logged for this method
  public $log = FALSE;

  // Default format for message rendering
  public $format = MESSAGING_FORMAT_HTML;

  /**
   * Get address type
   */
  public static function address_type() {
    return 'none';
  }

  /**
   * Get address info property
   */
  public static function address_info($property = NULL, $default = NULL) {
    return messaging_address_info(self::address_type(), $property, $default);
  }

  /**
   * Get address name
   */
  public static function address_name() {
    return self::address_info('name', t('Address'));
  }

  /**
   * Message processing: Decide on queue, log, cron and send options, prepare parameters
   *
   * At this stage, the message can be still redirected through other sending method, or marked for discard
   */
  function message_prepare($message) {

    // Set queueing if not message priority
    if ($this->queue && $message->priority <= 0) {
      $message->queue = 1;
    }
    $message->log = $message->log || $this->log;
    $this
      ->message_log('Message prepared', $message);
  }

  /**
   * Prepare message for specific user. Check availability, redirect, etc..
   *
   * Redirecting is only possible when we are sending to a user account, not for anonymous destinations
   */
  function message_user($message) {
  }

  /**
   * Prepare template for this method.
   *
   * Here we can clone and alter the template or just return the same
   */
  function message_render($message) {
    $message
      ->get_template()
      ->set_method($this->method)
      ->set_format($this->format);
  }

  /**
   * Send message to a single or multiple destination
   */
  function message_send($message) {
    $this
      ->message_log('Message send', $message);
    $destinations = $message
      ->get_destinations();
    $results = $this
      ->send_multiple($destinations, $message);
    $message
      ->set_results($results);
    return (bool) array_filter($results);
  }

  /**
   * Send message to destination
   */
  function send_destination($destination, $message) {

    // Set destination to message template
    $message
      ->get_template()
      ->set_destination($destination);
    return $this
      ->send_address($destination
      ->get_address(), $message);
  }

  /**
   * Send message to address, to be implemented by send method
   */
  function send_address($address, $message) {
    return FALSE;
  }

  /**
   * Send message to multiple destinations
   */
  function send_multiple($destinations, $message) {
    $results = array();
    foreach ($destinations as $key => $destination) {
      $results[$key] = $this
        ->send_destination($destination, $message);
    }
    return $results;
  }

  /**
   * Get message parameters for this method
   */
  function message_params($message) {
    return $message
      ->get_params($this->method) + $message
      ->get_params($this->type) + $this
      ->default_params();
  }

  /**
   * Queue message for next delivery
   *
   * By default it is saved to the store, though some sending methods like 'simple' may not consider queueing.
   *
   * If no queue available we send the message
   */
  function message_queue($message) {
    if ($queue = messaging_store('queue')) {
      $message->queued = time();
      $queue
        ->message_queue($message);
      return TRUE;
    }
    else {
      $message->queued = 0;
      return $this
        ->message_send($message);
    }
  }

  /**
   * Get destination for user account
   *
   * @param $account
   *   User account object or uid
   */
  function user_destination($account) {
    return Messaging_Destination::build_user($this
      ->address_type(), $account);
  }

  /**
   * Check user access to this method
   */
  function user_access($account) {
    if (!$account->uid && !$this->anonymous) {
      return FALSE;
    }
    if ($permission = $this
      ->method_info('access')) {
      return user_access($permission, $account);
    }
    else {
      return TRUE;
    }
  }

  /**
   * Make address into destination
   */
  public function address_destination($address, $validate = TRUE) {
    return Messaging_Destination::build_address($this
      ->address_type(), $address, $validate);
  }

  /**
   * Validate address
   */
  public function address_validate($address) {
    return Messaging_Destination::validate_address($address, $this
      ->address_type());
  }

  /**
   * Format address for display
   */
  public function format_address($address, $format = MESSAGING_FORMAT_PLAIN) {
    return Messaging_Destination::format_address($address, $format, $this
      ->address_type());
  }

  /**
   * Check whether it supports anonyous destination
   */
  function supports_anonymous() {
    return TRUE;
  }

  /**
   * Get default parameters for this method
   */
  static function default_params() {
    return array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Messaging_Method::$info public property
Messaging_Method::default_method static function Returns default messaging method
Messaging_Method::get_description function Get method description, may be overridden by info properties
Messaging_Method::get_name function Get method name, may be overridden by info properties
Messaging_Method::get_title function Get method title for administrator list
Messaging_Method::message_log protected function Log message action
Messaging_Method::method_disable static function Update messaging method.
Messaging_Method::method_info function Get info property
Messaging_Method::__construct function Build send method from info array
Messaging_Send_Method::$anonymous public property Overrides Messaging_Method::$anonymous
Messaging_Send_Method::$enabled public property Overrides Messaging_Method::$enabled
Messaging_Send_Method::$format public property
Messaging_Send_Method::$log public property
Messaging_Send_Method::$method public property Overrides Messaging_Method::$method
Messaging_Send_Method::$queue public property
Messaging_Send_Method::$type public property Overrides Messaging_Method::$type
Messaging_Send_Method::address_destination public function Make address into destination
Messaging_Send_Method::address_info public static function Get address info property
Messaging_Send_Method::address_name public static function Get address name
Messaging_Send_Method::address_type public static function Get address type
Messaging_Send_Method::address_validate public function Validate address
Messaging_Send_Method::default_params static function Get default parameters for this method
Messaging_Send_Method::format_address public function Format address for display
Messaging_Send_Method::message_params function Get message parameters for this method
Messaging_Send_Method::message_prepare function Message processing: Decide on queue, log, cron and send options, prepare parameters
Messaging_Send_Method::message_queue function Queue message for next delivery
Messaging_Send_Method::message_render function Prepare template for this method.
Messaging_Send_Method::message_send function Send message to a single or multiple destination
Messaging_Send_Method::message_user function Prepare message for specific user. Check availability, redirect, etc..
Messaging_Send_Method::send_address function Send message to address, to be implemented by send method
Messaging_Send_Method::send_destination function Send message to destination
Messaging_Send_Method::send_multiple function Send message to multiple destinations
Messaging_Send_Method::supports_anonymous function Check whether it supports anonyous destination
Messaging_Send_Method::user_access function Check user access to this method
Messaging_Send_Method::user_destination function Get destination for user account