示例#1
0
 public function generateMailFromData(Mail $mail, Student $student)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array(['mail.' . $mail->getId() => $mail->getContent()]), array('autoescape' => false));
     $subject = $mail->getSubject();
     $message = $this->_twig->render("@BdEMain/Mail/bde.html.twig", array('content' => $twig->render("mail." . $mail->getId(), array('student' => $student)), 'config' => array('title' => $mail->getSubject(), 'company' => "BdE INSA Lyon", 'student' => $student, 'mail_id' => $this->_crypt_data($mail->getId(), $student->getId())), 'why_this_mail' => ""));
     return ['subject' => $subject, 'body' => $message];
 }
示例#2
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;
 }
示例#3
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;
 }
 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));
 }
 /**
  * @Route(path="/import", name="cva_membership_payments_import")
  * @param Request $request
  * @return \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function importAction(Request $request)
 {
     if ($request->isMethod('POST')) {
         $out = "";
         $var = $request->request->get('students');
         $em = $this->get('doctrine.orm.entity_manager');
         $em->beginTransaction();
         $product = $em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentVA()[0];
         $out .= '<b>Importation de ' . count($var) . ' étudiant(s) :</b><br>';
         if ($var != null) {
             foreach ($var as $student) {
                 if ($student['student'] == '') {
                     $out .= '<span class="text-error">' . $student['firstname'] . ' ' . $student['lastname'] . ' (' . $student['mail'] . ') est déjà adhérant</span><br>';
                     continue;
                 }
                 $new = false;
                 $r = $em->getRepository("CvaGestionMembreBundle:Etudiant")->findOneBy(array('numEtudiant' => $student['student']));
                 if ($r == null) {
                     $r = new Etudiant();
                     $r->setFirstName($student['firstname']);
                     $r->setName($student['lastname']);
                     $r->setCivilite($student['sex']);
                     $r->setMail($student['mail']);
                     $r->setNumEtudiant($student['student']);
                     if ($student['birthday'] != null) {
                         $birthday = new \DateTime();
                         $birthday->setTimestamp(strtotime($student['birthday']));
                         $r->setBirthday($birthday);
                     }
                     $new = true;
                 } else {
                     $c = $em->getRepository("CvaGestionMembreBundle:Payment")->createQueryBuilder('p')->select('COUNT(p.id)')->where('p.student = ?1')->andWhere('p.product IN (?2)')->setParameter(1, $r)->setParameter(2, $em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentVAIds())->getQuery()->getSingleScalarResult();
                     if ($c > 0) {
                         $out .= '<span class="text-warning">' . $r . ' (' . $r->getNumEtudiant() . ') est déjà adhérant</span><br>';
                         continue;
                     }
                 }
                 $r->setAnnee($student['year']);
                 $r->setDepartement($student['depart']);
                 $em->persist($r);
                 $payment = Payment::generate($r, $product, $student['payment']);
                 $em->persist($payment);
                 $out .= '<span class="text-' . ($new ? 'success' : 'info') . '">' . $r . ' (' . $r->getNumEtudiant() . ')' . ($new ? ' a été créé et' : '') . ' a acheté le produit ' . $product->getName() . '</span><br>';
             }
         }
         $em->flush();
         $em->commit();
         return $this->render("CvaGestionMembreBundle:Payments:importResult.html.twig", array('out' => $out));
     } else {
         return $this->render("CvaGestionMembreBundle:Payments:import.html.twig");
     }
 }
示例#6
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;
 }
 /**
  * @param Request $request
  * @param $student
  * @return \Symfony\Component\Form\Form|Response
  */
 public function handleAffectationForm(Request $request, Etudiant $student)
 {
     $em = $this->get('doctrine.orm.entity_manager');
     $busNotFull = $em->getRepository("BdEWeiBundle:Bus")->getAllNotFull();
     if ($student->getBus() != null && !in_array($student->getBus(), $busNotFull)) {
         $busNotFull[] = $student->getBus();
     }
     $affectation = $this->createFormBuilder($student, ['action' => $this->generateUrl("bde_wei_registration_sidebar", array('id' => $student->getId()))]);
     $affectation->add('bus', 'entity', ['class' => 'BdE\\WeiBundle\\Entity\\Bus', 'choices' => $busNotFull, 'choice_label' => function (Bus $bus) {
         return $bus->getNom() . ' (' . $bus->getAmountOfRegisteredEtudiants() . '/' . $bus->getNbPlaces() . ')';
     }, 'required' => false]);
     if ($student->getBus()) {
         $bungalowNotFull = $em->getRepository("BdEWeiBundle:Bungalow")->getAllNotFullByGender($student->getCivilite());
         if ($student->getBungalow() != null && !in_array($student->getBungalow(), $bungalowNotFull)) {
             $bungalowNotFull[] = $student->getBungalow();
         }
         $affectation->add('bungalow', 'entity', ['class' => 'BdE\\WeiBundle\\Entity\\Bungalow', 'choices' => $bungalowNotFull, 'choice_label' => function (Bungalow $bungalow) {
             return $bungalow->getNom() . ' (' . $bungalow->getAmountOfRegisteredEtudiants() . '/' . $bungalow->getNbPlaces() . ')';
         }, 'required' => false]);
     }
     $affectation->add('actions', 'form_actions', ['buttons' => ['save' => ['type' => 'submit', 'options' => ['label' => 'button.save', 'attr' => ['class' => 'btn-block']]]]]);
     $affectation = $affectation->getForm();
     $affectation->handleRequest($request);
     if ($affectation->isValid()) {
         $data = $affectation->getData();
         $em->persist($data);
         $em->flush();
         $this->addFlash("success", "Etudiant affecté");
         return $this->redirectToRoute("bde_wei_registration_index");
     }
     return $affectation;
 }
示例#10
0
 /**
  * @param Etudiant $etudiant
  * @return Bus
  */
 public function getBusForEtudiant(Etudiant $etudiant)
 {
     $qb = $this->createQueryBuilder('b');
     $qb->join('b.students', 'e', 'e.id = :e_id')->setParameter("e_id", $etudiant->getId());
     return $qb->getQuery()->getOneOrNullResult();
 }