public function actionCompose($to_user_id = null, $answer_to = 0)
 {
     $model = new YumMessage();
     $this->performAjaxValidation('YumMessage', 'yum-message-form');
     if (isset($_POST['YumMessage'])) {
         $model->attributes = $_POST['YumMessage'];
         $model->from_user_id = Yii::app()->user->id;
         $model->validate();
         if (!$model->hasErrors()) {
             $model->save();
             Yum::setFlash(Yum::t('Message "{message}" has been sent to {to}', array('{message}' => $model->title, '{to}' => YumUser::model()->findByPk($model->to_user_id)->username)));
             $this->redirect(Yum::module('message')->inboxRoute);
         }
     }
     $fct = 'render';
     if (Yii::app()->request->isAjaxRequest) {
         $fct = 'renderPartial';
     }
     $this->{$fct}('compose', array('model' => $model, 'to_user_id' => $to_user_id, 'answer_to' => $answer_to));
 }
예제 #2
0
 public static function write($to, $from, $subject, $body, $mail = true)
 {
     $message = new YumMessage();
     if (!$mail) {
         $message->omit_mail = true;
     }
     if (is_object($from)) {
         $message->from_user_id = (int) $from->id;
     } else {
         if (is_numeric($from)) {
             $message->from_user_id = $from;
         } else {
             if (is_string($from) && ($user = YumUser::model()->find("username = '******'"))) {
                 $message->from_user_id = $user->id;
             } else {
                 return false;
             }
         }
     }
     if (is_object($to)) {
         $message->to_user_id = (int) $to->id;
     } else {
         if (is_numeric($to)) {
             $message->to_user_id = $to;
         } else {
             if (is_string($to) && ($user = YumUser::model()->find("username = '******'"))) {
                 $message->to_user_id = $user->id;
             } else {
                 return false;
             }
         }
     }
     $message->title = $subject;
     $message->message = $body;
     $message->message_read = 0;
     return $message->save();
 }