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); } }
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; }
public static function model($className = __CLASS__) { return parent::model($className); }
/** * @param string $message */ public function __construct($message) { $this->message = $message; parent::__construct(static::TYPE); }
/** * 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; }