protected function getMessages($queue, $userId)
    {
        $messages = $queue->receive($userId);

        if (empty($messages)) {
            return [];
        }

        $messages = array_slice($messages, 0, 20);
        /** @var Module $module */
        $module = Yii::$app->getModule($this->module);
        $soundUrl = $module->soundUrl !== null ? Url::to($module->soundUrl) : null;

        $results = [];
        foreach ($messages as $message) {
            $result = [
                'title' => $queue->label,
                'body' => $message->body,
            ];
            if ($soundUrl !== null) {
                $result['sound'] = $soundUrl;
            }
            $results[] = $result;
        }

        return $results;
    }
protected function getMessages($queue, $userId)
    {
        $messages = $queue->receive($userId);

        if (empty($messages)) {
            return [];
        }

        $messages = array_slice($messages, 0, 20);
        /** @var Module $module */
        $module = Yii::$app->getModule($this->module);
        $soundUrl = $module->soundUrl !== null ? Url::to($module->soundUrl) : null;

        $results = [];
        foreach ($messages as $message) {
            $result = [
                'title' => $queue->label,
                'body' => $message->body,
            ];
            if ($soundUrl !== null) {
                $result['sound'] = $soundUrl;
            }
            $results[] = $result;
        }

        return $results;
    }
protected function getMessages ( $ queue , $ userId ) { $ messages = $ queue -> receive ( $ userId ) ; if ( empty ( $ messages ) ) { return [ ] ; } $ messages = array_slice ( $ messages , 0 , 20 ) ; /** @var Module $module */ $ module = Yii :: $ app -> getModule ( $ this -> module ) ; $ soundUrl = $ module -> soundUrl !== null ? Url :: to ( $ module -> soundUrl ) : null ; $ results = [ ] ; foreach ( $ messages as $ message ) { $ result = [ 'title' => $ queue -> label , 'body' => $ message -> body , ] ; if ( $ soundUrl !== null ) { $ result [ 'sound' ] = $ soundUrl ; } $ results [ ] = $ result ; } return $ results ; }
Fetches messages from a queue and deletes them. Messages are transformed into a json serializable array.
If a sound is configured in the module, an url is added to each message.

Only first 20 messages are returned but all available messages are deleted from the queue.

@param  QueueInterface $queue
@param  string         $userId
@return array
Fetches messages from a queue and deletes them . Messages are transformed into a json serializable array . If a sound is configured in the module an url is added to each message .