<?php
namespace App\MDS\GreenPatioBundle\Form;
use App\Entity\Client;
use App\Entity\Supplier;
use App\MDS\GreenPatioBundle\Entity\Reservation;
use App\Repository\SupplierRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
class ReservationType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $builder->getData(); // usado para ->add('cateringName', EntityType::class, array(
// $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
// $builder->addEventListener(FormEvents::PRE_SUBMIT, array($this, 'onPreSubmit'));
$builder
->add('title', TextType::class, array(
'required' => true))
// ->add('createdAt')
// ->add('createdBy', TextType::class, array(
// 'required' => false))
// ->add('supplier', TextType::class, array(
// 'required' => false))
// ->add('status')
->add('status', ChoiceType::class, array(
'required' => false,
'choices' => array(
'Iniciado' => 'Iniciado',
'Bloqueo' => 'Bloqueo',
'Confirmado' => 'Confirmed',
'Cotizado' => 'Cotizado',
'Facturado' => 'Invoiced'
), 'placeholder' => 'Select a status'))
->add('priority', ChoiceType::class, array(
'required' => false,
'choices' => array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'10' => '10'
), 'placeholder' => 'Auto'))
->add('client', EntityType::class, array(
'required' => false,
'class' => Client::class,
'choice_label' => 'name',
'choice_value' => 'id',
'expanded' => false,
'multiple' => false,
'placeholder' => 'Select a Client'))
->add('clientContact', HiddenType::class)
->add('contactUnregistered', HiddenType::class)
->add('days', HiddenType::class)
->add('cateringName', EntityType::class, array(
'class' => Supplier::class,
'choice_label' => 'name',
'choice_value' => 'id',
'required' => false,
'multiple' => false,
'placeholder' => 'Select a Supplier',
'query_builder' => function (SupplierRepository $er) use ($data) {
$qb = $er->createQueryBuilder('e')
->where('e.tags like :manufacturer')
->setParameter('manufacturer', 'catering');
return $qb->orderBy('e.company');
}
))
->add('advancePayment', IntegerType::class, array(
'required' => false))
->add('daysBlock', IntegerType::class, array(
'required' => false))
->add('idProposal', IntegerType::class, array(
'required' => false))
->add('pax', IntegerType::class, array(
'required' => false))
->add('deposit', IntegerType::class, array(
'required' => false))
->add('description', TextareaType::class, array(
'required' => false))
->add('save', SubmitType::class);
}
//
// protected function addElements(FormInterface $form, Period $period = null) {
// // 4. Add the province element
// $form->add('jornada', EntityType::class, array(
// 'required' => true,
// 'data' => $period,
// 'placeholder' => 'Select a Period...',
// 'class' => 'GreenPatioBundle:Period'
// ));
//
// // Neighborhoods empty, unless there is a selected City (Edit View)
// $lounges = array();
//
// // If there is a city stored in the Person entity, load the neighborhoods of it
// if ($period) {
// // Fetch Neighborhoods of the City if there's a selected city
// $repoLoungesProfile = $this->em->getRepository(ReservationLoungeProfile::class);
//
// $profiles = $repoLoungesProfile->createQueryBuilder("p")
// ->where("p.periodId = :periodId")
// ->setParameter("periodId", $period->getId())
// ->getQuery()
// ->getResult();
// }
//
// // Add the profiles field with the properly data
// $form->add('profiles', EntityType::class, array(
// 'required' => true,
// 'placeholder' => 'Select a Period first ...',
// 'class' => ReservationLoungeProfile::class,
// 'choices' => $profiles
// ));
// }
//
// function onPreSubmit(FormEvent $event) {
// $form = $event->getForm();
// $data = $event->getData();
//
// // Search for selected City and convert it into an Entity
// $period = $this->em->getRepository('GreenPatioBundle:Period')->find($data['jornada']);
//
// $this->addElements($form, $period);
// }
//
// function onPreSetData(FormEvent $event) {
// $reservation = $event->getData();
// $form = $event->getForm();
//
// // When you create a new reservation, the period is always empty
// $city = $reservation->getCity() ? $person->getCity() : null;
//
// $this->addElements($form, $city);
// }
//
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Reservation::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'mds_greenpatiobundle_reservation';
}
}