0

I have the following function that counts the unanswered questions:

   public function getUnansweredQuestions(Company $company){
        $qb = $this->createQueryBuilder("q");
        $andX = $qb->expr()->andX();

        $andX->add($qb->expr()->isNull("q.answer"));
        $andX->add("user.company = :company");
        $qb->setParameter("company", $company);

        $andX->add($qb->expr()->in("bid.status", ":status"));
        $qb->setParameter("status", [PurchaseBid::STATUS_PUBLISHED, PurchaseBid::STATUS_CLOSED]);

        $qb->leftJoin("q.purchaseBid", "bid");
        $qb->leftJoin("bid.createdBy", "user");
        $qb->where($andX);
        return $qb->getQuery()->getResult();
    }

I need to ask only if there is a question (answered or unanswered). I don't understand the code very well, but a way from this function should be exists.

dimvcl
  • 289
  • 1
  • 3
  • 13
  • http://stackoverflow.com/questions/9214471/count-rows-in-doctrine-querybuilder – a1337q Jan 04 '16 at 15:34
  • Your question is about the Doctrine Query Builder, not about Symfony2 directly. Also it doesn't have to do much with functions. You really have to read the manuals on all the stuff in order to understand what's happening. http://symfony.com/doc/current/book/doctrine.html – a1337q Jan 04 '16 at 15:35

1 Answers1

1

See Count Rows in Doctrine QueryBuilder for solutions how to count number of rows using the Doctrine Query Builder. I guess this solves your problem. Count > 1 => you have questions.

Community
  • 1
  • 1
a1337q
  • 770
  • 3
  • 10
  • 20