src/EventListener/ExportParticipationSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Sogec\BOBundle\Event\CRUDEvents;
  4. use Sogec\BOBundle\Event\ExportListEvent;
  5. use Symfony\Component\EventDispatcher\Event;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. /**
  9.  * Class ExportParticipationSubscriber.
  10.  */
  11. class ExportParticipationSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var SessionInterface
  15.      */
  16.     private $session;
  17.     /**
  18.      * ExportParticipationSubscriber constructor.
  19.      *
  20.      * @param SessionInterface $session
  21.      */
  22.     public function __construct(SessionInterface $session)
  23.     {
  24.         $this->session $session;
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             CRUDEvents::EXPORT_INITIALIZE => [
  33.                 ['isFilterEmpty'2],
  34.             ],
  35.         ];
  36.     }
  37.     /**
  38.      * @param ExportListEvent $event
  39.      */
  40.     public function isFilterEmpty(Event $event)
  41.     {
  42.         if ('participation_filter' !== $event->getForm()->getName()) {
  43.             return;
  44.         }
  45.         $tErrors = [];
  46.         $data unserialize($this->session->get('filter_list_'.$event->getForm()->getName(), 'a:0:{}'));
  47.         if (empty($data)) {
  48.             $tErrors[] = 'Veillez filtrer la liste avant de faire un export';
  49.             $event->setExportErrors($tErrors);
  50.             $event->stopPropagation();
  51.         }
  52.     }
  53.     /**
  54.      * @param ExportListEvent $event
  55.      */
  56.     public function isParticipationExportable(Event $event)
  57.     {
  58.         if ('participation_filter' !== $event->getForm()->getName()) {
  59.             return;
  60.         }
  61.         $tErrors = [];
  62.         $data unserialize($this->session->get('filter_list_'.$event->getForm()->getName(), 'a:0:{}'));
  63.         // il faut filtrer
  64.         if (('participation_filter' === $event->getForm()->getName())) {
  65.             if (isset($data['operation']) && !== count($data['operation'])) {
  66.                 $tErrors[] = 'Veillez séléctionner seulement une operation';
  67.                 $event->setExportErrors($tErrors);
  68.             }
  69.         }
  70.     }
  71. }