コード例 #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()]);
 }
コード例 #2
0
 /**
  * @return MessageInterface
  */
 public function getMessageEntity()
 {
     if (empty($this->messageEntity)) {
         $messageEntityClass = $this->options->getMessageEntity();
         $this->messageEntity = new $messageEntityClass();
     }
     return $this->messageEntity;
 }
コード例 #3
0
 /**
  * @param  ConversationInterface $conversation
  * @param  UserInterface         $user
  * @return bool
  */
 public function isUnread(ConversationInterface $conversation, UserInterface $user)
 {
     $this->getEventManager()->trigger('isUnread.pre', $this, ['conversation' => $conversation, 'user' => $user]);
     $repository = $this->objectManager->getRepository($this->options->getConversationReceiverEntity());
     $conversationReceiver = $repository->findOneBy(['conversation' => $conversation->getId(), 'to' => $user->getId()]);
     $unread = $conversationReceiver->getUnread();
     $this->getEventManager()->trigger('isUnread', $this, ['conversation' => $conversation, 'unread' => $unread]);
     return $unread;
 }
コード例 #4
0
 /**
  * @covers Eye4web\ZfcUser\Pm\Mapper\DoctrineORM\PmMapper::isUnread
  */
 public function testIsUnread()
 {
     $conversation = new Conversation();
     $conversation->setId(1);
     $user = new User();
     $user->setId(1);
     $optionsData = ['conversation' => $conversation->getId(), 'to' => $user->getId()];
     $this->options->expects($this->once())->method('getConversationReceiverEntity')->will($this->returnValue('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver'));
     $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $this->objectManager->expects($this->once())->method('getRepository')->with('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver')->will($this->returnValue($objectRepository));
     $conversationReceive = $this->getMock('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver');
     $objectRepository->expects($this->once())->method('findOneBy')->with($optionsData)->will($this->returnValue($conversationReceive));
     $conversationReceive->expects($this->once())->method('getUnread')->will($this->returnValue(true));
     $this->assertTrue($this->mapper->isUnread($conversation, $user));
 }