public function findOrCreateConversation($firstUser, $secondUser, $subject = null) { $firstAuthor = $this->checkAndCreateAuthor($firstUser, true); $secondAuthor = $this->checkAndCreateAuthor($secondUser, true); $conversations = $this->findConversationsBetween($firstAuthor, $secondAuthor); if ($conversations) { foreach ($conversations as $conversation) { if ($conversation->getSubject() == $subject) { return $conversation; } } } $conversation = new Conversation(); $conversation->addAuthor($firstAuthor); $conversation->addAuthor($secondAuthor); $conversation->setSubject($subject); $this->container->get('doctrine')->getManager()->persist($conversation); $this->container->get('doctrine')->getManager()->flush(); return $conversation; }
public function checkExistAuthor(Conversation $conversation, Author $author) { return $this->createQueryBuilder('r')->select('COUNT(r)')->innerJoin('r.authors', 'authors')->where('authors.id = :author_id')->andWhere('r.id = :id')->setParameter('id', $conversation->getId())->setParameter('author_id', $author->getId())->getQuery()->getSingleScalarResult(); }