You are here

abstract class Messaging_Method in Messaging 7

Same name and namespace in other branches
  1. 6.4 includes/messaging_method.class.inc \Messaging_Method

Base class for all Incoming and Sending methods

Hierarchy

Expanded class hierarchy of Messaging_Method

File

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

View source
abstract class Messaging_Method {

  // Method identifier
  public $method;

  // Method type
  public $type;

  // Method group
  public $enabled = TRUE;
  public $anonymous = FALSE;

  // Remaining info array
  public $info = array();

  /**
   * Build send method from info array
   *
   * Some of the array values will be set as properties for the object. Some others won't as they're just
   * for formatting, so they'll be kept only in the $object->info array
   */
  function __construct($method, $info = array()) {
    $this->method = $method;
    foreach ($info as $key => $value) {
      $this->{$key} = $value;
    }
    $this->info = $info;
  }

  /**
   * Get method title for administrator list
   */
  function get_title() {
    return $this
      ->method_info('title', t('Method'));
  }

  /**
   * Get method name, may be overridden by info properties
   */
  function get_name() {
    return $this
      ->method_info('name', $this
      ->get_title());
  }

  /**
   * Get method description, may be overridden by info properties
   */
  function get_description() {
    return $this
      ->method_info('description', t('Send messages.'));
  }

  /**
   * Get info property
   */
  function method_info($property = NULL, $default = NULL) {
    if ($property) {
      return isset($this->info[$property]) ? $this->info[$property] : $default;
    }
    else {
      return $this->info;
    }
  }

  /**
   * Returns default messaging method
   */
  static function default_method($account = NULL) {
    if ($account && !empty($account->messaging_default) && messaging_method($account->messaging_default)
      ->user_access($account)) {
      return $account->messaging_default;
    }
    elseif ($method = variable_get('messaging_default_method', '')) {
      return $method;
    }
    else {
      return key(messaging_method_info());
    }
  }

  /**
   * Update messaging method.
   *
   * When a messaging method is disabled, we need to update current settings for this and other modues
   *
   * @param $method
   *   Method to disable
   * @param $replace
   *   Optional replacement method suggested by the disabled one.
   */
  static function method_disable($method, $replace = NULL) {
    module_load_include('install', 'messaging');
    $replace = isset($replace) ? $replace : messaging_update_method_replace($method, TRUE);
    messaging_update_method_disable($method, $replace);
    if ($replace) {
      drupal_set_message(t('Disabled messaging sending method %method and replaced by %replace', array(
        '%method' => messaging_method_info($method, 'title'),
        '%replace' => messaging_method_info($replace, 'title'),
      )));
    }
    else {

      // It seems all methods are disabled, print warning
      drupal_set_message(t('Disabled messaging sending method but cannot find a replacement. Please, enable some other sending method.'), 'error');
    }
  }

  /**
   * Log message action
   */
  protected function message_log($text, $message) {
    $text = $this
      ->get_name() . ': ' . $text;
    messaging_log($text, array(
      'message' => $message,
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Messaging_Method::$anonymous public property 1
Messaging_Method::$enabled public property 1
Messaging_Method::$info public property
Messaging_Method::$method public property 1
Messaging_Method::$type public property 1
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