Beispiel #1
0
 public function checkVA(Etudiant $student)
 {
     $products = $this->em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentVAIds();
     $studentProducts = $student->getProducts();
     foreach ($studentProducts as $prod) {
         if (in_array($prod->getId(), $products)) {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
 public function getProductsFor(Etudiant $student)
 {
     $products = $this->getProducts();
     $boughtProducts = $student->getProducts();
     /** @var Produit $product */
     foreach ($products as $k => &$product) {
         foreach ($boughtProducts as &$sproduct) {
             if ($product == $sproduct || $product->getCanNotBeSoldWith()->contains($sproduct)) {
                 unset($products[$k]);
             }
         }
     }
     return $products;
 }
Beispiel #3
0
 /**
  * Match if this mail can be send to this user.
  * @param Etudiant $student The student to test for this mail
  * @param Produit[] $addProducts The new products, it should contains at least one of required products
  * @return true if it can be used to send a mail
  */
 public function canBeSentTo(Etudiant $student, array $addProducts = [])
 {
     if (!$this->active) {
         return false;
     }
     // Check addProduct include in required products at least for one
     $count = 0;
     foreach ($this->forProducts as $product) {
         foreach ($addProducts as $p) {
             if ($product == $p) {
                 $count++;
                 break;
             }
         }
         if ($count > 0) {
             break;
         }
     }
     if ($count == 0 && $this->forProducts->count() != 0) {
         return false;
     }
     // Check creation date
     switch ($this->getForNewMembers()) {
         case 1:
             if ($student->getDateCreation() < new \DateTime("3 months ago")) {
                 return false;
             }
             break;
         case 2:
             if ($student->getDateCreation() >= new \DateTime("3 months ago")) {
                 return false;
             }
             break;
         case 0:
         default:
     }
     // Check if this is good year
     $valid = count($this->forYears) == 0;
     // Already valid if no condition
     foreach ($this->forYears as $year) {
         if (strval($student->getAnnee()) == strval($year)) {
             $valid = true;
         }
     }
     if (!$valid) {
         return false;
     }
     // Check department
     $valid = count($this->forDepartment) == 0;
     // Already valid if no condition
     foreach ($this->forDepartment as $department) {
         if (strval($student->getDepartement()) == strval($department)) {
             $valid = true;
         }
     }
     if (!$valid) {
         return false;
     }
     // Check products
     $valid = $this->forProducts->count() == 0;
     // Already valid if no condition
     $sum = 0;
     $produits = array_merge($student->getProducts(), $addProducts);
     foreach ($this->forProducts as $product) {
         foreach ($produits as $boughtProduct) {
             if ($product == $boughtProduct) {
                 $sum++;
             }
         }
     }
     if ($sum == $this->forProducts->count()) {
         $valid = true;
     }
     if (!$valid) {
         return false;
     }
     return true;
 }
 /**
  * Determin if the student is already registred to go to the wei
  * @param Etudiant $student
  * @return bool True if he's registered
  */
 private function _is_preregistered_for_wei(Etudiant $student)
 {
     $produitRepository = $this->get("doctrine.orm.entity_manager")->getRepository("CvaGestionMembreBundle:Produit");
     $validProducts = [$produitRepository->getCurrentWEIPreInscription(), $produitRepository->getCurrentWEIPreWaiting()];
     $intersect = array_intersect($validProducts, $student->getProducts());
     return count($intersect) > 0;
 }
 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;
 }