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']);
                    }
                    $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]);
    }
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']);
                    }
                    $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]);
    }
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' ] ) ; } $ 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 ] ) ; }
Replying to the message of given ID.
@param int $id
@return string|Response
Replying to the message of given ID .