Пример #1
0
 /**
  * @Route("/confirmation", name="booking_step_five", schemes={"https"})
  */
 public function stepFiveAction()
 {
     $step = 5;
     $bookingUserSelection = $this->getCurrentBooking();
     if (!$bookingUserSelection->isStepValid(5) && !$bookingUserSelection->getProcessed()) {
         $this->get('session')->getFlashBag()->add('notice', 'booking.session.unvalidated');
         return $this->redirect($this->generateUrl('booking_step_one', array('bookingId' => $bookingUserSelection->getBookingId())));
     }
     $bookingManager = $this->getBookingManager();
     $hotel = $bookingManager->getHotel();
     $em = $this->getDoctrine()->getManager();
     $accentCard = '';
     $accountData = new AccountData();
     $user = null;
     if ($bookingUserSelection->getAuthMode() == BookingUserSelection::BOOKING_AUTH_MOD_NEW_ACCOUNT) {
         $newAccountData = $bookingUserSelection->getNewAccountData();
         $accountData = $newAccountData->getCustomer();
         $title = $em->getRepository('SehBundle:Customer\\Title')->find($accountData->getTitle());
         if (!$bookingUserSelection->getCreatedCustomer()) {
             $customer = new Customer();
             $customer->setTitle($title);
             $customer->setGalittTitle($title->getGalittTitle()->getValue());
             $accountData->toUser($customer);
             $customer->setLoyalty($newAccountData->getLoyalty());
             $customer->setActive(false);
             $customer->setToken(hash('sha512', $customer->getLastName() . ' ' . $customer->getFirstName() . ' ' . $customer->getEmail()));
             $em->persist($customer);
             $em->flush();
             $bookingUserSelection->setCreatedCustomer(true);
             $bookingManager->saveBookingToSession($bookingUserSelection);
             try {
                 $mailParams = $this->container->getParameter('emails');
                 $body = $this->renderView('SehBundle:mails:account_validation.html.twig', array('title' => $customer->getTitle(), 'fullName' => ucfirst($customer->getLastName()) . ' ' . ucfirst($customer->getFirstName()), 'token' => $customer->getToken(), 'subject' => '[Société Européenne d\'Hôtellerie] Validation de votre compte'));
                 $mailNewAccount = \Swift_Message::newInstance()->setContentType('text/html')->setFrom(array($mailParams['booking']['sender_mail'] => $mailParams['booking']['sender_name']))->addTo($customer->getEmail())->setSubject("[Société Européenne d'Hôtellerie] Validation de votre compte")->setBody($body);
                 $this->get('mailer')->send($mailNewAccount);
             } catch (\Exception $e) {
                 $this->container->get('logger')->error($e->getMessage());
             }
         }
     } elseif ($bookingUserSelection->getAuthMode() == BookingUserSelection::BOOKING_AUTH_MOD_LOGGED_OFF) {
         $accountData = $bookingUserSelection->getNoAccountData();
     } elseif ($bookingUserSelection->getAuthMode() == BookingUserSelection::BOOKING_AUTH_MOD_LOGGED_IN) {
         $accountData = new AccountData();
         $accountData->fromUser($user = $this->getUser());
     }
     $title = $this->getRepository('SehBundle:Customer\\Title')->find($accountData->getTitle());
     $reservationErrors = $bookingUserSelection->getReservationErrors();
     $bookingUserSelection->setReservationErrors(array());
     $bookingManager->saveBookingToSession($bookingUserSelection);
     $booking = $this->getRepository('SehBundle:Booking\\Booking')->findOneByBookingId($bookingUserSelection->getBookingId());
     if ($user) {
         $accentCard = $this->getRepository('SehBundle:Customer\\AccentCard')->findOneByUserMainCard($user);
     }
     $bookingId = $this->getRequest()->query->get('bookingId');
     $refererLinkKnowMore = '?referer=booking_step_five&bookingId=' . $bookingId;
     return $this->renderForBooking('MobileBundle:booking:step.five.html.twig', array('civility' => $title, 'customer' => $accountData, 'step' => $step, 'hotel' => $hotel, 'booking' => $booking, 'errors' => $reservationErrors, 'backLink' => $bookingManager->getReferer(), 'accentCard' => $user ? $accentCard : false, 'refererLinkKnowMore' => $refererLinkKnowMore));
 }