src/Form/RDVType.php line 94

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\RDV;
  4. use App\Entity\Salon;
  5. use App\Entity\Client;
  6. use App\Entity\Product;
  7. use App\Entity\Intervenant;
  8. use App\Entity\CancelReason;
  9. use Doctrine\ORM\EntityRepository;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  13. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  18. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  19. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  21. use Symfony\Component\Security\Core\Security;
  22. class RDVType extends AbstractType
  23. {
  24.     private $security;
  25.     public function __construct(Security $security)
  26.     {
  27.         $this->security $security;
  28.     }
  29.     /**
  30.      * @param FormBuilderInterface $builder
  31.      * @param array $options
  32.      * @return void
  33.      */
  34.     public function buildForm(FormBuilderInterface $builder, array $options)
  35.     {
  36.         $intervenant =
  37.             [
  38.                 'label' => 'Choisir un intervenant',
  39.                 'class' => Intervenant::class,
  40.                 'empty_data' => '',
  41.                 'attr' => [
  42.                     'placeholder' => 'Choisir un intervenant',
  43.                 ],
  44.                 'placeholder' => 'Choisir un intervenant',
  45.                 'label_attr' => array('class' => ''),
  46.                 'required' => false
  47.             ];
  48.         if (!$options['edition']) {
  49.             $intervenant['query_builder'] = function (EntityRepository $repository) {
  50.                 $qb $repository->createQueryBuilder('i');
  51.                 // the function returns a QueryBuilder object
  52.                 return $qb
  53.                     // find all users where 'deleted' is NOT '1'
  54.                     ->where($qb->expr()->eq('i.status''?1'))
  55.                     ->setParameter('1''1')
  56.                     ->orderBy('i.lastname''ASC');
  57.             };
  58.         }
  59.         $builder
  60.             ->add('intervenant'EntityType::class, $intervenant);
  61.         $array = [
  62.             'label' => 'Choisir un produit',
  63.             'class' => Product::class,
  64.             'query_builder' => function (EntityRepository $er) {
  65.                 // the function returns a QueryBuilder object
  66.                 return $er->createQueryBuilder('p')
  67.                     ->where('p.indisponibleVente = :indisponibleVente')
  68.                     ->setParameter('indisponibleVente'0);
  69.             },
  70.             'placeholder' => 'Choisir un produit',
  71.             'multiple' => true,
  72.             'mapped' => false,
  73.             'attr' => [
  74.                 'placeholder' => 'Choisir un produit',
  75.                 'style' => 'width:100%'
  76.             ],
  77.             'label_attr' => array('class' => ''),
  78.             'choice_label' => 'name'
  79.         ];
  80.         if (isset($options['salon'])) {
  81.             /** @var Salon $salon */
  82.             $salon $options['salon'];
  83.             $array array_merge($array, [
  84.                 'query_builder' => function (EntityRepository $er) use ($salon) {
  85.                     return $er->createQueryBuilder('p')
  86.                         ->where('p.type = :type')
  87.                         ->andWhere('p.indisponibleVente = :indisponibleVente')
  88.                         ->setParameter('indisponibleVente'0)
  89.                         ->setParameter('type'$salon->getService());
  90.                 },
  91.             ]);
  92.         }
  93.         if (!isset($options['view'])) {
  94.             $builder->add('products'EntityType::class, $array);
  95.         }
  96.         $builder->add('salon'EntityType::class, [
  97.             'label' => 'Salon',
  98.             'class' => Salon::class,
  99.             'attr' => [
  100.                 'placeholder' => 'Salon',
  101.                 'readonly' => true,
  102.             ],
  103.             'placeholder' => 'Salon',
  104.             'label_attr' => array('class' => ''),
  105.         ]);
  106.         $builder->add('comment'TextareaType::class, [
  107.             'label' => 'Remarques sur RDV',
  108.             'required' => false
  109.         ]);
  110.         $builder->add('consignesClient'TextareaType::class, [
  111.             'label' => 'Consignes client',
  112.             'required' => false,
  113.             'mapped' => false,
  114.         ]);
  115.         $builder->add('roomNumber'TextType::class, [
  116.             'label' => 'Batiment / Étage / Numéro de chambre',
  117.             'attr' => [
  118.                 'placeholder' => 'Entrer le batiment / étage / numéro de chambre',
  119.             ],
  120.             'required' => false,
  121.             'mapped' => false,
  122.         ]);
  123.         $builder->add('client'EntityType::class, [
  124.             'label' => 'Choisir un client',
  125.             'placeholder' => 'Choisir un client',
  126.             'choice_label' => function (Client $client) {
  127.                 $site $client->getSite();
  128.                 $zipcode '';
  129.                 if ($site) {
  130.                     $zipcode $site->getAddress() ? $site->getAddress()->getZipcode() : '';
  131.                 }
  132.                 return $client->getLastname() . ' ' $client->getFirstname() . ' ' $zipcode;
  133.             },
  134.             'class' => Client::class,
  135.             'attr' => [
  136.                 'placeholder' => 'Choisir un client',
  137.             ],
  138.             'label_attr' => array('class' => ''),
  139.             'query_builder' => function (EntityRepository $er) {
  140.                 return $er->createQueryBuilder('c')
  141.                     ->where('(c.statusProspect != :status AND c.statusProspect != :statusParti) OR c.statusProspect IS NULL' )
  142.                     ->setParameter('status',  Client::STATUS_INACTIF)
  143.                     ->setParameter('statusParti',  'Parti');
  144.             },
  145.         ]);
  146.         $builder->add('start'DateTimeType::class, [
  147.             'widget' => 'single_text',
  148.             'required' => true,
  149.             // prevents rendering it as type="date", to avoid HTML5 date pickers
  150.             'html5' => false,
  151.             'label' => 'Début prestation',
  152.             'disabled' => $options['disabled'] ? true false,
  153.         ]);
  154.         $builder->add('hasAddService'ChoiceType::class, [
  155.             'label' => "Si votre parent souhaite un service additionnel à l’ehpad peut-il le commander ?",
  156.             'choices' => [
  157.                 'Ne sait pas' => 'Ne sait pas',
  158.                 'Oui' => 'Oui',
  159.                 'Non' => 'Non',
  160.             ],
  161.             'required' => true,
  162.         ]);
  163.         if ($options['withCustomPicker']) {
  164.             $builder->remove('start');
  165.             $builder->remove('intervenant');
  166.         }
  167.         if ($options['view'] === 'client') {
  168.             $builder->remove('start');
  169.             $builder->remove('intervenant');
  170.             $builder->remove('salon');
  171.             $builder->remove('client');
  172.             $builder->add('recurrence'ChoiceType::class, [
  173.                 'label' => 'Récurrence souhaitée',
  174.                 'choices' => [
  175.                     'Hebdomadaire' => 'hebdo',
  176.                     'Tous les 15 jours' => 'bi mensuelle',
  177.                     'Tous les mois' => 'mensuelle',
  178.                     'Tous les 2 mois' => 'bimestriel',
  179.                     'Trimestrielle' => 'trimestrielle',
  180.                     'Non, demande ponctuelle' => 'ponctuel',
  181.                 ],
  182.                 'placeholder' => 'Sélectionner',
  183.                 'required' => false,
  184.             ]);
  185.             $builder->add('email'EmailType::class, [
  186.                 'label' => "L’adresse mail de facturation",
  187.                 'mapped' => false,
  188.                 'attr' => [
  189.                     'placeholder' => 'L’adresse mail de facturation',
  190.                 ],
  191.                 'required' => true,
  192.             ]);
  193.             $builder->add('civilite'ChoiceType::class, [
  194.                 'label' => 'Civilité bénéficiaire de la prestation',
  195.                 'mapped' => false,
  196.                 'attr' => [
  197.                     'placeholder' => 'Civilité bénéficiaire de la prestation',
  198.                 ],
  199.                 'required' => true,
  200.                 'placeholder' => 'Choisir une civilite',
  201.                 'choices'  => [
  202.                     'Madame' => 'Madame',
  203.                     'Monsieur' => 'Monsieur',
  204.                 ],
  205.             ]);
  206.             $builder->add('lastname'null, [
  207.                 'label' => "Nom bénéficiaire de la prestation",
  208.                 'mapped' => false,
  209.                 'attr' => [
  210.                     'placeholder' => 'Nom bénéficiaire de la prestation',
  211.                 ],
  212.                 'required' => true,
  213.             ]);
  214.             $builder->add('firstname'null, [
  215.                 'label' => "Prénom bénéficiaire de la prestation",
  216.                 'mapped' => false,
  217.                 'attr' => [
  218.                     'placeholder' => 'Prénom bénéficiaire de la prestation',
  219.                 ],
  220.                 'required' => true,
  221.             ]);
  222.         }
  223.         if (isset($options['edition']) && $options['edition'] === true) {
  224.             $builder->add('start'DateTimeType::class, [
  225.                 'widget' => 'single_text',
  226.                 // prevents rendering it as type="date", to avoid HTML5 date pickers
  227.                 'html5' => false,
  228.                 'label' => 'Début prestation',
  229.                 'disabled' => $options['disabled'] ? true false,
  230.             ]);
  231.             $builder->add('end'DateTimeType::class, [
  232.                 'widget' => 'single_text',
  233.                 'html5' => false,
  234.                 'label' => 'Fin prestation',
  235.             ]);
  236.             $builder->add('priorite'ChoiceType::class, [
  237.                 'label' => 'Priorité',
  238.                 'choices' => [
  239.                     '1' => 1,
  240.                     '2' => 2,
  241.                     '3' => 3
  242.                 ]
  243.             ]);
  244.             $canValidate $options['canValidate'];
  245.             $choices = [
  246.                 'Planifié' => RDV::STATUS_PLANIFIER,
  247.                 'Annulé' => RDV::STATUS_ANNULER,
  248.                 'Validé' => RDV::STATUS_VALIDATED,
  249.                 //'Replanifié' => RDV::STATUS_REPLANIFIER,
  250.                 'Facturé' => RDV::STATUS_FACTURER,
  251.                 //'Reporté' => RDV::STATUS_REPORTE,
  252.                 // 'Facture annulé' => RDV::STATUS_FACTURE_ANNULER,
  253.             ];
  254.             /*if ($options['hideFacture']) {
  255.                 unset($choices['Facturé']);
  256.             }*/
  257.             $optionsStatus = [
  258.                 'label' => 'Statut',
  259.                 'choices' => $choices
  260.             ];
  261.             if ($canValidate === false) {
  262.                 $optionsStatus = [
  263.                     'label' => 'Statut',
  264.                     'choices' => $choices,
  265.                     'choice_attr' => function ($choice$key$value) {
  266.                         if ($value === 'billing') {
  267.                             return ['disabled' => 'disabled'];
  268.                         }
  269.                         return [];
  270.                     },
  271.                 ];
  272.             }
  273.             if($options['canChangeStatus'] === false){
  274.                 $optionsStatus = [
  275.                     'label' => 'Statut',
  276.                     'choices' => $choices,
  277.                     'choice_attr' => function ($choice$key$value) {
  278.                             return ['disabled' => 'disabled'];
  279.                     },
  280.                 ];
  281.             }
  282.             $builder->add('status'ChoiceType::class, $optionsStatus);
  283.             $builder->add('author'TextType::class, [
  284.                 'label' => 'Prise de RDV par',
  285.                 'disabled' => true,
  286.                 'attr' => [
  287.                     'placeholder' => $options['createdFrom'],
  288.                 ],
  289.             ]);
  290.             //                $builder ->add('validate', CheckboxType::class, [
  291.             //                    'label' => 'RDV Valider',
  292.             //                    'mapped' => false,
  293.             //                    'required' => false
  294.             //                ]);
  295.             $builder->add('comment'TextareaType::class, [
  296.                 'label' => 'Remarques sur RDV',
  297.                 'required' => false
  298.             ]);
  299.             $builder->add('commentForfait'TextareaType::class, [
  300.                 'label' => 'Remarques forfait',
  301.                 'required' => false,
  302.                 'label_attr' => [
  303.                     'style' => 'display:none',
  304.                 ],
  305.                 'attr' => [
  306.                     'style' => 'display:none',
  307.                 ],
  308.             ]);
  309.             $builder->add('cancelReason'EntityType::class, [
  310.                 'label' => 'Choisir un motif d\'annulation',
  311.                 'class' => CancelReason::class,
  312.                 'placeholder' => 'Choisir un motif d\'annulation',
  313.                 'required' => false,
  314.                 'attr' => [
  315.                     'placeholder' => 'Choisir un motif d\'annulation',
  316.                 ],
  317.                 'label_attr' => array('class' => ''),
  318.             ]);
  319.             $builder->add('recurrence'null, [
  320.                 'label' => 'Récurrence saisie par le client (espace réservation)',
  321.                 'disabled' => true,
  322.             ]);
  323.         } else {
  324.             //                $builder->add('start',HiddenType::class, [
  325.             //                ]);
  326.             $builder->add('end'HiddenType::class, []);
  327.             $builder->add('priorite'HiddenType::class, []);
  328.             $builder->add('status'HiddenType::class, []);
  329.         };
  330.     }
  331.     public function configureOptions(OptionsResolver $resolver)
  332.     {
  333.         $resolver->setDefaults([
  334.             'data_class' => RDV::class,
  335.             'edition' => false,
  336.             'salon' => null,
  337.             'canValidate' => false,
  338.             'view' => null,
  339.             'famille' => null,
  340.             'productIds' => null,
  341.             'allow_extra_fields' => true,
  342.             'createdFrom' => null,
  343.             'hideFacture' => false,
  344.             'csrf_protection' => true,
  345.             'csrf_field_name' => '_token',
  346.             // important part; unique key
  347.             'csrf_token_id'   => 'form_intention',
  348.             'withCustomPicker' => false,
  349.             'canChangeStatus' => true
  350.         ]);
  351.     }
  352. }