src/MDS/GreenPatioBundle/Form/ReservationType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\MDS\GreenPatioBundle\Form;
  3. use App\Entity\Client;
  4. use App\Entity\Supplier;
  5. use App\MDS\GreenPatioBundle\Entity\Reservation;
  6. use App\Repository\SupplierRepository;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  16. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  17. class ReservationType extends AbstractType
  18. {
  19.     /**
  20.      * {@inheritdoc}
  21.      */
  22.     public function buildForm(FormBuilderInterface $builder, array $options)
  23.     {
  24.         $data $builder->getData();            // usado para  ->add('cateringName', EntityType::class, array(
  25. //        $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
  26. //        $builder->addEventListener(FormEvents::PRE_SUBMIT, array($this, 'onPreSubmit'));
  27.         $builder
  28.             ->add('title'TextType::class, array(
  29.                 'required' => true))
  30. //            ->add('createdAt')
  31. //            ->add('createdBy', TextType::class, array(
  32. //                'required' => false))
  33. //            ->add('supplier', TextType::class, array(
  34. //                'required' => false))
  35. //            ->add('status')
  36.             ->add('status'ChoiceType::class, array(
  37.                 'required' => false,
  38.                 'choices' => array(
  39.                     'Iniciado' => 'Iniciado',
  40.                     'Bloqueo' => 'Bloqueo',
  41.                     'Confirmado' => 'Confirmed',
  42.                     'Cotizado' => 'Cotizado',
  43.                     'Facturado' => 'Invoiced'
  44.                 ), 'placeholder' => 'Select a status'))
  45.             ->add('priority'ChoiceType::class, array(
  46.                 'required' => false,
  47.                 'choices' => array(
  48.                     '1' => '1',
  49.                     '2' => '2',
  50.                     '3' => '3',
  51.                     '4' => '4',
  52.                     '5' => '5',
  53.                     '6' => '6',
  54.                     '7' => '7',
  55.                     '8' => '8',
  56.                     '9' => '9',
  57.                     '10' => '10'
  58.                 ), 'placeholder' => 'Auto'))
  59.             ->add('client'EntityType::class, array(
  60.                 'required' => false,
  61.                 'class' => Client::class,
  62.                 'choice_label' => 'name',
  63.                 'choice_value' => 'id',
  64.                 'expanded' => false,
  65.                 'multiple' => false,
  66.                 'placeholder' => 'Select a Client'))
  67.             ->add('clientContact'HiddenType::class)
  68.             ->add('contactUnregistered'HiddenType::class)
  69.             ->add('days'HiddenType::class)
  70.             ->add('cateringName'EntityType::class, array(
  71.                 'class' => Supplier::class,
  72.                 'choice_label' => 'name',
  73.                 'choice_value' => 'id',
  74.                 'required' => false,
  75.                 'multiple' => false,
  76.                 'placeholder' => 'Select a Supplier',
  77.                 'query_builder' => function (SupplierRepository $er) use ($data) {
  78.                     $qb $er->createQueryBuilder('e')
  79.                         ->where('e.tags like :manufacturer')
  80.                         ->setParameter('manufacturer''catering');
  81.                     return $qb->orderBy('e.company');
  82.                 }
  83.                 ))
  84.             ->add('advancePayment'IntegerType::class, array(
  85.                 'required' => false))
  86.             ->add('daysBlock'IntegerType::class, array(
  87.                 'required' => false))
  88.             ->add('idProposal'IntegerType::class, array(
  89.                 'required' => false))
  90.             ->add('pax'IntegerType::class, array(
  91.                 'required' => false))
  92.             ->add('deposit'IntegerType::class, array(
  93.                 'required' => false))
  94.             ->add('description'TextareaType::class, array(
  95.                 'required' => false))
  96.             ->add('save'SubmitType::class);
  97.     }
  98. //
  99. //    protected function addElements(FormInterface $form, Period $period = null) {
  100. //        // 4. Add the province element
  101. //        $form->add('jornada', EntityType::class, array(
  102. //            'required' => true,
  103. //            'data' => $period,
  104. //            'placeholder' => 'Select a Period...',
  105. //            'class' => 'GreenPatioBundle:Period'
  106. //        ));
  107. //
  108. //        // Neighborhoods empty, unless there is a selected City (Edit View)
  109. //        $lounges = array();
  110. //
  111. //        // If there is a city stored in the Person entity, load the neighborhoods of it
  112. //        if ($period) {
  113. //            // Fetch Neighborhoods of the City if there's a selected city
  114. //            $repoLoungesProfile = $this->em->getRepository(ReservationLoungeProfile::class);
  115. //
  116. //            $profiles = $repoLoungesProfile->createQueryBuilder("p")
  117. //                ->where("p.periodId = :periodId")
  118. //                ->setParameter("periodId", $period->getId())
  119. //                ->getQuery()
  120. //                ->getResult();
  121. //        }
  122. //
  123. //        // Add the profiles field with the properly data
  124. //        $form->add('profiles', EntityType::class, array(
  125. //            'required' => true,
  126. //            'placeholder' => 'Select a Period first ...',
  127. //            'class' => ReservationLoungeProfile::class,
  128. //            'choices' => $profiles
  129. //        ));
  130. //    }
  131. //
  132. //    function onPreSubmit(FormEvent $event) {
  133. //        $form = $event->getForm();
  134. //        $data = $event->getData();
  135. //
  136. //        // Search for selected City and convert it into an Entity
  137. //        $period = $this->em->getRepository('GreenPatioBundle:Period')->find($data['jornada']);
  138. //
  139. //        $this->addElements($form, $period);
  140. //    }
  141. //
  142. //    function onPreSetData(FormEvent $event) {
  143. //        $reservation = $event->getData();
  144. //        $form = $event->getForm();
  145. //
  146. //        // When you create a new reservation, the period is always empty
  147. //        $city = $reservation->getCity() ? $person->getCity() : null;
  148. //
  149. //        $this->addElements($form, $city);
  150. //    }
  151. //
  152.     
  153.     /**
  154.      * {@inheritdoc}
  155.      */
  156.     public function configureOptions(OptionsResolver $resolver)
  157.     {
  158.         $resolver->setDefaults(array(
  159.             'data_class' => Reservation::class
  160.         ));
  161.     }
  162.     /**
  163.      * {@inheritdoc}
  164.      */
  165.     public function getBlockPrefix()
  166.     {
  167.         return 'mds_greenpatiobundle_reservation';
  168.     }
  169. }