src/Form/RDVType.php line 142

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.             ],
  102.             'placeholder' => 'Salon',
  103.             'label_attr' => array('class' => ''),
  104.         ]);
  105.         $builder->add('comment'TextareaType::class, [
  106.             'label' => 'Remarques sur RDV',
  107.             'required' => false
  108.         ]);
  109.         $builder->add('consignesClient'TextareaType::class, [
  110.             'label' => 'Consignes client',
  111.             'required' => false,
  112.             'mapped' => false,
  113.         ]);
  114.         $builder->add('roomNumber'TextType::class, [
  115.             'label' => 'Batiment / Étage / Numéro de chambre',
  116.             'attr' => [
  117.                 'placeholder' => 'Entrer le batiment / étage / numéro de chambre',
  118.             ],
  119.             'required' => false,
  120.             'mapped' => false,
  121.         ]);
  122.         $builder->add('client'EntityType::class, [
  123.             'label' => 'Choisir un client',
  124.             'placeholder' => 'Choisir un client',
  125.             'choice_label' => function (Client $client) {
  126.                 $site $client->getSite();
  127.                 $zipcode '';
  128.                 if ($site) {
  129.                     $zipcode $site->getAddress() ? $site->getAddress()->getZipcode() : '';
  130.                 }
  131.                 return $client->getLastname() . ' ' $client->getFirstname() . ' ' $zipcode;
  132.             },
  133.             'class' => Client::class,
  134.             'attr' => [
  135.                 'placeholder' => 'Choisir un client',
  136.             ],
  137.             'label_attr' => array('class' => ''),
  138.             'query_builder' => function (EntityRepository $er) {
  139.                 return $er->createQueryBuilder('c')
  140.                     ->where('(c.statusProspect != :status AND c.statusProspect != :statusParti) OR c.statusProspect IS NULL' )
  141.                     ->setParameter('status',  Client::STATUS_INACTIF)
  142.                     ->setParameter('statusParti',  'Parti');
  143.             },
  144.         ]);
  145.         $builder->add('start'DateTimeType::class, [
  146.             'widget' => 'single_text',
  147.             'required' => true,
  148.             // prevents rendering it as type="date", to avoid HTML5 date pickers
  149.             'html5' => false,
  150.             'label' => 'Début prestation',
  151.             'disabled' => $options['disabled'] ? true false,
  152.         ]);
  153.         $builder->add('hasAddService'ChoiceType::class, [
  154.             'label' => "Si votre parent souhaite un service additionnel à l’ehpad peut-il le commander ?",
  155.             'choices' => [
  156.                 'Ne sait pas' => 'Ne sait pas',
  157.                 'Oui' => 'Oui',
  158.                 'Non' => 'Non',
  159.             ],
  160.             'required' => true,
  161.         ]);
  162.         if ($options['withCustomPicker']) {
  163.             $builder->remove('start');
  164.             $builder->remove('intervenant');
  165.         }
  166.         if ($options['view'] === 'client') {
  167.             $builder->remove('start');
  168.             $builder->remove('intervenant');
  169.             $builder->remove('salon');
  170.             $builder->remove('client');
  171.             $builder->add('recurrence'ChoiceType::class, [
  172.                 'label' => 'Récurrence souhaitée',
  173.                 'choices' => [
  174.                     'Hebdomadaire' => 'hebdo',
  175.                     'Tous les 15 jours' => 'bi mensuelle',
  176.                     'Tous les mois' => 'mensuelle',
  177.                     'Tous les 2 mois' => 'bimestriel',
  178.                     'Trimestrielle' => 'trimestrielle',
  179.                     'Non, demande ponctuelle' => 'ponctuel',
  180.                 ],
  181.                 'placeholder' => 'Sélectionner',
  182.                 'required' => false,
  183.             ]);
  184.             $builder->add('email'EmailType::class, [
  185.                 'label' => "L’adresse mail de facturation",
  186.                 'mapped' => false,
  187.                 'attr' => [
  188.                     'placeholder' => 'L’adresse mail de facturation',
  189.                 ],
  190.                 'required' => true,
  191.             ]);
  192.             $builder->add('civilite'ChoiceType::class, [
  193.                 'label' => 'Civilité bénéficiaire de la prestation',
  194.                 'mapped' => false,
  195.                 'attr' => [
  196.                     'placeholder' => 'Civilité bénéficiaire de la prestation',
  197.                 ],
  198.                 'required' => true,
  199.                 'placeholder' => 'Choisir une civilite',
  200.                 'choices'  => [
  201.                     'Madame' => 'Madame',
  202.                     'Monsieur' => 'Monsieur',
  203.                 ],
  204.             ]);
  205.             $builder->add('lastname'null, [
  206.                 'label' => "Nom bénéficiaire de la prestation",
  207.                 'mapped' => false,
  208.                 'attr' => [
  209.                     'placeholder' => 'Nom bénéficiaire de la prestation',
  210.                 ],
  211.                 'required' => true,
  212.             ]);
  213.             $builder->add('firstname'null, [
  214.                 'label' => "Prénom bénéficiaire de la prestation",
  215.                 'mapped' => false,
  216.                 'attr' => [
  217.                     'placeholder' => 'Prénom bénéficiaire de la prestation',
  218.                 ],
  219.                 'required' => true,
  220.             ]);
  221.         }
  222.         if (isset($options['edition']) && $options['edition'] === true) {
  223.             $builder->add('start'DateTimeType::class, [
  224.                 'widget' => 'single_text',
  225.                 // prevents rendering it as type="date", to avoid HTML5 date pickers
  226.                 'html5' => false,
  227.                 'label' => 'Début prestation',
  228.                 'disabled' => $options['disabled'] ? true false,
  229.             ]);
  230.             $builder->add('end'DateTimeType::class, [
  231.                 'widget' => 'single_text',
  232.                 'html5' => false,
  233.                 'label' => 'Fin prestation',
  234.             ]);
  235.             $builder->add('priorite'ChoiceType::class, [
  236.                 'label' => 'Priorité',
  237.                 'choices' => [
  238.                     '1' => 1,
  239.                     '2' => 2,
  240.                     '3' => 3
  241.                 ]
  242.             ]);
  243.             $canValidate $options['canValidate'];
  244.             $choices = [
  245.                 'Planifié' => RDV::STATUS_PLANIFIER,
  246.                 'Annulé' => RDV::STATUS_ANNULER,
  247.                 'Validé' => RDV::STATUS_VALIDATED,
  248.                 //'Replanifié' => RDV::STATUS_REPLANIFIER,
  249.                 'Facturé' => RDV::STATUS_FACTURER,
  250.                 //'Reporté' => RDV::STATUS_REPORTE,
  251.                 // 'Facture annulé' => RDV::STATUS_FACTURE_ANNULER,
  252.             ];
  253.             /*if ($options['hideFacture']) {
  254.                 unset($choices['Facturé']);
  255.             }*/
  256.             $optionsStatus = [
  257.                 'label' => 'Statut',
  258.                 'choices' => $choices
  259.             ];
  260.             if ($canValidate === false) {
  261.                 $optionsStatus = [
  262.                     'label' => 'Statut',
  263.                     'choices' => $choices,
  264.                     'choice_attr' => function ($choice$key$value) {
  265.                         if ($value === 'billing') {
  266.                             return ['disabled' => 'disabled'];
  267.                         }
  268.                         return [];
  269.                     },
  270.                 ];
  271.             }
  272.             if($options['canChangeStatus'] === false){
  273.                 $optionsStatus = [
  274.                     'label' => 'Statut',
  275.                     'choices' => $choices,
  276.                     'choice_attr' => function ($choice$key$value) {
  277.                             return ['disabled' => 'disabled'];
  278.                     },
  279.                 ];
  280.             }
  281.             $builder->add('status'ChoiceType::class, $optionsStatus);
  282.             $builder->add('author'TextType::class, [
  283.                 'label' => 'Prise de RDV par',
  284.                 'disabled' => true,
  285.                 'attr' => [
  286.                     'placeholder' => $options['createdFrom'],
  287.                 ],
  288.             ]);
  289.             //                $builder ->add('validate', CheckboxType::class, [
  290.             //                    'label' => 'RDV Valider',
  291.             //                    'mapped' => false,
  292.             //                    'required' => false
  293.             //                ]);
  294.             $builder->add('comment'TextareaType::class, [
  295.                 'label' => 'Remarques sur RDV',
  296.                 'required' => false
  297.             ]);
  298.             $builder->add('commentForfait'TextareaType::class, [
  299.                 'label' => 'Remarques forfait',
  300.                 'required' => false,
  301.                 'label_attr' => [
  302.                     'style' => 'display:none',
  303.                 ],
  304.                 'attr' => [
  305.                     'style' => 'display:none',
  306.                 ],
  307.             ]);
  308.             $builder->add('cancelReason'EntityType::class, [
  309.                 'label' => 'Choisir un motif d\'annulation',
  310.                 'class' => CancelReason::class,
  311.                 'placeholder' => 'Choisir un motif d\'annulation',
  312.                 'required' => false,
  313.                 'attr' => [
  314.                     'placeholder' => 'Choisir un motif d\'annulation',
  315.                 ],
  316.                 'label_attr' => array('class' => ''),
  317.             ]);
  318.             $builder->add('recurrence'null, [
  319.                 'label' => 'Récurrence saisie par le client (espace réservation)',
  320.                 'disabled' => true,
  321.             ]);
  322.         } else {
  323.             //                $builder->add('start',HiddenType::class, [
  324.             //                ]);
  325.             $builder->add('end'HiddenType::class, []);
  326.             $builder->add('priorite'HiddenType::class, []);
  327.             $builder->add('status'HiddenType::class, []);
  328.         };
  329.     }
  330.     public function configureOptions(OptionsResolver $resolver)
  331.     {
  332.         $resolver->setDefaults([
  333.             'data_class' => RDV::class,
  334.             'edition' => false,
  335.             'salon' => null,
  336.             'canValidate' => false,
  337.             'view' => null,
  338.             'famille' => null,
  339.             'productIds' => null,
  340.             'allow_extra_fields' => true,
  341.             'createdFrom' => null,
  342.             'hideFacture' => false,
  343.             'csrf_protection' => true,
  344.             'csrf_field_name' => '_token',
  345.             // important part; unique key
  346.             'csrf_token_id'   => 'form_intention',
  347.             'withCustomPicker' => false,
  348.             'canChangeStatus' => true
  349.         ]);
  350.     }
  351. }