src/Controller/TarifsController.php line 66

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author Mehrez Labidi
  5.  */
  6. namespace App\Controller;
  7. use Symfony\Component\HttpFoundation\{
  8.     Response,
  9.     Request
  10. };
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use App\Entity\Commandes;
  13. use App\Entity\DetailsCommande;
  14. use Doctrine\ORM\Query;
  15. use App\Repository\iRepository;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. use App\Validator\Constraints\Emoji;
  18. use Symfony\Component\Validator\Constraints\Email;
  19. use Symfony\Component\Form\Extension\Core\Type\{
  20.     ChoiceType,
  21.     HiddenType,
  22.     ButtonType,
  23.     SubmitType,
  24.     TextareaType,
  25.     TextType
  26. };
  27. use App\Services\TelephoneInternational;
  28. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  29. use App\Services\ContactezNous as ContactezNousService;
  30. class TarifsController extends EntityUsingController {
  31.     public const MAX_AGE 43200// 12heures
  32.     /**
  33.      * @var TelephoneInternational
  34.      */
  35.     private $telephoneInternational;
  36.     /**
  37.      * @var EntityManagerInterface
  38.      */
  39.     private $em;
  40.     /**
  41.      * 
  42.      * @var type
  43.      */
  44.     private $contactezNous;
  45.     /**
  46.      * 
  47.      * @param EntityManagerInterface $em
  48.      * @param TelephoneInternational $telephoneInternational
  49.      * @param ContactezNousService $contactezNous
  50.      */
  51.     public function __construct(EntityManagerInterface $emTelephoneInternational $telephoneInternationalContactezNousService $contactezNous) {
  52.         $this->em $em;
  53.         $this->telephoneInternational $telephoneInternational;
  54.         $this->contactezNous $contactezNous;
  55.     }
  56.     public function index(Request $request): Response {
  57.         $form $this->createFormBuilder()
  58.                 ->add('civilite'ChoiceType::class, [
  59.                     'choices' => ['M' => 'masculin''Mme' => 'feminin'],
  60.                     'constraints' => [new NotBlank(['message' => 'Ce champ est obligatoire'])],
  61.                     'expanded' => true,
  62.                     'multiple' => false,
  63.                 ])
  64.                 ->add('nom'TextType::class, ['constraints' => [new NotBlank(['message' => 'Le nom est obligatoire'])]])
  65.                 ->add('prenom'TextType::class, ['constraints' => [new NotBlank(['message' => 'Le prénom est obligatoire'])]])
  66.                 ->add('mail'TextType::class, ['constraints' => [new NotBlank(['message' => 'L\'email est obligatoire']), new Email(['message' => 'L\'email "{{ value }}" n\'est pas valide'])]])
  67.                 ->add('societe'TextType::class, ['constraints' => [new NotBlank(['message' => 'La société est obligatoire'])]])
  68.                 ->add('telephone'TextType::class, ['constraints' => [new NotBlank(['message' => 'Le téléphone est obligatoire'])]])
  69.                 ->add('indicatif'ChoiceType::class, [
  70.                     'choices' => $this->telephoneInternational->listIndicatifChoiceForm(),
  71.                     'attr' => ['class' => 'form-control'],
  72.                     'choice_attr' => fn($key$val$index) => ($key == "") ? ['disabled' => 'disabled'] : [],
  73.                     'data' => array_values($this->telephoneInternational->listIndicatifChoiceForm())[0],
  74.                     'constraints' => [new NotBlank(['message' => 'L\'indicatif est obligatoire'])]
  75.                 ])
  76.                 ->add('message'TextareaType::class, [
  77.                     'attr' => ['class' => 'form-control''rows' => 8'autocomplete' => 'off'],
  78.                     'constraints' => [new NotBlank(['message' => 'Le message est obligatoire']), new Emoji()]
  79.                 ])
  80.                 ->add('recaptcha'EWZRecaptchaType::class, ['mapped' => false'language' => 'fr'])
  81.                 ->getForm();
  82.         // Traitement de la requête
  83.         $form->handleRequest($request);
  84.         if ($form->isSubmitted()) {
  85.             $this->get('session')->getFlashBag()->clear(); // Clear tous les flashbags
  86.             if ($form->isValid() ) {
  87.                 $data $form->getData();
  88.                 $obj = new \stdClass();
  89.                 $obj->type_contact "cedant";
  90.                 $obj->civilite $data["civilite"];
  91.                 $obj->prenom $data["prenom"];
  92.                 $obj->nom $data["nom"];
  93.                 $obj->email $data["mail"];
  94.                 $obj->indicatif $data["indicatif"];
  95.                 $obj->telephone $data["telephone"];
  96.                 $obj->contenu_question $data["message"];
  97.    
  98.                 $response $this->contactezNous->sendMailCreateQuestionUtilisateur($obj);
  99.                 if ($response) {
  100.                     $this->addFlash('success_contact_tarif''Votre demande est bien envoyée');
  101.                 } else {
  102.                     $this->addFlash('error_contact_tarif'"Votre demande n'est pas envoyée");
  103.                 }
  104.             } else {
  105.                 $this->addFlash('error_contact_tarif'"Votre demande n'est pas envoyée");
  106.             }
  107.         }
  108.         $response $this->render('tarifs/index.html.twig', [
  109.             'controller_name' => 'TarifsController',
  110.             'form' => $form->createView(),
  111.         ]);
  112.         $response->setPublic();
  113.         $response->setMaxAge(self::MAX_AGE); // 12heures
  114.         return $response;
  115.     }
  116.     public function comparatifOffres(): Response {
  117.         $nbMiseEnRelations 0;
  118.         $time strtotime(date("Ymd"));
  119.         $final date("Ymd"strtotime("-1 month"$time));
  120.         $qb $this->em->createQueryBuilder();
  121.         $alias "a";
  122.         $query $qb->select([
  123.                     'd.id_detail_cmde',
  124.                 ])
  125.                 ->from(Commandes::class, $alias)
  126.                 ->leftJoin(DetailsCommande::class, 'd'iRepository::WITH'a.id_commande = d.id_commande')
  127.                 ->where($alias ".etat = 'facture_envoyee' OR " $alias ".etat = 'information_transmise'")
  128.                 ->andWhere($alias ".date_livraison <= '" date("Ymd") . "'")
  129.                 ->andWhere($alias ".date_livraison >= '" $final "'");
  130.         $commandes $query->getQuery()->getResult(Query::HYDRATE_ARRAY);
  131.         $nbMiseEnRelations count($commandes);
  132.         $array array_map('intval'str_split((string) $nbMiseEnRelations));
  133.         $response $this->render('tarifs/comparatif_offres.html.twig', [
  134.             'controller_name' => 'TarifsController',
  135.             'nbMiseEnRelations' => $array,
  136.         ]);
  137.         $response->setPublic();
  138.         $response->setMaxAge(self::MAX_AGE); // 12heures
  139.         return $response;
  140.     }
  141. }