/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new PrivateMessage();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['PrivateMessage'])) {
         $model->attributes = $_POST['PrivateMessage'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->MessageID));
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 2
0
File: User.php Progetto: rayku/rayku
 /**
  * Sends a private message from this user to $recipientID
  *
  * @param int $recipientID
  * @param string $subject
  * @param string $message
  * @return bool
  */
 public function sendMessage($recipientID, $subject, $message, $stripTags = true)
 {
     //If the user is banned, they can't send a message
     if ($this->getHidden()) {
         return false;
     }
     $recipient = UserPeer::retrieveByPK($recipientID);
     if (!$recipient) {
         return false;
     }
     $pm = new PrivateMessage();
     $pm->setSenderId($this->getId());
     $pm->setRecipientID($recipientID);
     //  $subject = $stripTags ? strip_tags($subject, sfConfig::get('app_general_allowed_html_tags')) : $subject;
     $pm->setSubject($subject);
     //   $message = $stripTags ? strip_tags($message, sfConfig::get('app_general_allowed_html_tags')) : $message;
     $pm->setBody($message);
     $saveStatus = $pm->save();
     $c = new Criteria();
     $c->add(NotificationEmailsPeer::USER_ID, $recipientID);
     $notifies = NotificationEmailsPeer::doSelectOne($c);
     if ($notifies != NULL) {
         if ($notifies->getOnOff() == 0) {
             if ($saveStatus) {
                 $mailer = Mailman::createMailer();
                 $mailer->setContentType('text/html');
                 $mailer->addAddress($recipient->getEmail());
                 $mailer->setSubject('New Private Message from Rayku.com');
                 sfProjectConfiguration::getActive()->loadHelpers(array('Url', 'Partial'));
                 $mailer->setBody(get_partial('global/mail/newPMNotification', array('pm' => $pm)));
                 //Send the e-mail off
                 $mailer->send();
             }
         }
     } else {
         if ($saveStatus) {
             $mailer = Mailman::createMailer();
             $mailer->setContentType('text/html');
             $mailer->addAddress($recipient->getEmail());
             $mailer->setSubject('New Private Message from Rayku.com');
             sfProjectConfiguration::getActive()->loadHelpers(array('Url', 'Partial'));
             $mailer->setBody(get_partial('global/mail/newPMNotification', array('pm' => $pm)));
             //Send the e-mail off
             $mailer->send();
         }
     }
     return $saveStatus;
 }