Пример #1
0
 public function generateMailFromData(Mail $mail, Participant $participant)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array(['mail.' . $mail->getId() => $mail->getMessage()]), array('autoescape' => false));
     $subject = $mail->getObject();
     $message = $this->_twig->render("@BdeRevent/Mail/mail.html.twig", array('content' => $twig->render("mail." . $mail->getId(), array('participant' => $participant, 'link' => $this->_website . $this->_router->generate("return_mail", array('key' => $this->_service->crypt_data($participant->getId()))))), 'config' => array()));
     return ['subject' => $subject, 'body' => $message];
 }
 /**
  * @Route("/{key}/invite", name="invite")
  * @Template()
  */
 public function inviteAction(Request $request, $key)
 {
     $id = $this->get("bde.revent.token_service")->decrypt_data($key);
     if ($id == null) {
         return $this->render('@BdeRevent/InviteController/deny.html.twig');
     }
     $em = $this->get("doctrine.orm.entity_manager");
     $participant = $em->getRepository("BdeReventBundle:Participant")->find($id);
     if ($participant == null) {
         return $this->render('@BdeRevent/InviteController/deny.html.twig');
     }
     if (!$participant->getUsed()) {
         return $this->redirectToRoute('return_mail', array('key' => $key));
     }
     if ($participant->getType()->getCanInvite()) {
         $max_invites = 7;
         $weezevent_invites = $participant->getGuestsByWeezevent();
         $max_invites -= $weezevent_invites;
         $addable_invites = $max_invites - $participant->getGuests()->count();
         $form = new InviteForm($this->createFormBuilder()->getFormConfig(), $addable_invites);
         if ($request->isMethod('POST')) {
             $form->handleRequest($request);
             if ($form->isValid()) {
                 $all_ok = true;
                 foreach ($form->getData() as $data) {
                     $check = $data['firstname'] . $data['lastname'] . $data['email'];
                     if ($check == "") {
                         continue;
                         // Do not handle an empty invite
                     }
                     if ($em->getRepository('BdeReventBundle:Participant')->findOneBy(array('email' => $data['email']))) {
                         $this->addFlash('info', htmlspecialchars($data['firstname']) . " (" . $data['email'] . ") est déjà invité au gala");
                         continue;
                     }
                     $guest = new Participant();
                     $guest->setFirstName($data['firstname']);
                     $guest->setLastName($data['lastname']);
                     $guest->setEmail($data['email']);
                     /** @noinspection PhpUndefinedMethodInspection */
                     $guest->setType($em->getRepository("BdeReventBundle:Type")->findOneByName('Invité'));
                     $guest->setInvitedBy($participant);
                     $em->persist($guest);
                     $em->flush($guest);
                     $this->get('bde.main.mailer_service')->send($guest);
                     $this->addFlash('success', htmlspecialchars($data['firstname']) . " (" . $data['email'] . ") a été invité");
                 }
                 return $this->redirectToRoute("invite", array('key' => $key));
             }
         }
         $formView = $form->createView();
         return array('participant' => $participant, 'token' => $key, 'invited' => $max_invites - $addable_invites + $weezevent_invites, 'form' => $formView, 'errors' => $form->getErrors(true, 2));
     } else {
         return $this->render('@BdeRevent/InviteController/can_not_invite.html.twig');
     }
 }
Пример #3
0
 public function getToken(Participant $participant)
 {
     return $this->token->crypt_data($participant->getId());
 }
 /**
  * @Route("/import")
  * @Template()
  */
 public function importAction(Request $request)
 {
     if ($request->isMethod("POST")) {
         $em = $this->get("doctrine.orm.entity_manager");
         $status = 1;
         try {
             $data = $request->get("data");
             foreach ($data as $guest) {
                 $participant = new Participant();
                 $participant->setType($em->getRepository("BdeReventBundle:Type")->findOneByName('Diplômé'));
                 $participant->setEmail($guest['email']);
                 $participant->setFirstName($guest['firstname']);
                 $participant->setLastName($guest['lastname']);
                 $em->persist($participant);
                 $em->flush($participant);
                 $this->get('bde.main.mailer_service')->send($participant);
             }
         } catch (Exception $e) {
             $status = 0;
         }
         echo $status;
         exit;
     }
     return array();
 }