src/EventSubscriber/InscriptionEventSubscriber.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Message\NewInscription;
  4. use Sulu\Bundle\CommunityBundle\Event\AbstractCommunityEvent;
  5. use Sulu\Bundle\CommunityBundle\Event\UserRegisteredEvent;
  6. use Sulu\Bundle\FormBundle\Entity\Dynamic;
  7. use Sulu\Bundle\FormBundle\Event\FormSavePostEvent;
  8. use Sulu\Component\DocumentManager\Subscriber\EventSubscriberInterface;
  9. use Symfony\Component\Messenger\MessageBusInterface;
  10. use Symfony\Contracts\HttpClient\HttpClientInterface;
  11. use Twig\Environment;
  12. class InscriptionEventSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var MessageBusInterface $bus
  16.      */
  17.     private MessageBusInterface $bus;
  18.     /**
  19.      * __construct
  20.      *
  21.      * @param  MessageBusInterface $dm
  22.      * @return void
  23.      */
  24.     /**
  25.      * @var HttpClientInterface $client
  26.      */
  27.     /**
  28.      * @var Environment
  29.      */
  30.     public function __construct(MessageBusInterface $bus)
  31.     {
  32.         $this->bus $bus;
  33.     }
  34.     public static function getSubscribedEvents(): array
  35.     {
  36.         return [
  37.             FormSavePostEvent::NAME => "noPayboxInscription"
  38.         ];
  39.     }
  40.     public function noPayboxInscription(FormSavePostEvent $event)
  41.     {
  42.         $dynamic $event->getData();
  43.         if (!$dynamic instanceof Dynamic) {
  44.             return;
  45.         }
  46.         $form $dynamic->getForm()->serializeForLocale($dynamic->getLocale(), $dynamic);
  47.         if ($form) {
  48.             $ref = isset($dynamic->getData()['text']) ? $dynamic->getData()['text'] : '';
  49.             $email = isset($dynamic->getData()['email']) ? $dynamic->getData()['email'] : '';
  50.             $lastName =  isset($dynamic->getData()['lastName']) ? $dynamic->getData()['lastName'] : '';
  51.             $firstName = isset($dynamic->getData()['firstName']) ? $dynamic->getData()['firstName'] : '';
  52.             $textarea = isset($dynamic->getData()['textarea']) ? $dynamic->getData()['textarea'] : '';
  53.             $structure = isset($dynamic->getData()['text2']) ? $dynamic->getData()['text2'] : '';
  54.             $fonction = isset($dynamic->getData()['dropdown']) ? $dynamic->getData()['dropdown'] : '';
  55.             $departement = isset($dynamic->getData()['dropdown1']) ? $dynamic->getData()['dropdown1'] : '';
  56.             if (empty($ref) || empty($email) || empty($lastName) || empty($firstName) || empty($structure) || empty($fonction) || empty($departement)) {
  57.                 return;
  58.             }
  59.             if (array_key_exists('text2'$dynamic->getData())) {
  60.                 $structure $dynamic->getData()['text2'];
  61.             }
  62.             if (array_key_exists('dropdown'$dynamic->getData())) {
  63.                 $fonction $dynamic->getData()['dropdown'];
  64.             }
  65.             if (array_key_exists('dropdown1'$dynamic->getData())) {
  66.                 $departement $dynamic->getData()['dropdown1'];
  67.             }
  68.             if (!$ref || !$email || !$lastName || !$firstName || !$structure || !$fonction || !$departement) {
  69.                 return;
  70.             }
  71.             $uuid explode('_'$ref)[0];
  72.             $user_id intval(explode("_"$ref)[1]);
  73.             $array = [
  74.                 'user_id' => $user_id,
  75.                 'locale' => $dynamic->getLocale(),
  76.                 'uuid' => $uuid,
  77.                 'ref' => $ref,
  78.                 'email' => $email,
  79.                 'lastname' => $lastName,
  80.                 'firstname' => $firstName,
  81.                 'textarea' => $textarea,
  82.                 'erreur' => '',
  83.                 'structure' => $structure,
  84.                 'fonction' => $fonction,
  85.                 'departement' => $departement
  86.             ];
  87.             $content json_encode($array);
  88.             $this->bus->dispatch(new NewInscription($content));
  89.             sleep(3);
  90.             exec('rm -rf /var/www/html/var/cache/common/*');
  91.         }
  92.         return;
  93.     }
  94. }