Exemplo n.º 1
0
 /**
  * Replying to the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionReply($id = null)
 {
     $model = new Message();
     $podiumUser = User::findMe();
     $reply = Message::findOne(['id' => $id, 'receiver_id' => $podiumUser->id]);
     if ($reply) {
         $model->topic = Message::re() . ' ' . $reply->topic;
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate()) {
                 if (!$podiumUser->isIgnoredBy($model->receiver_id)) {
                     $model->replyto = $reply->id;
                     if ($model->send()) {
                         $this->success(Yii::t('podium/flash', 'Message has been sent.'));
                         return $this->redirect(['messages/inbox']);
                     }
                 } else {
                     $this->error(Yii::t('podium/flash', 'Sorry! This member ignores you so you can not send the message.'));
                 }
             }
         }
         $model->receiver_id = $reply->sender_id;
         return $this->render('reply', ['model' => $model, 'reply' => $reply]);
     } else {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         return $this->redirect(['messages/inbox']);
     }
 }
Exemplo n.º 2
0
 /**
  * Viewing the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionView($id = null)
 {
     $model = Message::findOne(['and', ['id' => $id], ['or', 'receiver_id' => Yii::$app->user->id, 'sender_id' => Yii::$app->user->id]]);
     if ($model) {
         if ($model->receiver_id == Yii::$app->user->id && $model->receiver_status == Message::STATUS_NEW) {
             $model->receiver_status = Message::STATUS_READ;
             if ($model->save()) {
                 Cache::getInstance()->deleteElement('user.newmessages', Yii::$app->user->id);
             }
         }
         return $this->render('view', ['model' => $model]);
     } else {
         $this->error('Sorry! We can not find the message with the given ID.');
         return $this->redirect(['inbox']);
     }
 }