/**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $orders = array(array('ref' => 'AAAA', 'visitDate' => new \DateTime('2015-11-13'), 'visitDuration' => 'JOURNEE', 'validate' => false, 'tickets' => array(array('name' => 'Normal', 'longDescription' => 'De 12 ans à 59 ans', 'shortDescription' => '12 à 59 ans', 'price' => 16.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 59, 'visitor' => array('lastName' => 'DUPONT', 'firstName' => 'Alain', 'country' => 'France', 'birthdate' => new \DateTime('1970-02-17'))))))));
     foreach ($orders as $order) {
         $ticketsOrder = new TicketsOrder();
         $ticketsOrder->setRef($order['ref']);
         $ticketsOrder->setVisitDate($order['visitDate']);
         $ticketsOrder->setVisitDuration($order['visitDuration']);
         $ticketsOrder->setValidate($order['validate']);
         foreach ($order['tickets'] as $orderedTicket) {
             $ticket = new Ticket();
             $ticket->setName($orderedTicket['name']);
             $ticket->setLongDescription($orderedTicket['longDescription']);
             $ticket->setShortDescription($orderedTicket['shortDescription']);
             $ticket->setPrice($orderedTicket['price']);
             foreach ($orderedTicket['details'] as $detail) {
                 $ticketDetail = new TicketDetail();
                 $ticketDetail->setNumber($detail['number']);
                 $ticketDetail->setAgeMin($detail['ageMin']);
                 $ticketDetail->setAgeMax($detail['ageMax']);
                 $visitor = new Visitor();
                 $visitor->setLastName($detail['visitor']['lastName']);
                 $visitor->setFirstName($detail['visitor']['firstName']);
                 $visitor->setCountry($detail['visitor']['country']);
                 $visitor->setBirthdate($detail['visitor']['birthdate']);
                 $ticketDetail->setVisitor($visitor);
                 $ticket->addTicketDetail($ticketDetail);
             }
             $ticketsOrder->addTicket($ticket);
         }
         $manager->persist($ticketsOrder);
     }
     $manager->flush();
 }
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $orders = array(array('ref' => 'AD5BF6C12356981F', 'visitDate' => new \DateTime('2015-11-13'), 'visitDuration' => 'JOURNEE', 'validate' => false, 'tickets' => array(array('name' => 'Normal', 'longDescription' => 'De 12 ans à 59 ans', 'shortDescription' => '12 à 59 ans', 'price' => 16.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 59, 'visitor' => array('lastName' => 'DUPONT', 'firstName' => 'Alain', 'country' => 'France', 'birthdate' => new \DateTime('1970-02-17'))))), array('name' => 'Réduit', 'longDescription' => 'A partir de 12 ans', 'shortDescription' => 'Plus de 12 ans', 'price' => 10.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 999, 'visitor' => array('lastName' => 'DUPONT', 'firstName' => 'Hélène', 'country' => 'Belgique', 'birthdate' => new \DateTime('1967-11-12'))))))), array('ref' => 'DFE3A25C43123B2A', 'visitDate' => new \DateTime('2015-11-14'), 'visitDuration' => 'DEMI_JOURNEE', 'validate' => false, 'tickets' => array(array('name' => 'Famille', 'longDescription' => 'Famille (2 adultes et 2 enfants de même nom de famille', 'shortDescription' => 'Famille: 2adu./2enf.', 'price' => 35.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 999, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Lucien', 'country' => 'France', 'birthdate' => new \DateTime('1953-06-11'))), array('number' => 1, 'ageMin' => 12, 'ageMax' => 999, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Lucie', 'country' => 'France', 'birthdate' => new \DateTime('1959-11-06'))), array('number' => 3, 'ageMin' => 4, 'ageMax' => 11, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Paul', 'country' => 'France', 'birthdate' => new \DateTime('2004-02-06'))), array('number' => 3, 'ageMin' => 4, 'ageMax' => 11, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Claire', 'country' => 'France', 'birthdate' => new \DateTime('2007-05-15'))))))), array('ref' => 'EAABC456A234B6FA', 'visitDate' => new \DateTime('2016-01-02'), 'visitDuration' => 'JOURNEE', 'validate' => true, 'tickets' => array(array('name' => 'Sénior', 'longDescription' => 'A partir de 60 ans', 'shortDescription' => 'Plus de 60 ans', 'price' => 12.0, 'details' => array(array('number' => 1, 'ageMin' => 60, 'ageMax' => 999, 'visitor' => array('lastName' => 'MICHOU', 'firstName' => 'Michelle', 'country' => 'France', 'birthdate' => new \DateTime('1953-02-14'))))))));
     foreach ($orders as $order) {
         $ticketsOrder = new TicketsOrder();
         $ticketsOrder->setRef($order['ref']);
         $ticketsOrder->setVisitDate($order['visitDate']);
         $ticketsOrder->setVisitDuration($order['visitDuration']);
         $ticketsOrder->setValidate($order['validate']);
         foreach ($order['tickets'] as $orderedTicket) {
             $ticket = new Ticket();
             $ticket->setName($orderedTicket['name']);
             $ticket->setLongDescription($orderedTicket['longDescription']);
             $ticket->setShortDescription($orderedTicket['shortDescription']);
             $ticket->setPrice($orderedTicket['price']);
             foreach ($orderedTicket['details'] as $detail) {
                 $ticketDetail = new TicketDetail();
                 $ticketDetail->setNumber($detail['number']);
                 $ticketDetail->setAgeMin($detail['ageMin']);
                 $ticketDetail->setAgeMax($detail['ageMax']);
                 $visitor = new Visitor();
                 $visitor->setLastName($detail['visitor']['lastName']);
                 $visitor->setFirstName($detail['visitor']['firstName']);
                 $visitor->setCountry($detail['visitor']['country']);
                 $visitor->setBirthdate($detail['visitor']['birthdate']);
                 $ticketDetail->setVisitor($visitor);
                 $ticket->addTicketDetail($ticketDetail);
             }
             $ticketsOrder->addTicket($ticket);
         }
         $manager->persist($ticketsOrder);
     }
     $manager->flush();
 }
 /**
  * @View()
  * @Post("/api/v1/order.{_format}", requirements={"_format"="json, xml"}, name="post_order", defaults={"_format"="json"})
  * @RequestParam(name="visit_date", requirements="[0-9]{4}-[0-9]{2}-[0-9]{2}", description="date of the visit formatted as yyyy-mm-dd")
  * @RequestParam(name="visit_duration", requirements="(JOURNEE)|(DEMI_JOURNEE)", description="time of the visit (day or half day) : 'JOURNEE' or 'DEMI_JOURNEE'")
  * @ApiDoc(description="create an order")
  */
 public function postOrderAction(ParamFetcher $paramFetcher)
 {
     $visitDate = new DateTime($paramFetcher->get('visit_date'));
     $visitDuration = $paramFetcher->get('visit_duration');
     $validator = $this->get('app.validator');
     $validator->controlDateValidity($visitDate);
     $validator->controlTicketType($visitDuration, $visitDate);
     $order = new TicketsOrder();
     $order->setVisitDate($visitDate);
     $order->setVisitDuration($visitDuration);
     $order->setRef($this->createNewOrderRef());
     $this->saveOrder($order);
     return $order;
 }
 /**
  * @return int
  */
 private function createOrder()
 {
     $order = new TicketsOrder();
     $order->setRef('AZERTY1234AZE123');
     $order->setVisitDate(new \DateTime('2031-04-17'));
     $order->setVisitDuration('DEMI_JOURNEE');
     $this->entityManager->persist($order);
     $this->entityManager->flush();
     return $order->getId();
 }
 private function getOrder()
 {
     $order = new TicketsOrder();
     $order->setRef('AD5BF6C12356981F');
     $order->setVisitDate(new \DateTime('2015-11-13'));
     $order->setVisitDuration('JOURNEE');
     $order->setMail('*****@*****.**');
     $order->setValidate(false);
     $ticket = new Ticket();
     $ticket->setName('Normal');
     $ticket->setLongDescription('De 12 ans à 59 ans');
     $ticket->setShortDescription('12 à 59 ans');
     $ticket->setPrice(16.0);
     $detail = new TicketDetail();
     $detail->setAgeMin(12);
     $detail->setAgeMax(59);
     $visitor = new Visitor();
     $visitor->setFirstName('Alain');
     $visitor->setLastName('DUPONT');
     $visitor->setCountry('Belgique');
     $visitor->setBirthdate(new \DateTime('1970-02-17'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $order->addTicket($ticket);
     $ticket = new Ticket();
     $ticket->setName('Famille');
     $ticket->setLongDescription('Famille (2 adultes et 2 enfants de même nom de famille');
     $ticket->setShortDescription('Famille: 2adu./2enf.');
     $ticket->setPrice(35.0);
     $detail = new TicketDetail();
     $detail->setAgeMin(12);
     $detail->setAgeMax(999);
     $visitor = new Visitor();
     $visitor->setFirstName('Lucien');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('1953-06-11'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $detail = new TicketDetail();
     $detail->setAgeMin(12);
     $detail->setAgeMax(999);
     $visitor = new Visitor();
     $visitor->setFirstName('Lucie');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('1959-11-06'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $detail = new TicketDetail();
     $detail->setAgeMin(4);
     $detail->setAgeMax(11);
     $visitor = new Visitor();
     $visitor->setFirstName('Paul');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('2004-02-06'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $detail = new TicketDetail();
     $detail->setAgeMin(4);
     $detail->setAgeMax(11);
     $visitor = new Visitor();
     $visitor->setFirstName('Claire');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('2007-05-15'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $order->addTicket($ticket);
     return $order;
 }