public function getAvailableProductsFor(Etudiant $student) { // Select only product which has not be bought by this student $boughtProducts = array(); /** @var Payment[] $payments */ $payments = $student->getPayments(); foreach ($payments as $payment) { $boughtProducts[] = $payment->getProduct()->getId(); } // The query to achieve what we are looking for $qb = $this->createQueryBuilder('p')->where("p.active = true"); if (count($boughtProducts) > 0) { // This request bug if $boughtProducts is empty $qb->andWhere("p.id NOT IN (?2)")->setParameter(2, $boughtProducts); } return $this->to_array_result($qb->getQuery()->getResult(Query::HYDRATE_OBJECT)); }
private function _registerToWei(Etudiant $student, $paymentMethod = null) { $products = $this->em->getRepository("CvaGestionMembreBundle:Produit"); $allowedProducts = [$products->getCurrentWEIPreInscription(), $products->getCurrentWEIPreWaiting(), $products->getCurrentWEIWaiting()]; if (in_array($products->getCurrentWEI(), $student->getProducts())) { return true; } /** @var Payment $payment */ foreach ($student->getPayments() as $payment) { if (in_array($payment->getProduct(), $allowedProducts)) { $this->em->remove($payment); if ($payment->getProduct()->hasWaitingList()) { $this->removeFromWaitingList($student, $payment->getProduct()); } $newPayment = new Payment(); $newPayment->setBillId($payment->getBillId()); $newPayment->setMethod($paymentMethod == null ? $payment->getMethod() : $paymentMethod); $newPayment->setStudent($payment->getStudent()); $newPayment->setDate($payment->getDate()); $newPayment->setProduct($products->getCurrentWEI()); $this->em->persist($newPayment); $this->em->flush(); return true; } } return false; }