findByMerchantQuery() ; $query->andWhere('e.status = 1'); $query->andWhere('e.type = :type'); $query->andWhere(':user MEMBER OF e.users'); $query->setParameter('user', $user); $query->setParameter('type', ReductionCredit::TYPE_CREDIT); return $query->getQuery()->getResult() ; } public function findReductionGiftToUseByUser($user){ $query = $this->findByMerchantQuery() ; $query->andWhere('e.status = 1'); $query->andWhere('e.type = :type'); $query->andWhere(':user MEMBER OF e.users'); $query->andWhere(':now > e.activationDate'); $query->setParameter('now', new \DateTime()) ; $query->setParameter('user', $user); $query->setParameter('type', ReductionCredit::TYPE_GIFT); return $query->getQuery()->getResult() ; } public function findReductionGiftOwnedByUser($user){ $query = $this->findByMerchantQuery() ; $query->leftJoin('e.users', 'u'); $query->having('COUNT(u.id) =0'); $query->andWhere('e.status = 1'); $query->andWhere('e.type = :type'); $query->andWhere('e.owner = :user'); $query->setParameter('user', $user); $query->setParameter('type', ReductionCredit::TYPE_GIFT); $query->groupBy('e.id'); return $query->getQuery()->getResult() ; } public function findReductionGiftOwnedActiveByUser($user){ $query = $this->findByMerchantQuery() ; $query->leftJoin('e.users', 'u'); $query->having('COUNT(u.id) >0'); $query->andWhere('e.status = 1'); $query->andWhere('e.type = :type'); $query->andWhere('e.owner = :user'); $query->setParameter('user', $user); $query->setParameter('type', ReductionCredit::TYPE_GIFT); $query->groupBy('e.id'); return $query->getQuery()->getResult() ; } }