You are here

class Messaging_Simple in Messaging 7

Simple message instance

Hierarchy

Expanded class hierarchy of Messaging_Simple

File

messaging_simple/messaging_simple.inc, line 10
Drupal Messaging Framework - Send_Method class file

View source
class Messaging_Simple extends Messaging_Object {
  public $mgid;
  public $msid;
  public $uid;
  public $sender;
  public $subject;
  public $body;
  public $language;

  // Timestamps
  public $sent;
  public $timeread = 0;

  /**
   * Build from db object
   */
  public static function build_object($template) {
    return new Messaging_Simple($template);
  }

  /**
   * Build from user account and Messaging_Message
   */
  public static function build($user, $message) {
    $store = new Messaging_Simple();
    $store->uid = $user->uid;
    $store->msid = $message->msid;
    $store->sender = $message
      ->get_sender('uid');
    $store->language = $message
      ->get_language()->language;

    // Build message subject and content, may do token replacement
    $template = $message
      ->get_template();

    // As this is to be displayed on site we don't need greetings nor footer
    $store->subject = $template
      ->render('subject');
    $store->body = $template
      ->render('content');
    return $store;
  }

  /**
   * Save to db
   */
  public function save() {
    $this->sent = time();
    return drupal_write_record('messaging_simple', $this);
  }

  /**
   * Mark when read
   */
  public function read() {
    $this->timeread = time();
    db_update('messaging_simple')
      ->fields(array(
      'timeread' => $this->timeread,
    ))
      ->condition('mgid', $this->mgid)
      ->execute();
    return $this->timeread;
  }

  /**
   * Load from db
   */
  public static function load($mgid) {
    if ($message = db_query("SELECT * FROM {messaging_simple} WHERE mgid = :mgid", array(
      ':mgid' => $mgid,
    ))
      ->fetchObject()) {
      return self::build_object($message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Messaging_Object::__construct public function Constructor
Messaging_Simple::$body public property
Messaging_Simple::$language public property
Messaging_Simple::$mgid public property
Messaging_Simple::$msid public property
Messaging_Simple::$sender public property
Messaging_Simple::$sent public property
Messaging_Simple::$subject public property
Messaging_Simple::$timeread public property
Messaging_Simple::$uid public property
Messaging_Simple::build public static function Build from user account and Messaging_Message
Messaging_Simple::build_object public static function Build from db object Overrides Messaging_Object::build_object
Messaging_Simple::load public static function Load from db
Messaging_Simple::read public function Mark when read
Messaging_Simple::save public function Save to db