dimvcl
dimvcl

Reputation: 299

Doctrine create function from another

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.

Upvotes: 0

Views: 38

Answers (1)

a1337q
a1337q

Reputation: 780

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.

Upvotes: 1

Related Questions