Ejemplo n.º 1
0
 public function readConversationAction()
 {
     if (!$this->zfcUserAuthentication()->hasIdentity()) {
         return $this->redirect()->toRoute($this->zfcUserOptions->getLoginRedirectRoute());
     }
     $form = $this->newMessageForm;
     $conversation = $this->pmService->getConversation($this->params('conversationId'));
     $messages = $this->pmService->getMessages($conversation);
     $user = $this->ZfcUserAuthentication()->getIdentity();
     // Paginator
     $paginator = new Paginator(new ArrayAdapter($messages));
     $page = $this->params('page', 1);
     $paginator->setDefaultItemCountPerPage($this->options->getMessagesPerPage());
     $paginator->setCurrentPageNumber($page);
     $this->pmService->markRead($conversation, $user);
     $viewModel = new ViewModel(['conversation' => $conversation, 'messages' => &$paginator, 'form' => $form]);
     $viewModel->setTemplate('eye4web/zfc-user/pm/read-conversation.phtml');
     $redirectUrl = $this->url()->fromRoute('eye4web/zfc-user/pm/read-conversation', ['conversationId' => $conversation->getId()]);
     $prg = $this->prg($redirectUrl, true);
     if ($prg instanceof Response) {
         return $prg;
     } elseif ($prg === false) {
         return $viewModel;
     }
     $form->setData($prg);
     if (!$form->isValid()) {
         return $viewModel;
     }
     $user = $this->zfcUserAuthentication()->getIdentity();
     $this->pmService->newMessage($conversation, $form->getData()['message'], $user);
     // return to self to get newest message and clear form
     return $this->redirect()->toRoute('eye4web/zfc-user/pm/read-conversation', ['conversationId' => $conversation->getId()]);
 }