public function actionMessages($queue_name, $subscriber_id = null)
    {
        if (($subscriber_id = trim($subscriber_id)) === '') {
            $subscriber_id = null;
        }
        /** @var QueueInterface $queue */
        list($queue, $authItems) = $this->loadQueue($queue_name, ['nfy.message.read', 'nfy.message.create']);
        $this->verifySubscriber($queue, $subscriber_id);

        $formModel = new models\MessageForm();
        if ($authItems['nfy.message.create'] && isset($_POST['MessageForm'])) {
            $formModel->attributes = $_POST['MessageForm'];
            if ($formModel->validate()) {
                $queue->send($formModel->content, $formModel->category);

                return $this->redirect([
                    'messages',
                    'queue_name' => $queue_name,
                    'subscriber_id' => $subscriber_id,
                ]);
            }
        }

        $dataProvider = null;
        if ($authItems['nfy.message.read']) {
            $dataProvider = new \yii\data\ArrayDataProvider([
                'allModels' => $queue->peek($subscriber_id, 200, [
                    components\Message::AVAILABLE,
                    components\Message::RESERVED,
                    components\Message::DELETED,
                ]),
                'sort' => [
                    'attributes' => ['id'],
                    'defaultOrder' => ['id' => SORT_DESC],
                ],
            ]);
            // reverse display order to simulate a chat window, where latest message is right above the message form
            $dataProvider->setModels(array_reverse($dataProvider->getModels()));
        }

        return $this->render('messages', [
            'queue' => $queue,
            'queue_name' => $queue_name,
            'dataProvider' => $dataProvider,
            'model' => $formModel,
            'authItems' => $authItems,
        ]);
    }
public function actionMessages($queue_name, $subscriber_id = null)
    {
        if (($subscriber_id = trim($subscriber_id)) === '') {
            $subscriber_id = null;
        }
        /** @var QueueInterface $queue */
        list($queue, $authItems) = $this->loadQueue($queue_name, ['nfy.message.read', 'nfy.message.create']);
        $this->verifySubscriber($queue, $subscriber_id);

        $formModel = new models\MessageForm();
        if ($authItems['nfy.message.create'] && isset($_POST['MessageForm'])) {
            $formModel->attributes = $_POST['MessageForm'];
            if ($formModel->validate()) {
                $queue->send($formModel->content, $formModel->category);

                return $this->redirect([
                    'messages',
                    'queue_name' => $queue_name,
                    'subscriber_id' => $subscriber_id,
                ]);
            }
        }

        $dataProvider = null;
        if ($authItems['nfy.message.read']) {
            $dataProvider = new \yii\data\ArrayDataProvider([
                'allModels' => $queue->peek($subscriber_id, 200, [
                    components\Message::AVAILABLE,
                    components\Message::RESERVED,
                    components\Message::DELETED,
                ]),
                'sort' => [
                    'attributes' => ['id'],
                    'defaultOrder' => ['id' => SORT_DESC],
                ],
            ]);
            // reverse display order to simulate a chat window, where latest message is right above the message form
            $dataProvider->setModels(array_reverse($dataProvider->getModels()));
        }

        return $this->render('messages', [
            'queue' => $queue,
            'queue_name' => $queue_name,
            'dataProvider' => $dataProvider,
            'model' => $formModel,
            'authItems' => $authItems,
        ]);
    }
public function actionMessages ( $ queue_name , $ subscriber_id = null ) { if ( ( $ subscriber_id = trim ( $ subscriber_id ) ) === '' ) { $ subscriber_id = null ; } /** @var QueueInterface $queue */ list ( $ queue , $ authItems ) = $ this -> loadQueue ( $ queue_name , [ 'nfy.message.read' , 'nfy.message.create' ] ) ; $ this -> verifySubscriber ( $ queue , $ subscriber_id ) ; $ formModel = new models \ MessageForm ( ) ; if ( $ authItems [ 'nfy.message.create' ] && isset ( $ _POST [ 'MessageForm' ] ) ) { $ formModel -> attributes = $ _POST [ 'MessageForm' ] ; if ( $ formModel -> validate ( ) ) { $ queue -> send ( $ formModel -> content , $ formModel -> category ) ; return $ this -> redirect ( [ 'messages' , 'queue_name' => $ queue_name , 'subscriber_id' => $ subscriber_id , ] ) ; } } $ dataProvider = null ; if ( $ authItems [ 'nfy.message.read' ] ) { $ dataProvider = new \ yii \ data \ ArrayDataProvider ( [ 'allModels' => $ queue -> peek ( $ subscriber_id , 200 , [ components \ Message :: AVAILABLE , components \ Message :: RESERVED , components \ Message :: DELETED , ] ) , 'sort' => [ 'attributes' => [ 'id' ] , 'defaultOrder' => [ 'id' => SORT_DESC ] , ] , ] ) ; // reverse display order to simulate a chat window, where latest message is right above the message form $ dataProvider -> setModels ( array_reverse ( $ dataProvider -> getModels ( ) ) ) ; } return $ this -> render ( 'messages' , [ 'queue' => $ queue , 'queue_name' => $ queue_name , 'dataProvider' => $ dataProvider , 'model' => $ formModel , 'authItems' => $ authItems , ] ) ; }
Displays and send messages in the specified queue.
@param string $queue_name
@param string $subscriber_id
@return string|\yii\web\Response
Displays and send messages in the specified queue .