src/EventSubscriber/Metier/ContratSubscriber.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Metier;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Symfony\Component\HttpKernel\Event\PostResponseEvent;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use App\AppEvents;
  9. use App\Events\Metier\ContratEvent;
  10. use App\Events\Metier\SinistreEvent;
  11. use App\Helpers\UserTypeConst;
  12. use App\Service\User\ExpertUserManager;
  13. use App\Service\Firebase\DoPush;
  14. class ContratSubscriber implements EventSubscriberInterface
  15. {
  16.     private $em;
  17.     private $token;
  18.     private $doPush;
  19.     private $usermanager;
  20.     public function __construct(EntityManagerInterface $emTokenStorageInterface $tokenExpertUserManager $usermanagerDoPush $doPush)
  21.     {
  22.         $this->em $em;
  23.         $this->token $token;
  24.         $this->doPush $doPush;
  25.         $this->usermanager $usermanager;
  26.     }
  27.     public function onContratAlert(ContratEvent $event)
  28.     {
  29.         $contrat $event->getContrat();
  30.         $avenant $event->getAvenant();
  31.         $nbjr $event->getNombreJour();
  32.         $extra = ['type' => UserTypeConst::TYPE_CONTRAT'method' => UserTypeConst::METHOD_ALERT'id' => $contrat->getId(), 'avenant' => $avenant->getId()];
  33.         $message '';
  34.         $notify $this->em->getRepository('Admin:Parametre')->findOneBy(['cle' => UserTypeConst::PARAMS_ALERT_CONTRAT_MESSAGE]);
  35.         if (!is_null($notify)) {
  36.             $handler = [$contrat->getNumPolice(), $avenant->getDateExpiration()->format('d/m/Y')];
  37.             $holder = ['%num_police%''%date%'];
  38.             $message str_replace($holder$handler$notify->getValeur());
  39.         }
  40.         $client $contrat->getClient();
  41.         if (!is_null($client)) {
  42.             $this->doPush->setNumClient($client->getNumClient())->setExtra($extra)->setTelepohne($client->getTel())->setTitle('myFidelia')->setMessage($message)->doPush();
  43.         }
  44.     }
  45.     public function onSinistreAlert(SinistreEvent $event)
  46.     {
  47.         $sinistre $event->getSinistre();
  48.         $nbjr $event->getNombreJour();
  49.         $extra = ['type' => UserTypeConst::TYPE_SINISTRE'method' => UserTypeConst::METHOD_ALERT'id' => $sinistre->getId()];
  50.         $message '';
  51.         $notify $this->em->getRepository('Admin:Parametre')->findOneBy(['cle' => UserTypeConst::PARAMS_ALERT_SINISTRE_MESSAGE]);
  52.         if (!is_null($notify)) {
  53.             $handler = [$sinistre->getNumSinistre(), $sinistre->getDateEcheance()->format('d/m/Y')];
  54.             $holder = ['%num_sinistre''%date'];
  55.             $message str_replace($holder$handler$notify->getValeur());
  56.         }
  57.         $client $sinistre->getContrat()->getClient();
  58.         $this->doPush->setExtra($extra)->setTelepohne($client->getTel())->setTitle('myFidelia')->setMessage($message)->doPush();
  59.     }
  60.     public function onAllContratDelete(PostResponseEvent $event)
  61.     {
  62.         //$controller = $event->getRequest()->get
  63.     }
  64.     public static function getSubscribedEvents()
  65.     {
  66.         return [
  67.             KernelEvents::TERMINATE => 'onAllContratDelete',
  68.             AppEvents::CONTRAT_ALERT => 'onContratAlert',
  69.             AppEvents::SINISTRE_ALERT => 'onSinistreAlert'
  70.         ];
  71.     }
  72. }