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
 /**
  * Replying to the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionReply($id = null)
 {
     $podiumUser = User::findMe();
     if (Message::tooMany($podiumUser->id)) {
         $this->warning(Yii::t('podium/flash', 'You have reached maximum {max_messages, plural, =1{ message} other{ messages}} per {max_minutes, plural, =1{ minute} other{ minutes}} limit. Wait few minutes before sending a new message.', ['max_messages' => Message::SPAM_MESSAGES, 'max_minutes' => Message::SPAM_WAIT]));
         return $this->redirect(['messages/inbox']);
     }
     $reply = Message::find()->where([Message::tableName() . '.id' => $id])->joinWith(['messageReceivers' => function ($q) use($podiumUser) {
         $q->where(['receiver_id' => $podiumUser->id]);
     }])->limit(1)->one();
     if (empty($reply)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         return $this->redirect(['messages/inbox']);
     }
     $model = new Message();
     $model->topic = Message::re() . ' ' . $reply->topic;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if (!$podiumUser->isIgnoredBy($model->receiversId[0])) {
                 $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! There was some error while sending your message.'));
                 }
             } else {
                 $this->error(Yii::t('podium/flash', 'Sorry! This member ignores you so you can not send the message.'));
             }
         }
     }
     $model->receiversId = [$reply->sender_id];
     return $this->render('reply', ['model' => $model, 'reply' => $reply]);
 }