/** * Check if user is participant to a conversation * * @param ConversationInterface $conversation * @param UserInterface $user * @return bool */ public function isParticipant(ConversationInterface $conversation, UserInterface $user) { foreach ($conversation->getParticipants() as $participant) { if ($participant->getUser() === $user->getId()) { return true; } } return false; }
/** * Find user conversation * * @param UserInterface $user * @return array|\LaravelPM\Models\ParticipantInterface[] */ public function getUserConversations(UserInterface $user) { $query = $this->objectManager->createQuery(sprintf('select p from %s p where p.user = :userId', $this->participantModel)); $query->setParameter('userId', $user->getId()); /** @var ParticipantInterface[]|array $participantLinks */ $participantLinks = $query->getResult(); /** @var ConversationInterface $conversations */ $conversations = []; foreach ($participantLinks as $participantLink) { $conversations[] = $participantLink->getConversation(); } return $conversations; }