public function save(Doctrine_Connection $conn = null)
 {
     $send_message = false;
     if ($this->isNew()) {
         if (!$this->hasVerifiedSender()) {
             $this->deleteWithException("Cannot create Message " . "because sfGuardUser " . $this->getSenderId() . " has not been validated yet.", 406);
         }
         if (!$this->hasVerifiedRecipient()) {
             $this->deleteWithException("Cannot create Message " . "because sfGuardUser " . $this->getSenderId() . " has not been validated yet.", 406);
         }
         $send_message = true;
     }
     /* If the obejct is not new or has passed all rules for saving, we pass
      * it on to the parent save function.
      */
     parent::save($conn);
     if ($send_message) {
         /* The following is for sending an email to the recipient to notify them that they've received a message.
          */
         $recipient = sfGuardUserTable::getInstance()->find($this->getRecipientId());
         if (!$recipient || !$recipient->getReceiveNotificationOfPrivateMessages()) {
             return parent::save($conn);
         }
         $parameters = array('user_id' => $this->getRecipientId(), 'message_id' => $this->getIncremented());
         $prefer_html = $recipient->getPreferHtml();
         $address = $recipient->getEmailAddress();
         $name = $recipient->getPreferredName() ? $recipient->getPreferredName() : $recipient->getFullName();
         $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('NewPrivateMessage', $recipient->getPreferredLanguage());
         $subject = $email->generateSubject($parameters);
         $body = $email->generateBodyText($parameters, $prefer_html);
         $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>');
         AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null);
     }
 }
示例#2
0
文件: Message.php 项目: ably/ably-php
 protected function encode()
 {
     $msg = parent::encode();
     if (isset($this->name) && $this->name) {
         $msg->name = $this->name;
     }
     if (isset($this->connectionKey) && $this->connectionKey) {
         $msg->connectionKey = $this->connectionKey;
     }
     return $msg;
 }
示例#3
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * @param string $message
  */
 public function __construct($message)
 {
     $this->message = $message;
     parent::__construct(static::TYPE);
 }
示例#5
0
 /**
  * Returns a peer instance associated with this om.
  *
  * Since Peer classes are not to have any instance attributes, this method returns the
  * same instance for all member of this class. The method could therefore
  * be static, but this would prevent one from overriding the behavior.
  *
  * @return     MessagePeer
  */
 public function getPeer()
 {
     if (self::$peer === null) {
         self::$peer = new MessagePeer();
     }
     return self::$peer;
 }